-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in which
!
is suggested for erroneous identifier not
Impressing confused Python users with magical diagnostics is perhaps worth this not-grossly-unreasonable (only 40ish lines) extra complexity in the parser? Thanks to Vadim Petrochenkov for guidance. This resolves #46836.
- Loading branch information
1 parent
944c401
commit ba0dd8e
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn gratitude() { | ||
let for_you = false; | ||
if not for_you { | ||
//~^ ERROR unexpected `for_you` after identifier | ||
println!("I couldn't"); | ||
} | ||
} | ||
|
||
fn qualification() { | ||
let the_worst = true; | ||
while not the_worst { | ||
//~^ ERROR unexpected `the_worst` after identifier | ||
println!("still pretty bad"); | ||
} | ||
} | ||
|
||
fn should_we() { | ||
let not = true; | ||
if not // lack of braces is [sic] | ||
println!("Then when?"); | ||
//~^ ERROR expected `{`, found `; | ||
//~| ERROR unexpected `println` after identifier | ||
} | ||
|
||
fn sleepy() { | ||
let resource = not 2; | ||
//~^ ERROR unexpected `2` after identifier | ||
} | ||
|
||
fn main() { | ||
let be_smothered_out_before = true; | ||
let young_souls = not be_smothered_out_before; | ||
//~^ ERROR unexpected `be_smothered_out_before` after identifier | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error: unexpected `for_you` after identifier | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:13:12 | ||
| | ||
LL | if not for_you { | ||
| ----^^^^^^^ | ||
| | | ||
| help: use `!` to perform logical negation | ||
|
||
error: unexpected `the_worst` after identifier | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:21:15 | ||
| | ||
LL | while not the_worst { | ||
| ----^^^^^^^^^ | ||
| | | ||
| help: use `!` to perform logical negation | ||
|
||
error: unexpected `println` after identifier | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:30:9 | ||
| | ||
LL | if not // lack of braces is [sic] | ||
| ----- help: use `!` to perform logical negation | ||
LL | println!("Then when?"); | ||
| ^^^^^^^ | ||
|
||
error: expected `{`, found `;` | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:30:31 | ||
| | ||
LL | if not // lack of braces is [sic] | ||
| -- this `if` statement has a condition, but no block | ||
LL | println!("Then when?"); | ||
| ^ | ||
|
||
error: unexpected `2` after identifier | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:36:24 | ||
| | ||
LL | let resource = not 2; | ||
| ----^ | ||
| | | ||
| help: use `!` to perform logical negation | ||
|
||
error: unexpected `be_smothered_out_before` after identifier | ||
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:42:27 | ||
| | ||
LL | let young_souls = not be_smothered_out_before; | ||
| ----^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| help: use `!` to perform logical negation | ||
|
||
error: aborting due to 6 previous errors | ||
|