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

Wrong suggestion usize::from for LHS expression #81293

Closed
tesuji opened this issue Jan 23, 2021 · 0 comments · Fixed by #81325
Closed

Wrong suggestion usize::from for LHS expression #81293

tesuji opened this issue Jan 23, 2021 · 0 comments · Fixed by #81325
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented Jan 23, 2021

I try this code: (Playground)

fn main() {
    let a: u16;
    let b: u16 = 42;
    let c: usize = 5;

    a = c + b * 5;
}

I expect to see this happen: No invalid suggestion for usize::from(a) = c + b*5.

Instead, I got this errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:6:13
  |
6 |     a = c + b * 5;
  |             ^^^^^ expected `usize`, found `u16`

error[E0308]: mismatched types
 --> src/main.rs:6:9
  |
6 |     a = c + b * 5;
  |         ^^^^^^^^^ expected `u16`, found `usize`
  |
help: you can convert `a` from `u16` to `usize`, matching the type of `c + b * 5`
  |
6 |     usize::from(a) = c + b * 5;
  |     ^^^^^^^^^^^^^^

error[E0277]: cannot add `u16` to `usize`
 --> src/main.rs:6:11
  |
6 |     a = c + b * 5;
  |           ^ no implementation for `usize + u16`
  |
  = help: the trait `Add<u16>` is not implemented for `usize`

@rustbot label D-invalid-suggestion T-compiler

@rustbot rustbot added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 23, 2021
@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. labels Jan 23, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 26, 2021
typeck: Don't suggest converting LHS exprs

Converting LHS of an assignment does not work, so avoid suggesting that.

Fixes rust-lang#81293
@bors bors closed this as completed in d035be8 Jan 26, 2021
zaharidichev pushed a commit to zaharidichev/rust that referenced this issue Mar 15, 2021
Converting LHS of an assignment does not work, so avoid suggesting that.

Fixes rust-lang#81293
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. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

3 participants