1
Fork 0

Fix rustfix panic on test

`run-rustfix` applies all suggestions regardless of their Applicability.
There's a flag, `rustfix-only-machine-applicable`, that does what it
says, but then the produced `.fixed` file would have invalid code from
the suggestions that weren't applied. So, I moved the cases of postfix
increment, in which case multiple suggestions are given, to the
`-notfixed` test, which does not run rustfix.

I also changed the Applicability to Unspecified since MaybeIncorrect
requires that the code be valid, even if it's incorrect.
This commit is contained in:
Noah Lev 2022-03-23 17:26:59 -07:00
parent 725cde42d5
commit 86220d6e51
6 changed files with 144 additions and 123 deletions

View file

@ -1326,7 +1326,7 @@ impl<'a> Parser<'a> {
MultiSugg::emit_many( MultiSugg::emit_many(
&mut err, &mut err,
"use `+= 1` instead", "use `+= 1` instead",
Applicability::MaybeIncorrect, Applicability::Unspecified,
[sugg1, sugg2].into_iter(), [sugg1, sugg2].into_iter(),
) )
} }

View file

@ -1,19 +1,5 @@
// run-rustfix // run-rustfix
fn post_regular() {
let mut i = 0;
{ let tmp = i; i += 1; tmp }; //~ ERROR Rust has no postfix increment operator
println!("{}", i);
}
fn post_while() {
let mut i = 0;
while { let tmp = i; i += 1; tmp } < 5 {
//~^ ERROR Rust has no postfix increment operator
println!("{}", i);
}
}
fn pre_regular() { fn pre_regular() {
let mut i = 0; let mut i = 0;
i += 1; //~ ERROR Rust has no prefix increment operator i += 1; //~ ERROR Rust has no prefix increment operator
@ -28,9 +14,18 @@ fn pre_while() {
} }
} }
fn main() { fn pre_regular_tmp() {
post_regular(); let mut tmp = 0;
post_while(); tmp += 1; //~ ERROR Rust has no prefix increment operator
pre_regular(); println!("{}", tmp);
pre_while();
} }
fn pre_while_tmp() {
let mut tmp = 0;
while { tmp += 1; tmp } < 5 {
//~^ ERROR Rust has no prefix increment operator
println!("{}", tmp);
}
}
fn main() {}

View file

@ -1,33 +1,5 @@
// run-rustfix // run-rustfix
fn post_regular() {
let mut i = 0;
i++; //~ ERROR Rust has no postfix increment operator
println!("{}", i);
}
fn post_while() {
let mut i = 0;
while i++ < 5 {
//~^ ERROR Rust has no postfix increment operator
println!("{}", i);
}
}
fn post_regular_tmp() {
let mut tmp = 0;
tmp++; //~ ERROR Rust has no postfix increment operator
println!("{}", tmp);
}
fn post_while_tmp() {
let mut tmp = 0;
while tmp++ < 5 {
//~^ ERROR Rust has no postfix increment operator
println!("{}", tmp);
}
}
fn pre_regular() { fn pre_regular() {
let mut i = 0; let mut i = 0;
++i; //~ ERROR Rust has no prefix increment operator ++i; //~ ERROR Rust has no prefix increment operator
@ -42,11 +14,18 @@ fn pre_while() {
} }
} }
fn main() { fn pre_regular_tmp() {
post_regular(); let mut tmp = 0;
post_while(); ++tmp; //~ ERROR Rust has no prefix increment operator
post_regular_tmp(); println!("{}", tmp);
post_while_tmp();
pre_regular();
pre_while();
} }
fn pre_while_tmp() {
let mut tmp = 0;
while ++tmp < 5 {
//~^ ERROR Rust has no prefix increment operator
println!("{}", tmp);
}
}
fn main() {}

View file

@ -1,61 +1,5 @@
error: Rust has no postfix increment operator
--> $DIR/increment-autofix.rs:5:6
|
LL | i++;
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | { let tmp = i; i += 1; tmp };
| +++++++++++ ~~~~~~~~~~~~~~~
LL - i++;
LL + i += 1;
|
error: Rust has no postfix increment operator
--> $DIR/increment-autofix.rs:11:12
|
LL | while i++ < 5 {
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | while { let tmp = i; i += 1; tmp } < 5 {
| +++++++++++ ~~~~~~~~~~~~~~~
LL - while i++ < 5 {
LL + while i += 1 < 5 {
|
error: Rust has no postfix increment operator
--> $DIR/increment-autofix.rs:19:8
|
LL | tmp++;
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | { let tmp_ = tmp; tmp += 1; tmp_ };
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
LL - tmp++;
LL + tmp += 1;
|
error: Rust has no postfix increment operator
--> $DIR/increment-autofix.rs:25:14
|
LL | while tmp++ < 5 {
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 {
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
LL - while tmp++ < 5 {
LL + while tmp += 1 < 5 {
|
error: Rust has no prefix increment operator error: Rust has no prefix increment operator
--> $DIR/increment-autofix.rs:33:5 --> $DIR/increment-autofix.rs:5:5
| |
LL | ++i; LL | ++i;
| ^^ not a valid prefix operator | ^^ not a valid prefix operator
@ -67,7 +11,7 @@ LL + i += 1;
| |
error: Rust has no prefix increment operator error: Rust has no prefix increment operator
--> $DIR/increment-autofix.rs:39:11 --> $DIR/increment-autofix.rs:11:11
| |
LL | while ++i < 5 { LL | while ++i < 5 {
| ^^ not a valid prefix operator | ^^ not a valid prefix operator
@ -77,5 +21,28 @@ help: use `+= 1` instead
LL | while { i += 1; i } < 5 { LL | while { i += 1; i } < 5 {
| ~ +++++++++ | ~ +++++++++
error: aborting due to 6 previous errors error: Rust has no prefix increment operator
--> $DIR/increment-autofix.rs:19:5
|
LL | ++tmp;
| ^^ not a valid prefix operator
|
help: use `+= 1` instead
|
LL - ++tmp;
LL + tmp += 1;
|
error: Rust has no prefix increment operator
--> $DIR/increment-autofix.rs:25:11
|
LL | while ++tmp < 5 {
| ^^ not a valid prefix operator
|
help: use `+= 1` instead
|
LL | while { tmp += 1; tmp } < 5 {
| ~ +++++++++++
error: aborting due to 4 previous errors

View file

@ -6,6 +6,34 @@ struct Bar {
qux: i32, qux: i32,
} }
fn post_regular() {
let mut i = 0;
i++; //~ ERROR Rust has no postfix increment operator
println!("{}", i);
}
fn post_while() {
let mut i = 0;
while i++ < 5 {
//~^ ERROR Rust has no postfix increment operator
println!("{}", i);
}
}
fn post_regular_tmp() {
let mut tmp = 0;
tmp++; //~ ERROR Rust has no postfix increment operator
println!("{}", tmp);
}
fn post_while_tmp() {
let mut tmp = 0;
while tmp++ < 5 {
//~^ ERROR Rust has no postfix increment operator
println!("{}", tmp);
}
}
fn post_field() { fn post_field() {
let foo = Foo { bar: Bar { qux: 0 } }; let foo = Foo { bar: Bar { qux: 0 } };
foo.bar.qux++; foo.bar.qux++;
@ -30,8 +58,4 @@ fn pre_field() {
println!("{}", foo.bar.qux); println!("{}", foo.bar.qux);
} }
fn main() { fn main() {}
post_field();
post_field_tmp();
pre_field();
}

View file

@ -1,5 +1,61 @@
error: Rust has no postfix increment operator error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:11:16 --> $DIR/increment-notfixed.rs:11:6
|
LL | i++;
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | { let tmp = i; i += 1; tmp };
| +++++++++++ ~~~~~~~~~~~~~~~
LL - i++;
LL + i += 1;
|
error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:17:12
|
LL | while i++ < 5 {
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | while { let tmp = i; i += 1; tmp } < 5 {
| +++++++++++ ~~~~~~~~~~~~~~~
LL - while i++ < 5 {
LL + while i += 1 < 5 {
|
error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:25:8
|
LL | tmp++;
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | { let tmp_ = tmp; tmp += 1; tmp_ };
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
LL - tmp++;
LL + tmp += 1;
|
error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:31:14
|
LL | while tmp++ < 5 {
| ^^ not a valid postfix operator
|
help: use `+= 1` instead
|
LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 {
| ++++++++++++ ~~~~~~~~~~~~~~~~~~
LL - while tmp++ < 5 {
LL + while tmp += 1 < 5 {
|
error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:39:16
| |
LL | foo.bar.qux++; LL | foo.bar.qux++;
| ^^ not a valid postfix operator | ^^ not a valid postfix operator
@ -13,7 +69,7 @@ LL + foo.bar.qux += 1;
| |
error: Rust has no postfix increment operator error: Rust has no postfix increment operator
--> $DIR/increment-notfixed.rs:21:10 --> $DIR/increment-notfixed.rs:49:10
| |
LL | s.tmp++; LL | s.tmp++;
| ^^ not a valid postfix operator | ^^ not a valid postfix operator
@ -27,7 +83,7 @@ LL + s.tmp += 1;
| |
error: Rust has no prefix increment operator error: Rust has no prefix increment operator
--> $DIR/increment-notfixed.rs:28:5 --> $DIR/increment-notfixed.rs:56:5
| |
LL | ++foo.bar.qux; LL | ++foo.bar.qux;
| ^^ not a valid prefix operator | ^^ not a valid prefix operator
@ -38,5 +94,5 @@ LL - ++foo.bar.qux;
LL + foo.bar.qux += 1; LL + foo.bar.qux += 1;
| |
error: aborting due to 3 previous errors error: aborting due to 7 previous errors