Skip to content

Integer mismatch incorrectly suggests T::from() as LHS of assignment #79756

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

Closed
Reconcyl opened this issue Dec 6, 2020 · 1 comment
Closed
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Reconcyl
Copy link

Reconcyl commented Dec 6, 2020

I tried the following code (playground link):

fn main() {
    let mut a: u8 = 0;
    let b: u32 = 0;
    a = b;
}

I expected the compiler to recommend using b.try_into().unwrap() to convert it into a u8. This seems to have been the case in version 1.37.0. Instead, it produces the following error message on stable, beta, and nightly:

error[E0308]: mismatched types
 --> src/main.rs:4:9
  |
4 |     a = b;
  |         ^ expected `u8`, found `u32`
  |
help: you can convert `a` from `u8` to `u32`, matching the type of `b`
  |
4 |     u32::from(a) = b;
  |     ^^^^^^^^^^^^

The suggestion is incorrect, as the return value of a function call is not assignable.

@Reconcyl Reconcyl added the C-bug Category: This is a bug. label Dec 6, 2020
@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 6, 2020
@camelid camelid self-assigned this Dec 6, 2020
@camelid camelid removed their assignment Dec 25, 2020
@camelid
Copy link
Member

camelid commented Jan 28, 2021

Fixed in #81325.

@camelid camelid closed this as completed Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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

3 participants