Skip to content

Commit a927d11

Browse files
committed
walk-struct-literal-with
1 parent b1086ce commit a927d11

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
struct Mine{
1+
//! Checks borrow after move error when using `self` consuming method with struct update syntax.
2+
3+
struct Mine {
24
test: String,
3-
other_val: isize
5+
other_val: isize,
46
}
57

6-
impl Mine{
7-
fn make_string_bar(mut self) -> Mine{
8+
impl Mine {
9+
fn make_string_bar(mut self) -> Mine {
810
self.test = "Bar".to_string();
911
self
1012
}
1113
}
1214

13-
fn main(){
14-
let start = Mine{test:"Foo".to_string(), other_val:0};
15-
let end = Mine{other_val:1, ..start.make_string_bar()};
15+
fn main() {
16+
let start = Mine { test: "Foo".to_string(), other_val: 0 };
17+
let end = Mine { other_val: 1, ..start.make_string_bar() };
1618
println!("{}", start.test); //~ ERROR borrow of moved value: `start`
1719
}

tests/ui/borrowck/ownership-struct-update-moved-error.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0382]: borrow of moved value: `start`
2-
--> $DIR/walk-struct-literal-with.rs:16:20
2+
--> $DIR/ownership-struct-update-moved-error.rs:18:20
33
|
4-
LL | let start = Mine{test:"Foo".to_string(), other_val:0};
4+
LL | let start = Mine { test: "Foo".to_string(), other_val: 0 };
55
| ----- move occurs because `start` has type `Mine`, which does not implement the `Copy` trait
6-
LL | let end = Mine{other_val:1, ..start.make_string_bar()};
7-
| ----------------- `start` moved due to this method call
6+
LL | let end = Mine { other_val: 1, ..start.make_string_bar() };
7+
| ----------------- `start` moved due to this method call
88
LL | println!("{}", start.test);
99
| ^^^^^^^^^^ value borrowed here after move
1010
|
1111
note: `Mine::make_string_bar` takes ownership of the receiver `self`, which moves `start`
12-
--> $DIR/walk-struct-literal-with.rs:7:28
12+
--> $DIR/ownership-struct-update-moved-error.rs:9:28
1313
|
14-
LL | fn make_string_bar(mut self) -> Mine{
14+
LL | fn make_string_bar(mut self) -> Mine {
1515
| ^^^^
1616
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

0 commit comments

Comments
 (0)