-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-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
This code should ideally trigger warnings about unused assignments, but it doesn't.
struct Pos {
x: i32
}
fn foo() -> Pos{
Pos{x: 2}
}
fn main() {
foo().x += 1; // Unused assignment
let mut f = Pos { x: 2 };
f.x = 2; // Unused assignment
}
It could be useful in situations like this:
struct Property {
x: i32
}
struct Foo {
prop: Property
}
impl Foo {
fn prop(&self) -> Property {
self.prop
}
fn mut_prop(&mut self) -> &mut Property {
&mut self.prop
}
}
fn main() {
let mut foo = Foo{prop: Property{x: 2}};
foo.prop().x += 2; // Oops, accidentally called prop() instead of mut_prop()
foo.mut_prop().x += 2;
}
Metadata
Metadata
Assignees
Labels
A-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.