Skip to content

Commit 84ca0a1

Browse files
SimonSapinoli-obk
authored andcommitted
Remove most uses of allow(unions_with_drop_fields) in tests
1 parent 0a08841 commit 84ca0a1

14 files changed

+118
-121
lines changed

src/test/ui/associated-type-bounds/union-bounds.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#![feature(associated_type_bounds)]
44
#![feature(untagged_unions)]
55

6-
#![allow(unions_with_drop_fields, unused_assignments)]
6+
#![allow(unused_assignments)]
77

8-
trait Tr1 { type As1; }
9-
trait Tr2 { type As2; }
10-
trait Tr3 { type As3; }
11-
trait Tr4<'a> { type As4; }
12-
trait Tr5 { type As5; }
8+
trait Tr1: Copy { type As1: Copy; }
9+
trait Tr2: Copy { type As2: Copy; }
10+
trait Tr3: Copy { type As3: Copy; }
11+
trait Tr4<'a>: Copy { type As4: Copy; }
12+
trait Tr5: Copy { type As5: Copy; }
1313

1414
impl Tr1 for &str { type As1 = bool; }
1515
impl Tr2 for bool { type As2 = u8; }
@@ -71,7 +71,8 @@ where
7171
let _: &'a T = &x.f0;
7272
}
7373

74-
union UnSelf<T> where Self: Tr1<As1: Tr2> {
74+
#[derive(Copy, Clone)]
75+
union UnSelf<T> where Self: Tr1<As1: Tr2>, T: Copy {
7576
f0: T,
7677
f1: <Self as Tr1>::As1,
7778
f2: <<Self as Tr1>::As1 as Tr2>::As2,

src/test/ui/drop/dynamic-drop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(slice_patterns)]
99

1010
use std::cell::{Cell, RefCell};
11+
use std::mem::ManuallyDrop;
1112
use std::ops::Generator;
1213
use std::panic;
1314
use std::pin::Pin;
@@ -152,17 +153,16 @@ fn assignment1(a: &Allocator, c0: bool) {
152153
_v = _w;
153154
}
154155

155-
#[allow(unions_with_drop_fields)]
156156
union Boxy<T> {
157-
a: T,
158-
b: T,
157+
a: ManuallyDrop<T>,
158+
b: ManuallyDrop<T>,
159159
}
160160

161161
fn union1(a: &Allocator) {
162162
unsafe {
163-
let mut u = Boxy { a: a.alloc() };
164-
u.b = a.alloc();
165-
drop(u.a);
163+
let mut u = Boxy { a: ManuallyDrop::new(a.alloc()) };
164+
*u.b = a.alloc(); // drops first alloc
165+
drop(ManuallyDrop::into_inner(u.a));
166166
}
167167
}
168168

src/test/ui/rfc-2093-infer-outlives/explicit-union.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#![feature(rustc_attrs)]
22
#![feature(untagged_unions)]
3-
#![allow(unions_with_drop_fields)]
43

54
#[rustc_outlives]
6-
union Foo<'b, U> { //~ ERROR rustc_outlives
5+
union Foo<'b, U: Copy> { //~ ERROR rustc_outlives
76
bar: Bar<'b, U>
87
}
98

10-
union Bar<'a, T> where T: 'a {
9+
union Bar<'a, T: Copy> where T: 'a {
1110
x: &'a (),
1211
y: T,
1312
}

src/test/ui/rfc-2093-infer-outlives/nested-union.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![feature(rustc_attrs)]
22
#![feature(untagged_unions)]
3-
#![allow(unions_with_drop_fields)]
43

54
#[rustc_outlives]
6-
union Foo<'a, T> { //~ ERROR rustc_outlives
5+
union Foo<'a, T: Copy> { //~ ERROR rustc_outlives
76
field1: Bar<'a, T>
87
}
98

109
// Type U needs to outlive lifetime 'b
11-
union Bar<'b, U> {
10+
union Bar<'b, U: Copy> {
1211
field2: &'b U
1312
}
1413

src/test/ui/self/self-in-typedefs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#![feature(untagged_unions)]
44

55
#![allow(dead_code)]
6-
#![allow(unions_with_drop_fields)]
6+
7+
use std::mem::ManuallyDrop;
78

89
enum A<'a, T: 'a>
910
where
@@ -24,6 +25,14 @@ where
2425
union C<'a, T: 'a>
2526
where
2627
Self: Send, T: PartialEq<Self>
28+
{
29+
foo: &'a Self,
30+
bar: ManuallyDrop<T>,
31+
}
32+
33+
union D<'a, T: 'a>
34+
where
35+
Self: Send, T: PartialEq<Self> + Copy
2736
{
2837
foo: &'a Self,
2938
bar: T,

src/test/ui/union/union-borrow-move-parent-sibling.rs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,90 @@
11
#![feature(untagged_unions)]
22
#![allow(unused)]
33

4-
#[allow(unions_with_drop_fields)]
4+
use std::ops::{Deref, DerefMut};
5+
6+
#[derive(Default)]
7+
struct MockBox<T> {
8+
value: [T; 1],
9+
}
10+
11+
impl<T> MockBox<T> {
12+
fn new(value: T) -> Self { MockBox { value: [value] } }
13+
}
14+
15+
impl<T> Deref for MockBox<T> {
16+
type Target = T;
17+
fn deref(&self) -> &T { &self.value[0] }
18+
}
19+
20+
impl<T> DerefMut for MockBox<T> {
21+
fn deref_mut(&mut self) -> &mut T { &mut self.value[0] }
22+
}
23+
24+
#[derive(Default)]
25+
struct MockVec<T> {
26+
value: [T; 0],
27+
}
28+
29+
impl<T> MockVec<T> {
30+
fn new() -> Self { MockVec { value: [] } }
31+
}
32+
33+
impl<T> Deref for MockVec<T> {
34+
type Target = [T];
35+
fn deref(&self) -> &[T] { &self.value }
36+
}
37+
38+
impl<T> DerefMut for MockVec<T> {
39+
fn deref_mut(&mut self) -> &mut [T] { &mut self.value }
40+
}
41+
42+
543
union U {
6-
x: ((Vec<u8>, Vec<u8>), Vec<u8>),
7-
y: Box<Vec<u8>>,
44+
x: ((MockVec<u8>, MockVec<u8>), MockVec<u8>),
45+
y: MockBox<MockVec<u8>>,
846
}
947

1048
fn use_borrow<T>(_: &T) {}
1149

1250
unsafe fn parent_sibling_borrow() {
13-
let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
51+
let mut u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
1452
let a = &mut u.x.0;
1553
let b = &u.y; //~ ERROR cannot borrow `u` (via `u.y`)
1654
use_borrow(a);
1755
}
1856

1957
unsafe fn parent_sibling_move() {
20-
let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
58+
let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
2159
let a = u.x.0;
2260
let b = u.y; //~ ERROR use of moved value: `u`
2361
}
2462

2563
unsafe fn grandparent_sibling_borrow() {
26-
let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
64+
let mut u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
2765
let a = &mut (u.x.0).0;
2866
let b = &u.y; //~ ERROR cannot borrow `u` (via `u.y`)
2967
use_borrow(a);
3068
}
3169

3270
unsafe fn grandparent_sibling_move() {
33-
let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
71+
let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
3472
let a = (u.x.0).0;
3573
let b = u.y; //~ ERROR use of moved value: `u`
3674
}
3775

3876
unsafe fn deref_sibling_borrow() {
39-
let mut u = U { y: Box::default() };
77+
let mut u = U { y: MockBox::default() };
4078
let a = &mut *u.y;
4179
let b = &u.x; //~ ERROR cannot borrow `u` (via `u.x`)
4280
use_borrow(a);
4381
}
4482

4583
unsafe fn deref_sibling_move() {
46-
let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
47-
let a = *u.y;
48-
let b = u.x; //~ ERROR use of moved value: `u`
84+
let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
85+
// No way to test deref-move without Box in union
86+
// let a = *u.y;
87+
// let b = u.x; ERROR use of moved value: `u`
4988
}
5089

5190

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x.0`)
2-
--> $DIR/union-borrow-move-parent-sibling.rs:15:13
2+
--> $DIR/union-borrow-move-parent-sibling.rs:54:13
33
|
44
LL | let a = &mut u.x.0;
55
| ---------- mutable borrow occurs here (via `u.x.0`)
@@ -11,17 +11,17 @@ LL | use_borrow(a);
1111
= note: `u.y` is a field of the union `U`, so it overlaps the field `u.x.0`
1212

1313
error[E0382]: use of moved value: `u`
14-
--> $DIR/union-borrow-move-parent-sibling.rs:22:13
14+
--> $DIR/union-borrow-move-parent-sibling.rs:61:13
1515
|
16-
LL | let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
16+
LL | let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
1717
| - move occurs because `u` has type `U`, which does not implement the `Copy` trait
1818
LL | let a = u.x.0;
1919
| ----- value moved here
2020
LL | let b = u.y;
2121
| ^^^ value used here after move
2222

2323
error[E0502]: cannot borrow `u` (via `u.y`) as immutable because it is also borrowed as mutable (via `u.x.0.0`)
24-
--> $DIR/union-borrow-move-parent-sibling.rs:28:13
24+
--> $DIR/union-borrow-move-parent-sibling.rs:67:13
2525
|
2626
LL | let a = &mut (u.x.0).0;
2727
| -------------- mutable borrow occurs here (via `u.x.0.0`)
@@ -33,38 +33,28 @@ LL | use_borrow(a);
3333
= note: `u.y` is a field of the union `U`, so it overlaps the field `u.x.0.0`
3434

3535
error[E0382]: use of moved value: `u`
36-
--> $DIR/union-borrow-move-parent-sibling.rs:35:13
36+
--> $DIR/union-borrow-move-parent-sibling.rs:74:13
3737
|
38-
LL | let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
38+
LL | let u = U { x: ((MockVec::new(), MockVec::new()), MockVec::new()) };
3939
| - move occurs because `u` has type `U`, which does not implement the `Copy` trait
4040
LL | let a = (u.x.0).0;
4141
| --------- value moved here
4242
LL | let b = u.y;
4343
| ^^^ value used here after move
4444

45-
error[E0502]: cannot borrow `u` (via `u.x`) as immutable because it is also borrowed as mutable (via `*u.y`)
46-
--> $DIR/union-borrow-move-parent-sibling.rs:41:13
45+
error[E0502]: cannot borrow `u` (via `u.x`) as immutable because it is also borrowed as mutable (via `u.y`)
46+
--> $DIR/union-borrow-move-parent-sibling.rs:80:13
4747
|
4848
LL | let a = &mut *u.y;
49-
| --------- mutable borrow occurs here (via `*u.y`)
49+
| --- mutable borrow occurs here (via `u.y`)
5050
LL | let b = &u.x;
51-
| ^^^^ immutable borrow of `u.x` -- which overlaps with `*u.y` -- occurs here
51+
| ^^^^ immutable borrow of `u.x` -- which overlaps with `u.y` -- occurs here
5252
LL | use_borrow(a);
5353
| - mutable borrow later used here
5454
|
55-
= note: `u.x` is a field of the union `U`, so it overlaps the field `*u.y`
55+
= note: `u.x` is a field of the union `U`, so it overlaps the field `u.y`
5656

57-
error[E0382]: use of moved value: `u`
58-
--> $DIR/union-borrow-move-parent-sibling.rs:48:13
59-
|
60-
LL | let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) };
61-
| - move occurs because `u` has type `U`, which does not implement the `Copy` trait
62-
LL | let a = *u.y;
63-
| ---- value moved here
64-
LL | let b = u.x;
65-
| ^^^ value used here after move
66-
67-
error: aborting due to 6 previous errors
57+
error: aborting due to 5 previous errors
6858

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

src/test/ui/union/union-derive-rpass.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// run-pass
22
#![allow(dead_code)]
33
#![allow(unused_variables)]
4-
#![allow(unions_with_drop_fields)]
54

65
// Some traits can be derived for unions.
76

@@ -24,11 +23,11 @@ impl PartialEq for U { fn eq(&self, rhs: &Self) -> bool { true } }
2423
Copy,
2524
Eq
2625
)]
27-
union W<T> {
26+
union W<T: Copy> {
2827
a: T,
2928
}
3029

31-
impl<T> PartialEq for W<T> { fn eq(&self, rhs: &Self) -> bool { true } }
30+
impl<T: Copy> PartialEq for W<T> { fn eq(&self, rhs: &Self) -> bool { true } }
3231

3332
fn main() {
3433
let u = U { b: 0 };

src/test/ui/union/union-drop-assign.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// run-pass
22
#![allow(unused_assignments)]
3-
#![allow(unions_with_drop_fields)]
43

54
// Drop works for union itself.
65

76
#![feature(untagged_unions)]
87

8+
use std::mem::ManuallyDrop;
9+
910
struct S;
1011

1112
union U {
12-
a: S
13+
a: ManuallyDrop<S>
1314
}
1415

1516
impl Drop for S {
@@ -28,11 +29,11 @@ static mut CHECK: u8 = 0;
2829

2930
fn main() {
3031
unsafe {
31-
let mut u = U { a: S };
32+
let mut u = U { a: ManuallyDrop::new(S) };
3233
assert_eq!(CHECK, 0);
33-
u = U { a: S };
34+
u = U { a: ManuallyDrop::new(S) };
3435
assert_eq!(CHECK, 1); // union itself is assigned, union is dropped, field is not dropped
35-
u.a = S;
36+
*u.a = S;
3637
assert_eq!(CHECK, 11); // union field is assigned, field is dropped
3738
}
3839
}

src/test/ui/union/union-drop.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// run-pass
22
#![allow(dead_code)]
33
#![allow(unused_variables)]
4-
#![allow(unions_with_drop_fields)]
54

65
// Drop works for union itself.
76

@@ -21,12 +20,6 @@ union Y {
2120
a: S,
2221
}
2322

24-
impl Drop for S {
25-
fn drop(&mut self) {
26-
unsafe { CHECK += 10; }
27-
}
28-
}
29-
3023
impl Drop for U {
3124
fn drop(&mut self) {
3225
unsafe { CHECK += 1; }
@@ -51,10 +44,10 @@ fn main() {
5144
{
5245
let w = W { a: S };
5346
}
54-
assert_eq!(CHECK, 2); // 2, not 11, dtor of S is not called
47+
assert_eq!(CHECK, 2); // 2, dtor of W is called
5548
{
5649
let y = Y { a: S };
5750
}
58-
assert_eq!(CHECK, 2); // 2, not 12, dtor of S is not called
51+
assert_eq!(CHECK, 2); // 2, dtor of Y is called
5952
}
6053
}

0 commit comments

Comments
 (0)