Skip to content

Commit 4e0a4cf

Browse files
authored
test(rustfix): re-enable disabled test due to unused variables (#16114)
### What does this PR try to resolve? Fixes #16097 The change in rustc seems intentionally and reasonable. Also suppress unrelated warnings to make the intent of the test clearer ### How to test and review this PR?
2 parents ce7aafe + 8d4ed85 commit 4e0a4cf

File tree

4 files changed

+73
-55
lines changed

4 files changed

+73
-55
lines changed

crates/rustfix/tests/everything/closure-immutable-outer-variable.fixed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Point at the captured immutable outer variable
22

3+
// Suppress unrelated warnings
4+
#![allow(unused)]
5+
36
fn foo(mut f: Box<dyn FnMut()>) {
47
f();
58
}
Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,83 @@
11
{
2-
"message": "cannot assign to captured outer variable in an `FnMut` closure",
3-
"code": {
4-
"code": "E0594",
5-
"explanation": null
6-
},
7-
"level": "error",
8-
"spans": [
9-
{
10-
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
11-
"byte_start": 615,
12-
"byte_end": 624,
13-
"line_start": 19,
14-
"line_end": 19,
15-
"column_start": 26,
16-
"column_end": 35,
17-
"is_primary": true,
18-
"text": [
19-
{
20-
"text": " foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable",
21-
"highlight_start": 26,
22-
"highlight_end": 35
23-
}
24-
],
25-
"label": null,
26-
"suggested_replacement": null,
27-
"expansion": null
28-
}
29-
],
2+
"$message_type": "diagnostic",
303
"children": [
314
{
32-
"message": "consider making `y` mutable",
5+
"children": [],
336
"code": null,
347
"level": "help",
8+
"message": "consider changing this to be mutable",
9+
"rendered": null,
3510
"spans": [
3611
{
37-
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
38-
"byte_start": 580,
39-
"byte_end": 581,
40-
"line_start": 18,
41-
"line_end": 18,
12+
"byte_end": 167,
13+
"byte_start": 167,
14+
"column_end": 9,
4215
"column_start": 9,
43-
"column_end": 10,
16+
"expansion": null,
17+
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
4418
"is_primary": true,
19+
"label": null,
20+
"line_end": 11,
21+
"line_start": 11,
22+
"suggested_replacement": "mut ",
23+
"suggestion_applicability": "MachineApplicable",
4524
"text": [
4625
{
47-
"text": " let y = true;",
26+
"highlight_end": 9,
4827
"highlight_start": 9,
49-
"highlight_end": 10
28+
"text": " let y = true;"
5029
}
51-
],
52-
"label": null,
53-
"suggested_replacement": "mut y",
54-
"expansion": null
30+
]
5531
}
56-
],
57-
"children": [],
58-
"rendered": null
32+
]
5933
}
6034
],
61-
"rendered": "error[E0594]: cannot assign to captured outer variable in an `FnMut` closure\n --> ./tests/everything/closure-immutable-outer-variable.rs:19:26\n |\n18 | let y = true;\n | - help: consider making `y` mutable: `mut y`\n19 | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable\n | ^^^^^^^^^\n\nIf you want more information on this error, try using \"rustc --explain E0594\"\n"
35+
"code": {
36+
"code": "E0594",
37+
"explanation": "A non-mutable value was assigned a value./n/nErroneous code example:/n/n```compile_fail,E0594/nstruct SolarSystem {/n earth: i32,/n}/n/nlet ss = SolarSystem { earth: 3 };/nss.earth = 2; // error!/n```/n/nTo fix this error, declare `ss` as mutable by using the `mut` keyword:/n/n```/nstruct SolarSystem {/n earth: i32,/n}/n/nlet mut ss = SolarSystem { earth: 3 }; // declaring `ss` as mutable/nss.earth = 2; // ok!/n```/n"
38+
},
39+
"level": "error",
40+
"message": "cannot assign to `y`, as it is not declared as mutable",
41+
"rendered": "error[E0594]: cannot assign to `y`, as it is not declared as mutable/n --> ./tests/everything/closure-immutable-outer-variable.rs:12:26/n |/n12 | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable/n | ^^^^^^^^^ cannot assign/n |/nhelp: consider changing this to be mutable/n |/n11 | let mut y = true;/n | +++/n/n",
42+
"spans": [
43+
{
44+
"byte_end": 211,
45+
"byte_start": 202,
46+
"column_end": 35,
47+
"column_start": 26,
48+
"expansion": null,
49+
"file_name": "./tests/everything/closure-immutable-outer-variable.rs",
50+
"is_primary": true,
51+
"label": "cannot assign",
52+
"line_end": 12,
53+
"line_start": 12,
54+
"suggested_replacement": null,
55+
"suggestion_applicability": null,
56+
"text": [
57+
{
58+
"highlight_end": 35,
59+
"highlight_start": 26,
60+
"text": " foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable"
61+
}
62+
]
63+
}
64+
]
6265
}
6366
{
64-
"message": "aborting due to previous error",
67+
"$message_type": "diagnostic",
68+
"children": [],
6569
"code": null,
6670
"level": "error",
67-
"spans": [],
68-
"children": [],
69-
"rendered": "error: aborting due to previous error\n\n"
71+
"message": "aborting due to 1 previous error",
72+
"rendered": "error: aborting due to 1 previous error/n/n",
73+
"spans": []
7074
}
75+
{
76+
"$message_type": "diagnostic",
77+
"children": [],
78+
"code": null,
79+
"level": "failure-note",
80+
"message": "For more information about this error, try `rustc --explain E0594`.",
81+
"rendered": "For more information about this error, try `rustc --explain E0594`./n",
82+
"spans": []
83+
}

crates/rustfix/tests/everything/closure-immutable-outer-variable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Point at the captured immutable outer variable
22

3-
fn foo(mut f: Box<FnMut()>) {
3+
// Suppress unrelated warnings
4+
#![allow(unused)]
5+
6+
fn foo(mut f: Box<dyn FnMut()>) {
47
f();
58
}
69

crates/rustfix/tests/parse_and_replace.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ macro_rules! run_test {
177177
};
178178
}
179179

180-
// NOTE: Temporarily disabled due to failures on nightly. Fix tracked in #16097
181-
// run_test! {
182-
// closure_immutable_outer_variable,
183-
// "closure-immutable-outer-variable.rs"
184-
// }
180+
run_test! {
181+
closure_immutable_outer_variable,
182+
"closure-immutable-outer-variable.rs"
183+
}
185184
run_test! {dedup_suggestions, "dedup-suggestions.rs"}
186185
run_test! {E0178, "E0178.rs"}
187186
run_test! {handle_insert_only, "handle-insert-only.rs"}

0 commit comments

Comments
 (0)