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

Incorrect error message location #70082

Closed
s3bk opened this issue Mar 17, 2020 · 3 comments · Fixed by #110825
Closed

Incorrect error message location #70082

s3bk opened this issue Mar 17, 2020 · 3 comments · Fixed by #110825
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@s3bk
Copy link
Contributor

s3bk commented Mar 17, 2020

I tried this code:

// the error is reported here
let em = |v: f64| -> f64 { v };

let x: f64 = em(1i16.into());

// but originates here
let y: f64 = 0.01f64 * 1i16.into();

(playground)

The error message:

error[E0284]: type annotations needed for `f64`
 --> src/main.rs:3:15
  |
3 |     let em = |v: f64| -> f64 { v };
  |               ^ consider giving this closure parameter a type
  |
  = note: cannot resolve `<f64 as std::ops::Mul<_>>::Output == f64`

I expected to see this happen: The error is reported on the line for y.

Instead, this happened: The error is reported for the closure…

Meta

Nighty, Beta and Stable affected.

@s3bk s3bk added the C-bug Category: This is a bug. label Mar 17, 2020
@bjorn3
Copy link
Member

bjorn3 commented Mar 17, 2020

@rustbot modify labels: +A-diagnostics +C-bug +D-incorrect

(someone other than the issue creator do this?)

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Mar 17, 2020
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 17, 2020
@tirr-c
Copy link
Contributor

tirr-c commented Mar 23, 2020

More minimal repro:

fn main() {
    |_: f64| {};
    let _: f64 = 0.0 * 0.into();
}

The closure just needs to be exist anywhere inside main. Even this code reports the same error:

fn main() {
    |_: f64| -> f64 {
        0.0 * 0.into()
    };
}

Edit: this triggers the same issue:

fn f() {
    |_| 0;
    0 * 0.into();
}

@contrun
Copy link
Contributor

contrun commented Apr 8, 2020

This is essentially the same issue as #69455.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 26, 2023
…=compiler-errors

diagnostics: add test case for already-solved issue

Fixes rust-lang#70082
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 26, 2023
…=compiler-errors

diagnostics: add test case for already-solved issue

Fixes rust-lang#70082
@bors bors closed this as completed in 1bfbac7 Apr 26, 2023
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 C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants