Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatched type errors have become useless #39343

Closed
nagisa opened this Issue Jan 27, 2017 · 7 comments

Comments

Projects
None yet
9 participants
@nagisa
Copy link
Contributor

nagisa commented Jan 27, 2017

A minimal test case. My actual case is much more complex, involves functions/callbacks with multiple params and several layers of typedefs.

fn takes_cb(f: fn(i8)) {}

fn main() {
    fn callback(x: i32) {}
    takes_cb(callback)
}

The error reported on 1.11.0 is this:

test.rs:5:14: 5:22 error: mismatched types [E0308]
test.rs:5     takes_cb(callback)
                       ^~~~~~~~
test.rs:5:14: 5:22 help: run `rustc --explain E0308` to see a detailed explanation
test.rs:5:14: 5:22 note: expected type `fn(i8)`
test.rs:5:14: 5:22 note:    found type `fn(i32) {main::callback}`

Useful and obvious. What error looks like now (stable (1.14.0)/beta/nightly (1.16.0))?

error[E0308]: mismatched types
 --> test.rs:5:14
  |
5 |     takes_cb(callback)
  |              ^^^^^^^^ expected i8, found i32

Cute but is as worthless and confusing as it gets.

@jdm jdm added the A-diagnostics label Jan 27, 2017

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Feb 1, 2017

This actually looks like a change in coercion? That is, a mismatch in the signature used to prevent the coercion, resulting in the subtyping fallback which simply fails, at the othermost level, whereas now the coercion is attempted and the error from inside the signature mismatch is being reported.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Feb 9, 2017

@eddyb any clues what change might have caused that?

cc @estebank @jonathandturner -- this doesn't look familiar, does it?

@brson brson added the I-nominated label Feb 9, 2017

@jonathandturner

This comment has been minimized.

Copy link
Contributor

jonathandturner commented Feb 9, 2017

@nikomatsakis - not to me. I thought we still always showed the expected/found full type since sometimes you need it to understand the error (this one included)

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Feb 9, 2017

@nikomatsakis sadly, it doesn't for me either.

@jonathandturner it doesn't if the type mismatch is between primitive types, which leads me to think that somewhere a TypeError is being constructed for the arguments alone, and not for the method signature. Probably a callee of report_mismatched_types.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Feb 16, 2017

triage: P-high - serious diagnostic regression, assign to @pnkfelix.

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Feb 17, 2017

While doing something else around type errors, I realized by chance why this was happening.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Feb 21, 2017

(seems like #39905 will fix this.)

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 24, 2017

Rollup merge of rust-lang#39905 - estebank:useless-error, r=arielb1
Properly display note/expected details

Given a file

```rust
fn takes_cb(f: fn(i8)) {}

fn main() {
    fn callback(x: i32) {}
    takes_cb(callback)
}
```

output

```rust
error[E0308]: mismatched types
 --> file2.rs:5:22
  |
5 |             takes_cb(callback)
  |                      ^^^^^^^^ expected i8, found i32
  |
  = note: expected type `fn(i8)`
             found type `fn(i32) {main::callback}`
```

Fix rust-lang#39343.

eddyb added a commit to eddyb/rust that referenced this issue Feb 25, 2017

Rollup merge of rust-lang#39905 - estebank:useless-error, r=arielb1
Properly display note/expected details

Given a file

```rust
fn takes_cb(f: fn(i8)) {}

fn main() {
    fn callback(x: i32) {}
    takes_cb(callback)
}
```

output

```rust
error[E0308]: mismatched types
 --> file2.rs:5:22
  |
5 |             takes_cb(callback)
  |                      ^^^^^^^^ expected i8, found i32
  |
  = note: expected type `fn(i8)`
             found type `fn(i32) {main::callback}`
```

Fix rust-lang#39343.

eddyb added a commit to eddyb/rust that referenced this issue Feb 25, 2017

Rollup merge of rust-lang#39905 - estebank:useless-error, r=arielb1
Properly display note/expected details

Given a file

```rust
fn takes_cb(f: fn(i8)) {}

fn main() {
    fn callback(x: i32) {}
    takes_cb(callback)
}
```

output

```rust
error[E0308]: mismatched types
 --> file2.rs:5:22
  |
5 |             takes_cb(callback)
  |                      ^^^^^^^^ expected i8, found i32
  |
  = note: expected type `fn(i8)`
             found type `fn(i32) {main::callback}`
```

Fix rust-lang#39343.

@bors bors closed this in #39905 Feb 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.