Skip to content

Wrong error message for missed type inference #71584

Closed
@leonardo-m

Description

@leonardo-m

Code that asks for some type inference:

fn main() {
    let n: u32 = 1;
    let mut d: u64 = 2;
    d = d % n.into();
}

It gives:

error[E0284]: type annotations needed for `u64`
 --> ...\test.rs:4:11
  |
3 |     let mut d: u64 = 2;
  |         ----- consider giving `d` a type
4 |     d = d % n.into();
  |           ^ cannot infer type for type `u64`
  |
  = note: cannot satisfy `<u64 as std::ops::Rem<_>>::Output == u64`

The error message "consider giving d a type" refers to a "d" that is actually typed as u64.
Using rustc 1.44.0-nightly (3360cc3 2020-04-24).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions