diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-07 08:15:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-07 08:15:19 +0100 |
| commit | e8bb6c05ab455999ccfe10e178bc2ada9d450187 (patch) | |
| tree | 3ab5e5734a1bb4a0794de59141b975ea13120b3d /src/test | |
| parent | 2890b37b861247de3b8c6ba2ecbcd00048c728a1 (diff) | |
| parent | 125159f30a7a97b0b4d4bc36b11846a3f6dd4a7b (diff) | |
| download | rust-e8bb6c05ab455999ccfe10e178bc2ada9d450187.tar.gz rust-e8bb6c05ab455999ccfe10e178bc2ada9d450187.zip | |
Rollup merge of #67741 - estebank:point-at-pat-def, r=Centril
When encountering an Item in a pat context, point at the item def
```
error[E0308]: mismatched types
--> $DIR/const-in-struct-pat.rs:8:17
|
LL | struct foo;
| ----------- `foo` defined here
...
LL | let Thing { foo } = t;
| ^^^ expected struct `std::string::String`, found struct `foo`
|
= note: `foo` is interpreted as a unit struct, not a new binding
help: you can bind the struct field to a different name
|
LL | let Thing { foo: other_foo } = t;
| ^^^^^^^^^^^^^^
```
```
error[E0308]: mismatched types
--> $DIR/const.rs:14:9
|
LL | const FOO: Foo = Foo{bar: 5};
| ----------------------------- constant defined here
...
LL | FOO => {},
| ^^^
| |
| expected `&Foo`, found struct `Foo`
| `FOO` is interpreted as a constant, not a new binding
| help: use different name to introduce a new binding: `other_foo`
```
Fix #55631, fix #48062, cc #42876.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/blind/blind-item-block-middle.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-33504.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-4968.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-5100.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-7867.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/match/match-tag-nullary.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/rfc-2005-default-binding-mode/const.stderr | 9 | ||||
| -rw-r--r-- | src/test/ui/suggestions/const-in-struct-pat.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/suggestions/const-in-struct-pat.stderr | 16 |
9 files changed, 68 insertions, 4 deletions
diff --git a/src/test/ui/blind/blind-item-block-middle.stderr b/src/test/ui/blind/blind-item-block-middle.stderr index 264e7fc8e73..d8d15615d7c 100644 --- a/src/test/ui/blind/blind-item-block-middle.stderr +++ b/src/test/ui/blind/blind-item-block-middle.stderr @@ -1,8 +1,15 @@ error[E0308]: mismatched types --> $DIR/blind-item-block-middle.rs:6:9 | +LL | mod foo { pub struct bar; } + | --------------- unit struct defined here +... LL | let bar = 5; - | ^^^ expected integer, found struct `foo::bar` + | ^^^ + | | + | expected integer, found struct `foo::bar` + | `bar` is interpreted as a unit struct, not a new binding + | help: introduce a new binding instead: `other_bar` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-33504.stderr b/src/test/ui/issues/issue-33504.stderr index 522df6a07c2..1e61178f42e 100644 --- a/src/test/ui/issues/issue-33504.stderr +++ b/src/test/ui/issues/issue-33504.stderr @@ -1,8 +1,15 @@ error[E0308]: mismatched types --> $DIR/issue-33504.rs:7:13 | +LL | struct Test; + | ------------ unit struct defined here +... LL | let Test = 1; - | ^^^^ expected integer, found struct `Test` + | ^^^^ + | | + | expected integer, found struct `Test` + | `Test` is interpreted as a unit struct, not a new binding + | help: introduce a new binding instead: `other_test` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-4968.stderr b/src/test/ui/issues/issue-4968.stderr index 35435d0e618..5451cf42355 100644 --- a/src/test/ui/issues/issue-4968.stderr +++ b/src/test/ui/issues/issue-4968.stderr @@ -1,8 +1,15 @@ error[E0308]: mismatched types --> $DIR/issue-4968.rs:5:16 | +LL | const A: (isize,isize) = (4,2); + | ------------------------------- constant defined here +LL | fn main() { LL | match 42 { A => () } - | ^ expected integer, found tuple + | ^ + | | + | expected integer, found tuple + | `A` is interpreted as a constant, not a new binding + | help: introduce a new binding instead: `other_a` | = note: expected type `{integer}` found tuple `(isize, isize)` diff --git a/src/test/ui/issues/issue-5100.stderr b/src/test/ui/issues/issue-5100.stderr index c81d6dcaf02..a89980964ca 100644 --- a/src/test/ui/issues/issue-5100.stderr +++ b/src/test/ui/issues/issue-5100.stderr @@ -1,6 +1,9 @@ error[E0308]: mismatched types --> $DIR/issue-5100.rs:8:9 | +LL | enum A { B, C } + | - unit variant defined here +... LL | match (true, false) { | ------------- this expression has type `(bool, bool)` LL | A::B => (), diff --git a/src/test/ui/issues/issue-7867.stderr b/src/test/ui/issues/issue-7867.stderr index 4a29464aebd..0d3121d6045 100644 --- a/src/test/ui/issues/issue-7867.stderr +++ b/src/test/ui/issues/issue-7867.stderr @@ -1,6 +1,9 @@ error[E0308]: mismatched types --> $DIR/issue-7867.rs:7:9 | +LL | enum A { B, C } + | - unit variant defined here +... LL | match (true, false) { | ------------- this expression has type `(bool, bool)` LL | A::B => (), diff --git a/src/test/ui/match/match-tag-nullary.stderr b/src/test/ui/match/match-tag-nullary.stderr index 3703a59edb8..723c7fa92b1 100644 --- a/src/test/ui/match/match-tag-nullary.stderr +++ b/src/test/ui/match/match-tag-nullary.stderr @@ -1,6 +1,9 @@ error[E0308]: mismatched types --> $DIR/match-tag-nullary.rs:4:40 | +LL | enum B { B } + | - unit variant defined here +LL | LL | fn main() { let x: A = A::A; match x { B::B => { } } } | - ^^^^ expected enum `A`, found enum `B` | | diff --git a/src/test/ui/rfc-2005-default-binding-mode/const.stderr b/src/test/ui/rfc-2005-default-binding-mode/const.stderr index 27efd450b94..10d30ec1a1b 100644 --- a/src/test/ui/rfc-2005-default-binding-mode/const.stderr +++ b/src/test/ui/rfc-2005-default-binding-mode/const.stderr @@ -1,10 +1,17 @@ error[E0308]: mismatched types --> $DIR/const.rs:14:9 | +LL | const FOO: Foo = Foo{bar: 5}; + | ----------------------------- constant defined here +... LL | match &f { | -- this expression has type `&Foo` LL | FOO => {}, - | ^^^ expected `&Foo`, found struct `Foo` + | ^^^ + | | + | expected `&Foo`, found struct `Foo` + | `FOO` is interpreted as a constant, not a new binding + | help: introduce a new binding instead: `other_foo` error: aborting due to previous error diff --git a/src/test/ui/suggestions/const-in-struct-pat.rs b/src/test/ui/suggestions/const-in-struct-pat.rs new file mode 100644 index 00000000000..1cbba935402 --- /dev/null +++ b/src/test/ui/suggestions/const-in-struct-pat.rs @@ -0,0 +1,11 @@ +#[allow(non_camel_case_types)] +struct foo; +struct Thing { + foo: String, +} + +fn example(t: Thing) { + let Thing { foo } = t; //~ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/suggestions/const-in-struct-pat.stderr b/src/test/ui/suggestions/const-in-struct-pat.stderr new file mode 100644 index 00000000000..0a010dcab4c --- /dev/null +++ b/src/test/ui/suggestions/const-in-struct-pat.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/const-in-struct-pat.rs:8:17 + | +LL | struct foo; + | ----------- unit struct defined here +... +LL | let Thing { foo } = t; + | ^^^ - this expression has type `Thing` + | | + | expected struct `std::string::String`, found struct `foo` + | `foo` is interpreted as a unit struct, not a new binding + | help: bind the struct field to a different name instead: `foo: other_foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
