Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2375dc0
unions: test move behavior of non-Copy fields
RalfJung Aug 15, 2020
fe21e4c
please tidy
RalfJung Aug 15, 2020
9c16cc2
make union-drop mem::forget test meaningful
RalfJung Aug 30, 2020
b1e481d
Simplify iter zip struct doc
pickfire Sep 12, 2020
8a261a2
Simplify SyncOnceCell's `take` and `drop`.
m-ou-se Sep 12, 2020
73e0a56
Make all methods of `Duration` const
CDirkx Sep 4, 2020
869021e
Add mailmap entry
CDirkx Sep 12, 2020
aa68aaa
Mark Once::new as #[inline].
m-ou-se Sep 12, 2020
4f0047e
Add a comment on is_trivially_sized about obviously !Sized types
nox Sep 12, 2020
75f0f7a
Fix a typo
nox Sep 12, 2020
caf6c92
Clean up some language trait items comparisons
nox Sep 12, 2020
2eeb8f1
Remove Windows details from Unix and VmWorks symlink() docstrings
nicholasbishop Sep 12, 2020
f75d29f
reduce size of test_from_iter_specialization_with_iterator_adapters t…
RalfJung Sep 13, 2020
bb41740
fix slice::check_range aliasing problems
RalfJung Sep 13, 2020
1500ced
Rollup merge of #75559 - RalfJung:union-test-move, r=joshtriplett
RalfJung Sep 13, 2020
b0d59f4
Rollup merge of #76335 - CDirkx:const-duration, r=ecstatic-morse
RalfJung Sep 13, 2020
945189a
Rollup merge of #76629 - pickfire:patch-4, r=jonas-schievink
RalfJung Sep 13, 2020
70fb791
Rollup merge of #76640 - fusion-engineering-forks:synconcecell-drop, …
RalfJung Sep 13, 2020
fc75c48
Rollup merge of #76641 - nox:pointee-random-stuff, r=eddyb
RalfJung Sep 13, 2020
68369ac
Rollup merge of #76646 - CDirkx:mailmap, r=Mark-Simulacrum
RalfJung Sep 13, 2020
004800c
Rollup merge of #76651 - nicholasbishop:bishop-remove-windows-note, r…
RalfJung Sep 13, 2020
e247c59
Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-Simulacrum
RalfJung Sep 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/test/ui/union/union-drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ fn main() {
{
let y = Y { a: S };
}
assert_eq!(CHECK, 2); // 2, dtor of Y is called
assert_eq!(CHECK, 2); // 2, Y has no dtor
{
let u2 = U { a: 1 };
std::mem::forget(u2);
}
assert_eq!(CHECK, 2); // 2, dtor of U *not* called for u2
}
}
53 changes: 53 additions & 0 deletions src/test/ui/union/union-move.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Test the behavior of moving out of non-`Copy` union fields.
//! Avoid types that `Drop`, we want to focus on moving.
#![feature(untagged_unions)]

use std::cell::RefCell;

fn move_out<T>(x: T) {}

union U1 {
f1_nocopy: RefCell<i32>,
f2_nocopy: RefCell<i32>,
f3_copy: i32,
}

union U2 {
f1_nocopy: RefCell<i32>,
}
impl Drop for U2 {
fn drop(&mut self) {}
}

fn test1(x: U1) {
// Moving out of a nocopy field prevents accessing other nocopy field.
unsafe {
move_out(x.f1_nocopy);
move_out(x.f2_nocopy); //~ ERROR use of moved value: `x`
}
}

fn test2(x: U1) {
// "Moving" out of copy field doesn't prevent later field accesses.
unsafe {
move_out(x.f3_copy);
move_out(x.f2_nocopy); // no error
}
}

fn test3(x: U1) {
// Moving out of a nocopy field prevents accessing other copy field.
unsafe {
move_out(x.f2_nocopy);
move_out(x.f3_copy); //~ ERROR use of moved value: `x`
}
}

fn test4(x: U2) {
// Cannot move out of union that implements `Drop`.
unsafe {
move_out(x.f1_nocopy); //~ ERROR cannot move out of type `U2`, which implements the `Drop`
}
}

fn main() {}
35 changes: 35 additions & 0 deletions src/test/ui/union/union-move.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0382]: use of moved value: `x`
--> $DIR/union-move.rs:26:18
|
LL | fn test1(x: U1) {
| - move occurs because `x` has type `U1`, which does not implement the `Copy` trait
...
LL | move_out(x.f1_nocopy);
| ----------- value moved here
LL | move_out(x.f2_nocopy);
| ^^^^^^^^^^^ value used here after move

error[E0382]: use of moved value: `x`
--> $DIR/union-move.rs:42:18
|
LL | fn test3(x: U1) {
| - move occurs because `x` has type `U1`, which does not implement the `Copy` trait
...
LL | move_out(x.f2_nocopy);
| ----------- value moved here
LL | move_out(x.f3_copy);
| ^^^^^^^^^ value used here after move

error[E0509]: cannot move out of type `U2`, which implements the `Drop` trait
--> $DIR/union-move.rs:49:18
|
LL | move_out(x.f1_nocopy);
| ^^^^^^^^^^^
| |
| cannot move out of here
| move occurs because `x.f1_nocopy` has type `std::cell::RefCell<i32>`, which does not implement the `Copy` trait

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0382, E0509.
For more information about an error, try `rustc --explain E0382`.