Open
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;
}