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.
This commit is contained in:
Mazdak Farrokhzad 2020-03-07 08:15:19 +01:00 committed by GitHub
commit e8bb6c05ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 147 additions and 28 deletions

View file

@ -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

View file

@ -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)`

View file

@ -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 => (),

View file

@ -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 => (),