2025-07-01 23:37:49 +05:00
|
|
|
//! Checks borrow after move error when using `self` consuming method with struct update syntax.
|
|
|
|
|
|
|
|
|
|
struct Mine {
|
2014-11-05 15:05:01 -08:00
|
|
|
test: String,
|
2025-07-01 23:37:49 +05:00
|
|
|
other_val: isize,
|
2014-11-05 15:05:01 -08:00
|
|
|
}
|
|
|
|
|
|
2025-07-01 23:37:49 +05:00
|
|
|
impl Mine {
|
|
|
|
|
fn make_string_bar(mut self) -> Mine {
|
2014-11-05 15:05:01 -08:00
|
|
|
self.test = "Bar".to_string();
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 23:37:49 +05:00
|
|
|
fn main() {
|
|
|
|
|
let start = Mine { test: "Foo".to_string(), other_val: 0 };
|
|
|
|
|
let end = Mine { other_val: 1, ..start.make_string_bar() };
|
2019-04-22 08:40:08 +01:00
|
|
|
println!("{}", start.test); //~ ERROR borrow of moved value: `start`
|
2014-11-05 15:05:01 -08:00
|
|
|
}
|