-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #68108 - varkor:chained-comparison-suggestions, r=Cen…
…tril Add suggestions when encountering chained comparisons Ideally, we'd also prevent the type error, which is just extra noise, but that will require moving the error from the parser, and I think the suggestion makes things clear enough for now. Fixes #65659.
- Loading branch information
Showing
8 changed files
with
335 additions
and
49 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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
fn main() { | ||
(0..13).collect<Vec<i32>>(); | ||
//~^ ERROR chained comparison | ||
//~^ ERROR comparison operators cannot be chained | ||
Vec<i32>::new(); | ||
//~^ ERROR chained comparison | ||
//~^ ERROR comparison operators cannot be chained | ||
(0..13).collect<Vec<i32>(); | ||
//~^ ERROR chained comparison | ||
//~^ ERROR comparison operators cannot be chained | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Check that we get nice suggestions when attempting a chained comparison. | ||
|
||
fn comp1() { | ||
1 < 2 <= 3; //~ ERROR comparison operators cannot be chained | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn comp2() { | ||
1 < 2 < 3; //~ ERROR comparison operators cannot be chained | ||
} | ||
|
||
fn comp3() { | ||
1 <= 2 < 3; //~ ERROR comparison operators cannot be chained | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn comp4() { | ||
1 <= 2 <= 3; //~ ERROR comparison operators cannot be chained | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn comp5() { | ||
1 > 2 >= 3; //~ ERROR comparison operators cannot be chained | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn comp6() { | ||
1 > 2 > 3; //~ ERROR comparison operators cannot be chained | ||
} | ||
|
||
fn comp7() { | ||
1 >= 2 > 3; //~ ERROR comparison operators cannot be chained | ||
} | ||
|
||
fn comp8() { | ||
1 >= 2 >= 3; //~ ERROR comparison operators cannot be chained | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.