- Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-unused_assignmentsLint: unused_assignmentsLint: unused_assignmentsT-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
code like this causes a proper warning
fn main() { let mut a; let b = 4; let c = 5; a = b; a = c; println!("{}", a); }=>
warning: value assigned to `a` is never read --> src/main.rs:6:5 | 6 | a = b; | ^ | = note: #[warn(unused_assignments)] on by default however if a is a struct field, I get no warning at all.
struct Foo { x: i32, } fn main() { let mut strct = Foo { x: 0, // maybe warn here, too? }; let b = 4; let c = 5; strct.x = b; // please warn! strct.x = c; println!("{}", strct.x); }playground: https://play.rust-lang.org/?gist=c904ff202754b2691e2968977620fd7a&version=nightly
I ran into bugs in my code that could have been prevented by warning about this :(
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.L-unused_assignmentsLint: unused_assignmentsLint: unused_assignmentsT-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.