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-18 11:35:11 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-04-19 10:13:45 -0700
commit4c4ca60edd9775873e555dbb5928b000bd734403 (patch)
tree36d0896b30261cfc9be79a761fc6c5a6fab55475 /src/test
parentf1be8d16c55990fff8c265352328fd90555feabd (diff)
downloadrust-4c4ca60edd9775873e555dbb5928b000bd734403.tar.gz
rust-4c4ca60edd9775873e555dbb5928b000bd734403.zip
remove duplicated code and simplify logic
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/struct-literal-variant-in-if.rs15
-rw-r--r--src/test/ui/struct-literal-variant-in-if.stderr70
2 files changed, 80 insertions, 5 deletions
diff --git a/src/test/ui/struct-literal-variant-in-if.rs b/src/test/ui/struct-literal-variant-in-if.rs
index 2d87c4ca73d..8f2d50586c0 100644
--- a/src/test/ui/struct-literal-variant-in-if.rs
+++ b/src/test/ui/struct-literal-variant-in-if.rs
@@ -1,12 +1,25 @@
 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
 enum E {
-    V { field: bool }
+    V { field: bool },
+    I { field1: bool, field2: usize },
+    J { field: isize },
+    K { field: &'static str},
 }
 fn test_E(x: E) {
     let field = true;
     if x == E::V { field } {}
     //~^ ERROR expected value, found struct variant `E::V`
     //~| ERROR mismatched types
+    if x == E::I { field1: true, field2: 42 } {}
+    //~^ ERROR struct literals are not allowed here
+    if x == E::V { field: false } {}
+    //~^ ERROR expected identifier, found keyword `false`
+    //~| ERROR expected type, found keyword `false`
+    //~| ERROR expected value, found struct variant `E::V`
+    if x == E::J { field: -42 } {}
+    //~^ ERROR struct literals are not allowed here
+    if x == E::K { field: "" } {}
+    //~^ ERROR struct literals are not allowed here
     let y: usize = ();
     //~^ ERROR mismatched types
 }
diff --git a/src/test/ui/struct-literal-variant-in-if.stderr b/src/test/ui/struct-literal-variant-in-if.stderr
index e38eb0d61e0..0af0c6aefaf 100644
--- a/src/test/ui/struct-literal-variant-in-if.stderr
+++ b/src/test/ui/struct-literal-variant-in-if.stderr
@@ -1,13 +1,75 @@
+error: struct literals are not allowed here
+  --> $DIR/struct-literal-variant-in-if.rs:13:13
+   |
+LL |     if x == E::I { field1: true, field2: 42 } {}
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: surround the struct literal with parenthesis
+   |
+LL |     if x == (E::I { field1: true, field2: 42 }) {}
+   |             ^                                 ^
+
+error: expected identifier, found keyword `false`
+  --> $DIR/struct-literal-variant-in-if.rs:15:27
+   |
+LL |     if x == E::V { field: false } {}
+   |                           ^^^^^ expected identifier, found keyword
+help: you can escape reserved keywords to use them as identifiers
+   |
+LL |     if x == E::V { field: r#false } {}
+   |                           ^^^^^^^
+
+error: expected type, found keyword `false`
+  --> $DIR/struct-literal-variant-in-if.rs:15:27
+   |
+LL |     if x == E::V { field: false } {}
+   |                           ^^^^^ expecting a type here because of type ascription
+   |
+   = note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>`
+note: this expression expects an ascribed type after the colon
+  --> $DIR/struct-literal-variant-in-if.rs:15:20
+   |
+LL |     if x == E::V { field: false } {}
+   |                    ^^^^^
+   = help: this might be indicative of a syntax error elsewhere
+
+error: struct literals are not allowed here
+  --> $DIR/struct-literal-variant-in-if.rs:19:13
+   |
+LL |     if x == E::J { field: -42 } {}
+   |             ^^^^^^^^^^^^^^^^^^^
+help: surround the struct literal with parenthesis
+   |
+LL |     if x == (E::J { field: -42 }) {}
+   |             ^                   ^
+
+error: struct literals are not allowed here
+  --> $DIR/struct-literal-variant-in-if.rs:21:13
+   |
+LL |     if x == E::K { field: "" } {}
+   |             ^^^^^^^^^^^^^^^^^^
+help: surround the struct literal with parenthesis
+   |
+LL |     if x == (E::K { field: "" }) {}
+   |             ^                  ^
+
 error[E0423]: expected value, found struct variant `E::V`
-  --> $DIR/struct-literal-variant-in-if.rs:7:13
+  --> $DIR/struct-literal-variant-in-if.rs:10:13
    |
 LL |     if x == E::V { field } {}
    |             ^^^^----------
    |             |
    |             help: surround the struct literal with parenthesis: `(E::V { field })`
 
+error[E0423]: expected value, found struct variant `E::V`
+  --> $DIR/struct-literal-variant-in-if.rs:15:13
+   |
+LL |     if x == E::V { field: false } {}
+   |             ^^^^-----------------
+   |             |
+   |             help: surround the struct literal with parenthesis: `(E::V { field: false })`
+
 error[E0308]: mismatched types
-  --> $DIR/struct-literal-variant-in-if.rs:7:20
+  --> $DIR/struct-literal-variant-in-if.rs:10:20
    |
 LL | fn test_E(x: E) {
    |                 - help: try adding a return type: `-> bool`
@@ -19,7 +81,7 @@ LL |     if x == E::V { field } {}
               found type `bool`
 
 error[E0308]: mismatched types
-  --> $DIR/struct-literal-variant-in-if.rs:10:20
+  --> $DIR/struct-literal-variant-in-if.rs:23:20
    |
 LL |     let y: usize = ();
    |                    ^^ expected usize, found ()
@@ -27,7 +89,7 @@ LL |     let y: usize = ();
    = note: expected type `usize`
               found type `()`
 
-error: aborting due to 3 previous errors
+error: aborting due to 9 previous errors
 
 Some errors occurred: E0308, E0423.
 For more information about an error, try `rustc --explain E0308`.