Closed
Description
Code
fn change_val(mut val: &mut i32) {
val = &mut 10;
}
Current output
warning: value assigned to `val` is never read
--> src/lib.rs:2:5
|
2 | val = &mut 10;
| ^^^
|
= note: `#[warn(unused_assignments)]` on by default
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
|
1 ~ fn change_val(val: &mut mut i32) {
2 ~ *val = 10;
|
<other warning and error elided as they do not matter here>
Desired output
warning: value assigned to `val` is never read
--> src/lib.rs:2:5
|
2 | val = &mut 10;
| ^^^
|
= note: `#[warn(unused_assignments)]` on by default
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
|
1 ~ fn change_val(val: &mut i32) {
2 ~ *val = 10;
|
<other warning and error elided as they do not matter here>
Rationale and extra context
This hint was added in #134977. Encountered this while looking at #136026.
cc @estebank as you added this suggestion
Other cases
Rust Version
1.86.0-nightly (2025-01-23 99768c80a1c094a5cfc3)
Anything else?
No response
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.