Skip to content

Commit 1c6bd0b

Browse files
committed
Smaller span for unnessary mut suggestion
1 parent ae20897 commit 1c6bd0b

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

compiler/rustc_parse/src/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2278,9 +2278,8 @@ pub(crate) enum InvalidMutInPattern {
22782278
#[note(parse_note_mut_pattern_usage)]
22792279
NonIdent {
22802280
#[primary_span]
2281-
#[suggestion(code = "{pat}", applicability = "machine-applicable")]
2281+
#[suggestion(code = "", applicability = "machine-applicable")]
22822282
span: Span,
2283-
pat: String,
22842283
},
22852284
}
22862285

compiler/rustc_parse/src/parser/pat.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,13 @@ impl<'a> Parser<'a> {
638638

639639
/// Error on `mut $pat` where `$pat` is not an ident.
640640
fn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool) {
641-
let span = lo.to(pat.span);
642-
let pat = pprust::pat_to_string(&pat);
643-
644641
self.sess.emit_err(if changed_any_binding {
645-
InvalidMutInPattern::NestedIdent { span, pat }
642+
InvalidMutInPattern::NestedIdent {
643+
span: lo.to(pat.span),
644+
pat: pprust::pat_to_string(&pat),
645+
}
646646
} else {
647-
InvalidMutInPattern::NonIdent { span, pat }
647+
InvalidMutInPattern::NonIdent { span: lo.until(pat.span) }
648648
});
649649
}
650650

tests/ui/parser/issues/issue-32501.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
22
--> $DIR/issue-32501.rs:7:9
33
|
44
LL | let mut _ = 0;
5-
| ^^^^^ help: remove the `mut` prefix: `_`
5+
| ^^^^ help: remove the `mut` prefix
66
|
77
= note: `mut` may be followed by `variable` and `variable @ pattern`
88

tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
22
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:6:13
33
|
44
LL | let mut $eval = ();
5-
| ^^^^^^^^^ help: remove the `mut` prefix: `does_not_exist!()`
5+
| ^^^^ help: remove the `mut` prefix
66
...
77
LL | mac1! { does_not_exist!() }
88
| --------------------------- in this macro invocation
@@ -25,7 +25,7 @@ error: `mut` must be followed by a named binding
2525
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:13
2626
|
2727
LL | let mut $eval = ();
28-
| ^^^ help: remove the `mut` prefix: `does_not_exist!()`
28+
| ^^^ help: remove the `mut` prefix
2929
...
3030
LL | mac2! { does_not_exist!() }
3131
| --------------------------- in this macro invocation

tests/ui/parser/mut-patterns.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error: `mut` must be followed by a named binding
22
--> $DIR/mut-patterns.rs:9:9
33
|
44
LL | let mut _ = 0;
5-
| ^^^^^ help: remove the `mut` prefix: `_`
5+
| ^^^^ help: remove the `mut` prefix
66
|
77
= note: `mut` may be followed by `variable` and `variable @ pattern`
88

99
error: `mut` must be followed by a named binding
1010
--> $DIR/mut-patterns.rs:10:9
1111
|
1212
LL | let mut (_, _) = (0, 0);
13-
| ^^^^^^^^^^ help: remove the `mut` prefix: `(_, _)`
13+
| ^^^^ help: remove the `mut` prefix
1414
|
1515
= note: `mut` may be followed by `variable` and `variable @ pattern`
1616

tests/ui/self/self_type_keyword.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error: `mut` must be followed by a named binding
1414
--> $DIR/self_type_keyword.rs:16:9
1515
|
1616
LL | mut Self => (),
17-
| ^^^^^^^^ help: remove the `mut` prefix: `Self`
17+
| ^^^^ help: remove the `mut` prefix
1818
|
1919
= note: `mut` may be followed by `variable` and `variable @ pattern`
2020

0 commit comments

Comments
 (0)