forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67314 - matthewjasper:union-move-errors, r=…
…nikomatsakis Don't suppress move errors for union fields closes rust-lang#66500
- Loading branch information
Showing
3 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Moving from a reference/raw pointer should be an error, even when they're | ||
// the field of a union. | ||
|
||
#![feature(untagged_unions)] | ||
|
||
union Pointers { | ||
a: &'static String, | ||
b: &'static mut String, | ||
c: *const String, | ||
d: *mut String, | ||
} | ||
|
||
unsafe fn move_ref(u: Pointers) -> String { | ||
*u.a | ||
//~^ ERROR cannot move out of `*u.a` | ||
} | ||
unsafe fn move_ref_mut(u: Pointers) -> String { | ||
*u.b | ||
//~^ ERROR cannot move out of `*u.b` | ||
} | ||
unsafe fn move_ptr(u: Pointers) -> String { | ||
*u.c | ||
//~^ ERROR cannot move out of `*u.c` | ||
} | ||
unsafe fn move_ptr_mut(u: Pointers) -> String { | ||
*u.d | ||
//~^ ERROR cannot move out of `*u.d` | ||
} | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/borrowck/move-from-union-field-issue-66500.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0507]: cannot move out of `*u.a` which is behind a shared reference | ||
--> $DIR/move-from-union-field-issue-66500.rs:14:5 | ||
| | ||
LL | *u.a | ||
| ^^^^ move occurs because `*u.a` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0507]: cannot move out of `*u.b` which is behind a mutable reference | ||
--> $DIR/move-from-union-field-issue-66500.rs:18:5 | ||
| | ||
LL | *u.b | ||
| ^^^^ move occurs because `*u.b` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0507]: cannot move out of `*u.c` which is behind a raw pointer | ||
--> $DIR/move-from-union-field-issue-66500.rs:22:5 | ||
| | ||
LL | *u.c | ||
| ^^^^ move occurs because `*u.c` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error[E0507]: cannot move out of `*u.d` which is behind a raw pointer | ||
--> $DIR/move-from-union-field-issue-66500.rs:26:5 | ||
| | ||
LL | *u.d | ||
| ^^^^ move occurs because `*u.d` has type `std::string::String`, which does not implement the `Copy` trait | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0507`. |