Skip to content

Commit 7a24f8e

Browse files
committed
add array tests, cleanup, tidy, and bless
1 parent 1cf6f5c commit 7a24f8e

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

compiler/rustc_feature/src/removed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ declare_features! (
182182
(removed, unsafe_no_drop_flag, "1.0.0", None, None, None),
183183
/// Allows `union` fields that don't implement `Copy` as long as they don't have any drop glue.
184184
(removed, untagged_unions, "1.13.0", Some(55149), None,
185-
Some("unions with `Copy` and `MaybeUninit` fields are stable; there is no intent to stabilize more")),
185+
Some("unions with `Copy` and `ManuallyDrop` fields are stable; there is no intent to stabilize more")),
186186
/// Allows `#[unwind(..)]`.
187187
///
188188
/// Permits specifying whether a function should permit unwinding or abort on unwind.

compiler/rustc_typeck/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
421421
}
422422
_ => {
423423
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
424-
ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
424+
ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop())
425425
|| ty.is_copy_modulo_regions(tcx.at(span), param_env)
426426
}
427427
}

compiler/rustc_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ This API is completely unstable and subject to change.
7272
#![feature(once_cell)]
7373
#![feature(slice_partition_dedup)]
7474
#![feature(try_blocks)]
75+
#![feature(is_some_with)]
7576
#![recursion_limit = "256"]
7677

7778
#[macro_use]

src/test/ui/consts/invalid-union.32bit.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/invalid-union.rs:40:1
2+
--> $DIR/invalid-union.rs:41:1
33
|
44
LL | fn main() {
55
| ^^^^^^^^^ constructing invalid value at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in a `const`
@@ -10,7 +10,7 @@ LL | fn main() {
1010
}
1111

1212
error: erroneous constant used
13-
--> $DIR/invalid-union.rs:41:25
13+
--> $DIR/invalid-union.rs:42:25
1414
|
1515
LL | let _: &'static _ = &C;
1616
| ^^ referenced constant has errors
@@ -24,7 +24,7 @@ error: aborting due to 2 previous errors
2424
For more information about this error, try `rustc --explain E0080`.
2525
Future incompatibility report: Future breakage diagnostic:
2626
error: erroneous constant used
27-
--> $DIR/invalid-union.rs:41:25
27+
--> $DIR/invalid-union.rs:42:25
2828
|
2929
LL | let _: &'static _ = &C;
3030
| ^^ referenced constant has errors

src/test/ui/union/field_checks.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// ignore-tidy-linelength
21
use std::mem::ManuallyDrop;
32

43
union U1 { // OK
@@ -45,6 +44,10 @@ union U5Nested { // a nested union that drops is NOT OK
4544
nest: U5, //~ ERROR unions cannot contain fields that may need dropping
4645
}
4746

47+
union U5Nested2 { // for now we don't special-case empty arrays
48+
nest: [U5; 0], //~ ERROR unions cannot contain fields that may need dropping
49+
}
50+
4851
union U6 { // OK
4952
s: &'static i32,
5053
m: &'static mut i32,
@@ -54,4 +57,9 @@ union U7<T> { // OK
5457
f: (&'static mut i32, ManuallyDrop<T>, i32),
5558
}
5659

60+
union U8<T> { // OK
61+
f1: [(&'static mut i32, i32); 8],
62+
f2: [ManuallyDrop<T>; 2],
63+
}
64+
5765
fn main() {}

src/test/ui/union/field_checks.stderr

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0740]: unions cannot contain fields that may need dropping
2-
--> $DIR/field_checks.rs:25:5
2+
--> $DIR/field_checks.rs:24:5
33
|
44
LL | a: String,
55
| ^^^^^^^^^
@@ -11,7 +11,7 @@ LL | a: std::mem::ManuallyDrop<String>,
1111
| +++++++++++++++++++++++ +
1212

1313
error[E0740]: unions cannot contain fields that may need dropping
14-
--> $DIR/field_checks.rs:29:5
14+
--> $DIR/field_checks.rs:28:5
1515
|
1616
LL | a: std::cell::RefCell<i32>,
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL | a: std::mem::ManuallyDrop<std::cell::RefCell<i32>>,
2323
| +++++++++++++++++++++++ +
2424

2525
error[E0740]: unions cannot contain fields that may need dropping
26-
--> $DIR/field_checks.rs:33:5
26+
--> $DIR/field_checks.rs:32:5
2727
|
2828
LL | a: T,
2929
| ^^^^
@@ -35,7 +35,7 @@ LL | a: std::mem::ManuallyDrop<T>,
3535
| +++++++++++++++++++++++ +
3636

3737
error[E0740]: unions cannot contain fields that may need dropping
38-
--> $DIR/field_checks.rs:45:5
38+
--> $DIR/field_checks.rs:44:5
3939
|
4040
LL | nest: U5,
4141
| ^^^^^^^^
@@ -46,6 +46,18 @@ help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>
4646
LL | nest: std::mem::ManuallyDrop<U5>,
4747
| +++++++++++++++++++++++ +
4848

49-
error: aborting due to 4 previous errors
49+
error[E0740]: unions cannot contain fields that may need dropping
50+
--> $DIR/field_checks.rs:48:5
51+
|
52+
LL | nest: [U5; 0],
53+
| ^^^^^^^^^^^^^
54+
|
55+
= note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
56+
help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
57+
|
58+
LL | nest: std::mem::ManuallyDrop<[U5; 0]>,
59+
| +++++++++++++++++++++++ +
60+
61+
error: aborting due to 5 previous errors
5062

5163
For more information about this error, try `rustc --explain E0740`.

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
union U { //~ ERROR recursive type `U` has infinite size
32
a: u8,
43
b: std::mem::ManuallyDrop<U>,

src/test/ui/union/union-nonrepresentable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0072]: recursive type `U` has infinite size
2-
--> $DIR/union-nonrepresentable.rs:2:1
2+
--> $DIR/union-nonrepresentable.rs:1:1
33
|
44
LL | union U {
55
| ^^^^^^^ recursive type has infinite size

0 commit comments

Comments
 (0)