about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-04-15 08:08:46 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-04-19 10:13:45 -0700
commitf1be8d16c55990fff8c265352328fd90555feabd (patch)
tree99c16d9f73b4cf921c383eb1bc226d906211267b /src/test
parent2f36b54f0f33427e926872935c325a660967af6f (diff)
downloadrust-f1be8d16c55990fff8c265352328fd90555feabd.tar.gz
rust-f1be8d16c55990fff8c265352328fd90555feabd.zip
Identify missing ambiguous case with best effort suggestion
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/struct-literal-variant-in-if.rs14
-rw-r--r--src/test/ui/struct-literal-variant-in-if.stderr33
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/ui/struct-literal-variant-in-if.rs b/src/test/ui/struct-literal-variant-in-if.rs
new file mode 100644
index 00000000000..2d87c4ca73d
--- /dev/null
+++ b/src/test/ui/struct-literal-variant-in-if.rs
@@ -0,0 +1,14 @@
+#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
+enum E {
+    V { field: bool }
+}
+fn test_E(x: E) {
+    let field = true;
+    if x == E::V { field } {}
+    //~^ ERROR expected value, found struct variant `E::V`
+    //~| ERROR mismatched types
+    let y: usize = ();
+    //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/struct-literal-variant-in-if.stderr b/src/test/ui/struct-literal-variant-in-if.stderr
new file mode 100644
index 00000000000..e38eb0d61e0
--- /dev/null
+++ b/src/test/ui/struct-literal-variant-in-if.stderr
@@ -0,0 +1,33 @@
+error[E0423]: expected value, found struct variant `E::V`
+  --> $DIR/struct-literal-variant-in-if.rs:7:13
+   |
+LL |     if x == E::V { field } {}
+   |             ^^^^----------
+   |             |
+   |             help: surround the struct literal with parenthesis: `(E::V { field })`
+
+error[E0308]: mismatched types
+  --> $DIR/struct-literal-variant-in-if.rs:7:20
+   |
+LL | fn test_E(x: E) {
+   |                 - help: try adding a return type: `-> bool`
+LL |     let field = true;
+LL |     if x == E::V { field } {}
+   |                    ^^^^^ expected (), found bool
+   |
+   = note: expected type `()`
+              found type `bool`
+
+error[E0308]: mismatched types
+  --> $DIR/struct-literal-variant-in-if.rs:10:20
+   |
+LL |     let y: usize = ();
+   |                    ^^ expected usize, found ()
+   |
+   = note: expected type `usize`
+              found type `()`
+
+error: aborting due to 3 previous errors
+
+Some errors occurred: E0308, E0423.
+For more information about an error, try `rustc --explain E0308`.