]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #82220 - henryboisdequin:fixes-80853, r=varkor
authorDylan DPC <dylan.dpc@gmail.com>
Thu, 25 Feb 2021 13:34:00 +0000 (14:34 +0100)
committerGitHub <noreply@github.com>
Thu, 25 Feb 2021 13:34:00 +0000 (14:34 +0100)
fix the false 'defined here' messages

Closes #80853.

Take this code:

```rust
struct S;

fn repro_ref(thing: S) {
    thing();
}
```

Previously, the error message would be this:

```
error[E0618]: expected function, found `S`
 --> src/lib.rs:4:5
  |
3 | fn repro_ref(thing: S) {
  |              ----- `S` defined here
4 |     thing();
  |     ^^^^^--
  |     |
  |     call expression requires function

error: aborting due to previous error
```

This is incorrect as `S` is not defined in the function arguments, `thing` is defined there. With this change, the following is emitted:

```
error[E0618]: expected function, found `S`
  --> $DIR/80853.rs:4:5
   |
LL | fn repro_ref(thing: S) {
   |              ----- is of type `S`
LL |     thing();
   |     ^^^^^--
   |     |
   |     call expression requires function
   |
   = note: local variable `S` is not a function

error: aborting due to previous error
```

As you can see, this error message points out that `thing` is of type `S` and later in a note, that `S` is not a function. This change does seem like a downside for some error messages. Take this example:

```
LL | struct Empty2;
   | -------------- is of type `Empty2`
```

As you can see, the error message shows that the definition of `Empty2` is of type `Empty2`. Although this isn't wrong, it would be more helpful if it would say something like this (which was there previously):

```
LL | struct Empty2;
   | -------------- `Empty2` defined here
```

If there is a better way of doing this, where the `Empty2` example would stay the same as without this change, please inform me.

**Update: This is now fixed**

CC `@camelid`

1  2 
compiler/rustc_typeck/src/check/callee.rs