2013-09-20 00:59:06 +00:00
|
|
|
// Issue 4691: Ensure that functional-struct-update can only copy, not
|
|
|
|
// move, when the struct implements Drop.
|
|
|
|
|
2015-08-12 00:27:05 +00:00
|
|
|
struct B;
|
Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.
```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:28:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
|
help: clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
| +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:20:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
|
note: `B` doesn't implement `Copy` or `Clone`
--> $DIR/borrowck-struct-update-with-dtor.rs:4:1
|
LL | struct B;
| ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
| +++++++++++++++++
```
2024-03-16 18:19:17 +00:00
|
|
|
struct S<K> { a: isize, b: B, c: K }
|
|
|
|
impl<K> Drop for S<K> { fn drop(&mut self) { } }
|
2013-09-20 00:59:06 +00:00
|
|
|
|
Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.
```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:28:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
|
help: clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
| +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:20:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
|
note: `B` doesn't implement `Copy` or `Clone`
--> $DIR/borrowck-struct-update-with-dtor.rs:4:1
|
LL | struct B;
| ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
| +++++++++++++++++
```
2024-03-16 18:19:17 +00:00
|
|
|
struct T { a: isize, b: Box<isize> }
|
2013-09-20 00:59:06 +00:00
|
|
|
impl Drop for T { fn drop(&mut self) { } }
|
|
|
|
|
Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.
```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:28:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
|
help: clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
| +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:20:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
|
note: `B` doesn't implement `Copy` or `Clone`
--> $DIR/borrowck-struct-update-with-dtor.rs:4:1
|
LL | struct B;
| ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
| +++++++++++++++++
```
2024-03-16 18:19:17 +00:00
|
|
|
struct V<K> { a: isize, b: Box<isize>, c: K }
|
|
|
|
impl<K> Drop for V<K> { fn drop(&mut self) { } }
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct Clonable;
|
|
|
|
|
|
|
|
mod not_all_clone {
|
|
|
|
use super::*;
|
|
|
|
fn a(s0: S<()>) {
|
|
|
|
let _s2 = S { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
}
|
|
|
|
fn b(s0: S<B>) {
|
|
|
|
let _s2 = S { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
//~| ERROR [E0509]
|
|
|
|
}
|
|
|
|
fn c<K: Clone>(s0: S<K>) {
|
|
|
|
let _s2 = S { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
//~| ERROR [E0509]
|
|
|
|
}
|
2013-09-20 00:59:06 +00:00
|
|
|
}
|
Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.
```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:28:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
|
help: clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
| +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:20:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
|
note: `B` doesn't implement `Copy` or `Clone`
--> $DIR/borrowck-struct-update-with-dtor.rs:4:1
|
LL | struct B;
| ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
| +++++++++++++++++
```
2024-03-16 18:19:17 +00:00
|
|
|
mod all_clone {
|
|
|
|
use super::*;
|
|
|
|
fn a(s0: T) {
|
|
|
|
let _s2 = T { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn b(s0: T) {
|
|
|
|
let _s2 = T { ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn c(s0: T) {
|
|
|
|
let _s2 = T { a: 2, b: s0.b };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn d<K: Clone>(s0: V<K>) {
|
|
|
|
let _s2 = V { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
//~| ERROR [E0509]
|
|
|
|
}
|
2013-09-20 00:59:06 +00:00
|
|
|
|
Account for move error in the spread operator on struct literals
We attempt to suggest an appropriate clone for move errors on expressions
like `S { ..s }` where a field isn't `Copy`. If we can't suggest, we still don't
emit the incorrect suggestion of `S { ..s }.clone()`.
```
error[E0509]: cannot move out of type `S<K>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:28:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.c` has type `K`, which does not implement the `Copy` trait
|
help: clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, c: s0.c.clone(), ..s0 };
| +++++++++++++++++
```
```
error[E0509]: cannot move out of type `S<()>`, which implements the `Drop` trait
--> $DIR/borrowck-struct-update-with-dtor.rs:20:19
|
LL | let _s2 = S { a: 2, ..s0 };
| ^^^^^^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `s0.b` has type `B`, which does not implement the `Copy` trait
|
note: `B` doesn't implement `Copy` or `Clone`
--> $DIR/borrowck-struct-update-with-dtor.rs:4:1
|
LL | struct B;
| ^^^^^^^^
help: if `B` implemented `Clone`, you could clone the value from the field instead of using the spread operator syntax
|
LL | let _s2 = S { a: 2, b: s0.b.clone(), ..s0 };
| +++++++++++++++++
```
2024-03-16 18:19:17 +00:00
|
|
|
fn e(s0: V<Clonable>) {
|
|
|
|
let _s2 = V { a: 2, ..s0 };
|
|
|
|
//~^ ERROR [E0509]
|
|
|
|
//~| ERROR [E0509]
|
|
|
|
}
|
2013-09-20 00:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|