Skip to content

Commit 9e4ab9f

Browse files
Rollup merge of #117395 - gurry:117380-wrong-parent-sugg, r=Nilstrieb
Fix missing leading space in suggestion For a local pattern with no space between `let` and `(` e.g.: ```rust let(_a) = 3; ``` we were previously suggesting this illegal code: ```rust let_a = 3; ``` After this change the suggestion will instead be: ```rust let _a = 3; ``` Fixes #117380
2 parents 02d32d2 + a2486db commit 9e4ab9f

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

compiler/rustc_lint/src/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ impl EarlyLintPass for UnusedParens {
11541154

11551155
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
11561156
if let StmtKind::Local(ref local) = s.kind {
1157-
self.check_unused_parens_pat(cx, &local.pat, true, false, (false, false));
1157+
self.check_unused_parens_pat(cx, &local.pat, true, false, (true, false));
11581158
}
11591159

11601160
<Self as UnusedDelimLint>::check_stmt(self, cx, s)

tests/ui/lint/lint-unnecessary-parens.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ fn main() {
8484
_a = 0; //~ ERROR unnecessary parentheses around assigned value
8585
_a += 1; //~ ERROR unnecessary parentheses around assigned value
8686

87+
let mut _a = 3; //~ ERROR unnecessary parentheses around pattern
88+
let mut _a = 3; //~ ERROR unnecessary parentheses around pattern
89+
let mut _a = 3; //~ ERROR unnecessary parentheses around pattern
90+
91+
let _a = 3; //~ ERROR unnecessary parentheses around pattern
92+
let _a = 3; //~ ERROR unnecessary parentheses around pattern
93+
let _a = 3; //~ ERROR unnecessary parentheses around pattern
94+
8795
let _a = baz!(3, 4);
8896
let _b = baz!(3);
8997
}

tests/ui/lint/lint-unnecessary-parens.rs

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ fn main() {
8484
_a = (0); //~ ERROR unnecessary parentheses around assigned value
8585
_a += (1); //~ ERROR unnecessary parentheses around assigned value
8686

87+
let(mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
88+
let (mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
89+
let( mut _a) = 3; //~ ERROR unnecessary parentheses around pattern
90+
91+
let(_a) = 3; //~ ERROR unnecessary parentheses around pattern
92+
let (_a) = 3; //~ ERROR unnecessary parentheses around pattern
93+
let( _a) = 3; //~ ERROR unnecessary parentheses around pattern
94+
8795
let _a = baz!(3, 4);
8896
let _b = baz!(3);
8997
}

tests/ui/lint/lint-unnecessary-parens.stderr

+73-1
Original file line numberDiff line numberDiff line change
@@ -267,5 +267,77 @@ LL - _a += (1);
267267
LL + _a += 1;
268268
|
269269

270-
error: aborting due to 22 previous errors
270+
error: unnecessary parentheses around pattern
271+
--> $DIR/lint-unnecessary-parens.rs:87:8
272+
|
273+
LL | let(mut _a) = 3;
274+
| ^ ^
275+
|
276+
help: remove these parentheses
277+
|
278+
LL - let(mut _a) = 3;
279+
LL + let mut _a = 3;
280+
|
281+
282+
error: unnecessary parentheses around pattern
283+
--> $DIR/lint-unnecessary-parens.rs:88:9
284+
|
285+
LL | let (mut _a) = 3;
286+
| ^ ^
287+
|
288+
help: remove these parentheses
289+
|
290+
LL - let (mut _a) = 3;
291+
LL + let mut _a = 3;
292+
|
293+
294+
error: unnecessary parentheses around pattern
295+
--> $DIR/lint-unnecessary-parens.rs:89:8
296+
|
297+
LL | let( mut _a) = 3;
298+
| ^^ ^
299+
|
300+
help: remove these parentheses
301+
|
302+
LL - let( mut _a) = 3;
303+
LL + let mut _a = 3;
304+
|
305+
306+
error: unnecessary parentheses around pattern
307+
--> $DIR/lint-unnecessary-parens.rs:91:8
308+
|
309+
LL | let(_a) = 3;
310+
| ^ ^
311+
|
312+
help: remove these parentheses
313+
|
314+
LL - let(_a) = 3;
315+
LL + let _a = 3;
316+
|
317+
318+
error: unnecessary parentheses around pattern
319+
--> $DIR/lint-unnecessary-parens.rs:92:9
320+
|
321+
LL | let (_a) = 3;
322+
| ^ ^
323+
|
324+
help: remove these parentheses
325+
|
326+
LL - let (_a) = 3;
327+
LL + let _a = 3;
328+
|
329+
330+
error: unnecessary parentheses around pattern
331+
--> $DIR/lint-unnecessary-parens.rs:93:8
332+
|
333+
LL | let( _a) = 3;
334+
| ^^ ^
335+
|
336+
help: remove these parentheses
337+
|
338+
LL - let( _a) = 3;
339+
LL + let _a = 3;
340+
|
341+
342+
error: aborting due to 28 previous errors
271343

0 commit comments

Comments
 (0)