forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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 rust-lang#57481 - euclio:bool-cast-suggestion, r=este…
…bank provide suggestion for invalid boolean cast Also, don't suggest comparing to zero for non-numeric expressions.
- Loading branch information
Showing
7 changed files
with
47 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
fn main() { | ||
let u = 5 as bool; | ||
//~^ ERROR cannot cast as `bool` | ||
let u = 5 as bool; //~ ERROR cannot cast as `bool` | ||
//~| HELP compare with zero instead | ||
//~| SUGGESTION 5 != 0 | ||
let t = (1 + 2) as bool; //~ ERROR cannot cast as `bool` | ||
//~| HELP compare with zero instead | ||
//~| SUGGESTION (1 + 2) != 0 | ||
let v = "hello" as bool; //~ ERROR cannot cast as `bool` | ||
} |
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,11 +1,21 @@ | ||
error[E0054]: cannot cast as `bool` | ||
--> $DIR/cast-as-bool.rs:2:13 | ||
| | ||
LL | let u = 5 as bool; | ||
| ^^^^^^^^^ unsupported cast | ||
LL | let u = 5 as bool; //~ ERROR cannot cast as `bool` | ||
| ^^^^^^^^^ help: compare with zero instead: `5 != 0` | ||
|
||
error[E0054]: cannot cast as `bool` | ||
--> $DIR/cast-as-bool.rs:5:13 | ||
| | ||
LL | let t = (1 + 2) as bool; //~ ERROR cannot cast as `bool` | ||
| ^^^^^^^^^^^^^^^ help: compare with zero instead: `(1 + 2) != 0` | ||
|
||
error[E0054]: cannot cast as `bool` | ||
--> $DIR/cast-as-bool.rs:8:13 | ||
| | ||
= help: compare with zero instead | ||
LL | let v = "hello" as bool; //~ ERROR cannot cast as `bool` | ||
| ^^^^^^^^^^^^^^^ unsupported cast | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0054`. |
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
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