about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-06-04 18:47:47 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-06-04 18:47:47 -0700
commit377cf44b4e52f5bf0f50b0c344bda71d810f0b8a (patch)
tree82aaa669260ac7c9ad9c645d755b2cafbb3f6cc0 /src/test/ui
parent41affd03eb169830773cd1b11efda562ab81fad0 (diff)
downloadrust-377cf44b4e52f5bf0f50b0c344bda71d810f0b8a.tar.gz
rust-377cf44b4e52f5bf0f50b0c344bda71d810f0b8a.zip
Suggest braces when a struct literal needs them
When writing a struct literal in an expression that expects a block to
be started afterwards (like an `if` statement), do not suggest using the
same struct literal:

```
did you mean `S { /* fields * /}`?
```

Instead, suggest surrounding the expression with parentheses:

```
did you mean `(S { /* fields * /})`?
```
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/error-codes/E0423.rs19
-rw-r--r--src/test/ui/error-codes/E0423.stderr43
2 files changed, 60 insertions, 2 deletions
diff --git a/src/test/ui/error-codes/E0423.rs b/src/test/ui/error-codes/E0423.rs
index f5fea77cf96..7d71499d318 100644
--- a/src/test/ui/error-codes/E0423.rs
+++ b/src/test/ui/error-codes/E0423.rs
@@ -13,3 +13,22 @@ fn main () {
 
     let f = Foo(); //~ ERROR E0423
 }
+
+fn bar() {
+    struct S { x: i32, y: i32 }
+    #[derive(PartialEq)]
+    struct T {}
+
+    if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
+    //~^ ERROR E0423
+    //~|  expected type, found `1`
+    if T {} == T {} { println!("Ok"); }
+    //~^ ERROR E0423
+    //~| ERROR expected expression, found `==`
+}
+
+fn foo() {
+    for _ in std::ops::Range { start: 0, end: 10 } {}
+    //~^ ERROR E0423
+    //~| ERROR expected type, found `0`
+}
diff --git a/src/test/ui/error-codes/E0423.stderr b/src/test/ui/error-codes/E0423.stderr
index ef24295332d..477c698ac9a 100644
--- a/src/test/ui/error-codes/E0423.stderr
+++ b/src/test/ui/error-codes/E0423.stderr
@@ -1,9 +1,48 @@
+error: expected type, found `1`
+  --> $DIR/E0423.rs:22:39
+   |
+LL |     if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
+   |                                       ^ expecting a type here because of type ascription
+
+error: expected expression, found `==`
+  --> $DIR/E0423.rs:25:13
+   |
+LL |     if T {} == T {} { println!("Ok"); }
+   |             ^^ expected expression
+
+error: expected type, found `0`
+  --> $DIR/E0423.rs:31:39
+   |
+LL |     for _ in std::ops::Range { start: 0, end: 10 } {}
+   |                                       ^ expecting a type here because of type ascription
+
 error[E0423]: expected function, found struct `Foo`
   --> $DIR/E0423.rs:14:13
    |
 LL |     let f = Foo(); //~ ERROR E0423
-   |             ^^^ did you mean `Foo { /* fields */ }`?
+   |             ^^^
+   |             |
+   |             did you mean `foo`?
+   |             did you mean `Foo { /* fields */ }`?
+
+error[E0423]: expected value, found struct `S`
+  --> $DIR/E0423.rs:22:32
+   |
+LL |     if let S { x: _x, y: 2 } = S { x: 1, y: 2 } { println!("Ok"); }
+   |                                ^ did you mean `(S { /* fields */ })`?
+
+error[E0423]: expected value, found struct `T`
+  --> $DIR/E0423.rs:25:8
+   |
+LL |     if T {} == T {} { println!("Ok"); }
+   |        ^ did you mean `(T { /* fields */ })`?
+
+error[E0423]: expected value, found struct `std::ops::Range`
+  --> $DIR/E0423.rs:31:14
+   |
+LL |     for _ in std::ops::Range { start: 0, end: 10 } {}
+   |              ^^^^^^^^^^^^^^^ did you mean `(std::ops::Range { /* fields */ })`?
 
-error: aborting due to previous error
+error: aborting due to 7 previous errors
 
 For more information about this error, try `rustc --explain E0423`.