Skip to content

Commit 22c5bb0

Browse files
Rollup merge of rust-lang#133560 - clubby789:mut-mut-space, r=jieyouxu
Trim extra space in 'repeated `mut`' diagnostic Trim an extra space when removing repeated `mut`. Also an extra test for even more repeated `mut`s
2 parents 7201f70 + c3c68c5 commit 22c5bb0

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

compiler/rustc_parse/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2620,8 +2620,9 @@ pub(crate) enum InvalidMutInPattern {
26202620
#[diag(parse_repeated_mut_in_pattern)]
26212621
pub(crate) struct RepeatedMutInPattern {
26222622
#[primary_span]
2623-
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
26242623
pub span: Span,
2624+
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
2625+
pub suggestion: Span,
26252626
}
26262627

26272628
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/pat.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,9 @@ impl<'a> Parser<'a> {
10891089
return;
10901090
}
10911091

1092-
self.dcx().emit_err(RepeatedMutInPattern { span: lo.to(self.prev_token.span) });
1092+
let span = lo.to(self.prev_token.span);
1093+
let suggestion = span.with_hi(self.token.span.lo());
1094+
self.dcx().emit_err(RepeatedMutInPattern { span, suggestion });
10931095
}
10941096

10951097
/// Parse macro invocation

tests/ui/parser/mut-patterns.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub fn main() {
1515
//~^ ERROR `mut` on a binding may not be repeated
1616
//~| remove the additional `mut`s
1717

18+
let mut mut mut mut mut x = 0;
19+
//~^ ERROR `mut` on a binding may not be repeated
20+
//~| remove the additional `mut`s
21+
1822
struct Foo { x: isize }
1923
let mut Foo { x: x } = Foo { x: 3 };
2024
//~^ ERROR `mut` must be attached to each individual binding

tests/ui/parser/mut-patterns.stderr

+24-12
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,23 @@ LL | let mut mut x = 0;
4545
help: remove the additional `mut`s
4646
|
4747
LL - let mut mut x = 0;
48-
LL + let mut x = 0;
48+
LL + let mut x = 0;
49+
|
50+
51+
error: `mut` on a binding may not be repeated
52+
--> $DIR/mut-patterns.rs:18:13
53+
|
54+
LL | let mut mut mut mut mut x = 0;
55+
| ^^^^^^^^^^^^^^^
56+
|
57+
help: remove the additional `mut`s
58+
|
59+
LL - let mut mut mut mut mut x = 0;
60+
LL + let mut x = 0;
4961
|
5062

5163
error: `mut` must be attached to each individual binding
52-
--> $DIR/mut-patterns.rs:19:9
64+
--> $DIR/mut-patterns.rs:23:9
5365
|
5466
LL | let mut Foo { x: x } = Foo { x: 3 };
5567
| ^^^^^^^^^^^^^^^^
@@ -61,7 +73,7 @@ LL | let Foo { x: mut x } = Foo { x: 3 };
6173
| ~~~~~~~~~~~~~~~~
6274

6375
error: `mut` must be attached to each individual binding
64-
--> $DIR/mut-patterns.rs:23:9
76+
--> $DIR/mut-patterns.rs:27:9
6577
|
6678
LL | let mut Foo { x } = Foo { x: 3 };
6779
| ^^^^^^^^^^^^^
@@ -73,19 +85,19 @@ LL | let Foo { mut x } = Foo { x: 3 };
7385
| ~~~~~~~~~~~~~
7486

7587
error: `mut` on a binding may not be repeated
76-
--> $DIR/mut-patterns.rs:28:13
88+
--> $DIR/mut-patterns.rs:32:13
7789
|
7890
LL | let mut mut yield(become, await) = r#yield(0, 0);
7991
| ^^^
8092
|
8193
help: remove the additional `mut`s
8294
|
8395
LL - let mut mut yield(become, await) = r#yield(0, 0);
84-
LL + let mut yield(become, await) = r#yield(0, 0);
96+
LL + let mut yield(become, await) = r#yield(0, 0);
8597
|
8698

8799
error: expected identifier, found reserved keyword `yield`
88-
--> $DIR/mut-patterns.rs:28:17
100+
--> $DIR/mut-patterns.rs:32:17
89101
|
90102
LL | let mut mut yield(become, await) = r#yield(0, 0);
91103
| ^^^^^ expected identifier, found reserved keyword
@@ -96,7 +108,7 @@ LL | let mut mut r#yield(become, await) = r#yield(0, 0);
96108
| ++
97109

98110
error: expected identifier, found reserved keyword `become`
99-
--> $DIR/mut-patterns.rs:28:23
111+
--> $DIR/mut-patterns.rs:32:23
100112
|
101113
LL | let mut mut yield(become, await) = r#yield(0, 0);
102114
| ^^^^^^ expected identifier, found reserved keyword
@@ -107,7 +119,7 @@ LL | let mut mut yield(r#become, await) = r#yield(0, 0);
107119
| ++
108120

109121
error: expected identifier, found keyword `await`
110-
--> $DIR/mut-patterns.rs:28:31
122+
--> $DIR/mut-patterns.rs:32:31
111123
|
112124
LL | let mut mut yield(become, await) = r#yield(0, 0);
113125
| ^^^^^ expected identifier, found keyword
@@ -118,7 +130,7 @@ LL | let mut mut yield(become, r#await) = r#yield(0, 0);
118130
| ++
119131

120132
error: `mut` must be followed by a named binding
121-
--> $DIR/mut-patterns.rs:28:9
133+
--> $DIR/mut-patterns.rs:32:9
122134
|
123135
LL | let mut mut yield(become, await) = r#yield(0, 0);
124136
| ^^^^^^^^
@@ -131,7 +143,7 @@ LL + let yield(become, await) = r#yield(0, 0);
131143
|
132144

133145
error: `mut` must be attached to each individual binding
134-
--> $DIR/mut-patterns.rs:37:9
146+
--> $DIR/mut-patterns.rs:41:9
135147
|
136148
LL | let mut W(mut a, W(b, W(ref c, W(d, B { box f }))))
137149
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -143,7 +155,7 @@ LL | let W(mut a, W(mut b, W(ref c, W(mut d, B { box mut f }))))
143155
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144156

145157
error: expected identifier, found `x`
146-
--> $DIR/mut-patterns.rs:44:21
158+
--> $DIR/mut-patterns.rs:48:21
147159
|
148160
LL | let mut $p = 0;
149161
| ^^ expected identifier
@@ -153,5 +165,5 @@ LL | foo!(x);
153165
|
154166
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
155167

156-
error: aborting due to 13 previous errors
168+
error: aborting due to 14 previous errors
157169

0 commit comments

Comments
 (0)