diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2022-02-17 14:58:46 -0800 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2022-03-23 22:31:57 -0700 |
| commit | 073010d425d7b6ff5e79fd41f209e4915daa6066 (patch) | |
| tree | 2f4ed899247b67791a8b39e160b04721ed1a07ed /src/test/ui/parser | |
| parent | 62b8ea67b79de77fca36ca82de4b934307b6de30 (diff) | |
| download | rust-073010d425d7b6ff5e79fd41f209e4915daa6066.tar.gz rust-073010d425d7b6ff5e79fd41f209e4915daa6066.zip | |
Improve handling of `tmp` variable name conflicts
Diffstat (limited to 'src/test/ui/parser')
| -rw-r--r-- | src/test/ui/parser/increment-autofix.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/parser/increment-autofix.stderr | 38 | ||||
| -rw-r--r-- | src/test/ui/parser/increment-notfixed.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/parser/increment-notfixed.stderr | 20 |
4 files changed, 80 insertions, 5 deletions
diff --git a/src/test/ui/parser/increment-autofix.rs b/src/test/ui/parser/increment-autofix.rs index f31031fed3a..909c8f8c371 100644 --- a/src/test/ui/parser/increment-autofix.rs +++ b/src/test/ui/parser/increment-autofix.rs @@ -14,6 +14,20 @@ fn post_while() { } } +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() { let mut i = 0; ++i; //~ ERROR Rust has no prefix increment operator @@ -31,6 +45,8 @@ fn pre_while() { fn main() { post_regular(); post_while(); + post_regular_tmp(); + post_while_tmp(); pre_regular(); pre_while(); } diff --git a/src/test/ui/parser/increment-autofix.stderr b/src/test/ui/parser/increment-autofix.stderr index e5386c7bdba..8c934c9efde 100644 --- a/src/test/ui/parser/increment-autofix.stderr +++ b/src/test/ui/parser/increment-autofix.stderr @@ -30,8 +30,40 @@ 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 (rename `tmp` so it doesn't conflict with your variable) + | +LL | { let tmp = tmp; tmp += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~ +help: or, if you don't need to use it as an expression, change it to this + | +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 (rename `tmp` so it doesn't conflict with your variable) + | +LL | while { let tmp = tmp; tmp += 1; tmp } < 5 { + | +++++++++++ ~~~~~~~~~~~~~~~~~ +help: or, if you don't need to use it as an expression, change it to this + | +LL - while tmp++ < 5 { +LL + while tmp += 1 < 5 { + | + error: Rust has no prefix increment operator - --> $DIR/increment-autofix.rs:19:5 + --> $DIR/increment-autofix.rs:33:5 | LL | ++i; | ^^ not a valid prefix operator @@ -43,7 +75,7 @@ LL + i += 1; | error: Rust has no prefix increment operator - --> $DIR/increment-autofix.rs:25:11 + --> $DIR/increment-autofix.rs:39:11 | LL | while ++i < 5 { | ^^ not a valid prefix operator @@ -53,5 +85,5 @@ help: use `+= 1` instead LL | while { i += 1; i } < 5 { | ~ +++++++++ -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors diff --git a/src/test/ui/parser/increment-notfixed.rs b/src/test/ui/parser/increment-notfixed.rs index d0efe952982..3db8a4c3326 100644 --- a/src/test/ui/parser/increment-notfixed.rs +++ b/src/test/ui/parser/increment-notfixed.rs @@ -13,6 +13,16 @@ fn post_field() { println!("{}", foo.bar.qux); } +fn post_field_tmp() { + struct S { + tmp: i32 + } + let s = S { tmp: 0 }; + s.tmp++; + //~^ ERROR Rust has no postfix increment operator + println!("{}", s.tmp); +} + fn pre_field() { let foo = Foo { bar: Bar { qux: 0 } }; ++foo.bar.qux; @@ -22,5 +32,6 @@ fn pre_field() { fn main() { post_field(); + post_field_tmp(); pre_field(); } diff --git a/src/test/ui/parser/increment-notfixed.stderr b/src/test/ui/parser/increment-notfixed.stderr index 43586c4c25e..c4c83b5113b 100644 --- a/src/test/ui/parser/increment-notfixed.stderr +++ b/src/test/ui/parser/increment-notfixed.stderr @@ -14,8 +14,24 @@ LL - foo.bar.qux++; LL + foo.bar.qux += 1; | +error: Rust has no postfix increment operator + --> $DIR/increment-notfixed.rs:21:10 + | +LL | s.tmp++; + | ^^ not a valid postfix operator + | +help: use `+= 1` instead + | +LL | { let tmp = s.tmp; s.tmp += 1; tmp }; + | +++++++++++ ~~~~~~~~~~~~~~~~~~~ +help: or, if you don't need to use it as an expression, change it to this + | +LL - s.tmp++; +LL + s.tmp += 1; + | + error: Rust has no prefix increment operator - --> $DIR/increment-notfixed.rs:18:5 + --> $DIR/increment-notfixed.rs:28:5 | LL | ++foo.bar.qux; | ^^ not a valid prefix operator @@ -26,5 +42,5 @@ LL - ++foo.bar.qux; LL + foo.bar.qux += 1; | -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors |
