diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-26 14:56:32 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-03-27 10:19:47 +0100 |
| commit | 05d59feb64cac786da37072dc3a52348e99756f3 (patch) | |
| tree | ec780992252e426aeec5cd150bb89ef8710f077e | |
| parent | 7945eff0805d91d3c0ca10df872bcabdd88aa4b6 (diff) | |
| download | rust-05d59feb64cac786da37072dc3a52348e99756f3.tar.gz rust-05d59feb64cac786da37072dc3a52348e99756f3.zip | |
add test for assignment x = y where type bool is expected.
| -rw-r--r-- | src/test/ui/type/type-check/assignment-expected-bool.rs | 29 | ||||
| -rw-r--r-- | src/test/ui/type/type-check/assignment-expected-bool.stderr | 135 |
2 files changed, 164 insertions, 0 deletions
diff --git a/src/test/ui/type/type-check/assignment-expected-bool.rs b/src/test/ui/type/type-check/assignment-expected-bool.rs new file mode 100644 index 00000000000..bb5ee46c9e1 --- /dev/null +++ b/src/test/ui/type/type-check/assignment-expected-bool.rs @@ -0,0 +1,29 @@ +// The purpose of this text is to ensure that we get good +// diagnostics when a `bool` is expected but that due to +// an assignment expression `x = y` the type is `()`. + +fn main() { + let _: bool = 0 = 0; //~ ERROR mismatched types [E0308] + + let _: bool = match 0 { + 0 => 0 = 0, //~ ERROR mismatched types [E0308] + _ => 0 = 0, //~ ERROR mismatched types [E0308] + }; + + let _: bool = match true { + true => 0 = 0, //~ ERROR mismatched types [E0308] + _ => (), + }; + + if 0 = 0 {} //~ ERROR mismatched types [E0308] + + let _: bool = if { 0 = 0 } { //~ ERROR mismatched types [E0308] + 0 = 0 //~ ERROR mismatched types [E0308] + } else { + 0 = 0 //~ ERROR mismatched types [E0308] + }; + + let _ = (0 = 0) //~ ERROR mismatched types [E0308] + && { 0 = 0 } //~ ERROR mismatched types [E0308] + || (0 = 0); //~ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/type/type-check/assignment-expected-bool.stderr b/src/test/ui/type/type-check/assignment-expected-bool.stderr new file mode 100644 index 00000000000..e9297357348 --- /dev/null +++ b/src/test/ui/type/type-check/assignment-expected-bool.stderr @@ -0,0 +1,135 @@ +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:6:19 + | +LL | let _: bool = 0 = 0; + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:9:14 + | +LL | 0 => 0 = 0, + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:10:14 + | +LL | _ => 0 = 0, + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:14:17 + | +LL | true => 0 = 0, + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:18:8 + | +LL | if 0 = 0 {} + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:20:24 + | +LL | let _: bool = if { 0 = 0 } { + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:21:9 + | +LL | 0 = 0 + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:23:9 + | +LL | 0 = 0 + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:26:13 + | +LL | let _ = (0 = 0) + | ^^^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:27:14 + | +LL | && { 0 = 0 } + | ^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error[E0308]: mismatched types + --> $DIR/assignment-expected-bool.rs:28:12 + | +LL | || (0 = 0); + | ^^^^^^^ + | | + | expected bool, found () + | help: try comparing for equality: `0 == 0` + | + = note: expected type `bool` + found type `()` + +error: aborting due to 11 previous errors + +For more information about this error, try `rustc --explain E0308`. |
