Closed
Description
In this code, the call to start.make_string_bar() should move start, but start can still be used by the println:
struct Mine{
test: String,
other_val: int
}
impl Mine{
fn make_string_bar(mut self) -> Mine{
self.test = "Bar".to_string();
self
}
}
fn main(){
let start = Mine{test:"Foo".to_string(), other_val:0};
let end = Mine{other_val:1, ..start.make_string_bar()};
println!("{}", start.test);
}
This specific example of the bug doesn't do anything terrible for me, it just doesn't print anything. However, this appears to trample variable values, as I first ran into this with more complex code where it caused a segfault.
Changing start.test
in the println to end.test
prints bar, as expected. Changing Mine{other_val:1, ..start.make_string_bar()}
to Mine{other_val:1, ..start}
causes compiler errors at the println saying start has moved, which is also correct.
Metadata
Metadata
Assignees
Labels
No labels