-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
leonardo-mrossmacarthur and eopb
Metadata
Metadata
Assignees
Labels
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.