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
Closed

Mismatched type errors have become useless #39343

nagisa opened this issue Jan 27, 2017 · 7 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

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 Area: Messages for errors, warnings, and lints label Jan 27, 2017
@eddyb
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.

@arielb1 arielb1 added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Feb 2, 2017
@brson brson added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 9, 2017
@nikomatsakis
Copy link
Contributor

@eddyb any clues what change might have caused that?

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

@sophiajt
Copy link
Contributor

sophiajt 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
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
Copy link
Contributor

arielb1 commented Feb 16, 2017

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

@estebank
Copy link
Contributor

estebank commented Feb 17, 2017

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

@pnkfelix
Copy link
Member

(seems like #39905 will fix this.)

frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 24, 2017
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
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
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants