diff options
| author | Andy Russell <arussell123@gmail.com> | 2019-01-09 16:57:49 -0500 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2019-01-09 16:59:12 -0500 |
| commit | 565c39de439f59e83efe2f0064c0dbebb287c8e9 (patch) | |
| tree | c35b6af967e03bd7b4f555d564fb8edc719b3ec5 /src/test/ui/cast | |
| parent | 6ecad338381cc3b8d56e2df22e5971a598eddd6c (diff) | |
| download | rust-565c39de439f59e83efe2f0064c0dbebb287c8e9.tar.gz rust-565c39de439f59e83efe2f0064c0dbebb287c8e9.zip | |
provide suggestion for invalid boolean cast
Also, don't suggest comparing to zero for non-numeric expressions.
Diffstat (limited to 'src/test/ui/cast')
| -rw-r--r-- | src/test/ui/cast/cast-as-bool.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/cast/cast-as-bool.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/cast/cast-rfc0401-2.stderr | 4 |
3 files changed, 22 insertions, 9 deletions
diff --git a/src/test/ui/cast/cast-as-bool.rs b/src/test/ui/cast/cast-as-bool.rs index 7a0bd0ec098..8130f4dedc9 100644 --- a/src/test/ui/cast/cast-as-bool.rs +++ b/src/test/ui/cast/cast-as-bool.rs @@ -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` } diff --git a/src/test/ui/cast/cast-as-bool.stderr b/src/test/ui/cast/cast-as-bool.stderr index 086d08a569a..6099a4195b3 100644 --- a/src/test/ui/cast/cast-as-bool.stderr +++ b/src/test/ui/cast/cast-as-bool.stderr @@ -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`. diff --git a/src/test/ui/cast/cast-rfc0401-2.stderr b/src/test/ui/cast/cast-rfc0401-2.stderr index 3bf6e5367f0..52f6af78a9b 100644 --- a/src/test/ui/cast/cast-rfc0401-2.stderr +++ b/src/test/ui/cast/cast-rfc0401-2.stderr @@ -2,9 +2,7 @@ error[E0054]: cannot cast as `bool` --> $DIR/cast-rfc0401-2.rs:6:13 | LL | let _ = 3 as bool; - | ^^^^^^^^^ unsupported cast - | - = help: compare with zero instead + | ^^^^^^^^^ help: compare with zero instead: `3 != 0` error: aborting due to previous error |
