Skip to content

Commit 6dfede3

Browse files
committed
also allow arrays of allowed types
1 parent ec7152c commit 6dfede3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

compiler/rustc_passes/src/stability.rs

+5
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
785785
// allow tuples of allowed types
786786
tys.iter().all(|ty| allowed_union_field(tcx, param_env, ty))
787787
}
788+
ty::Array(elem, _len) => {
789+
// Like `Copy`, we do *not* special-case length 0.
790+
allowed_union_field(tcx, param_env, *elem)
791+
}
788792
_ => {
793+
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
789794
ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
790795
|| ty.is_copy_modulo_regions(tcx.at(DUMMY_SP), param_env)
791796
}

src/test/ui/feature-gates/feature-gate-untagged_unions.rs

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ union U23<T> { // OK
1717
a: (ManuallyDrop<T>, i32),
1818
}
1919

20+
union U24<T> { // OK
21+
a: [ManuallyDrop<T>; 2],
22+
}
23+
2024
union U3 {
2125
a: String, //~ ERROR unions cannot contain fields that may need dropping
2226
}

src/test/ui/feature-gates/feature-gate-untagged_unions.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: unions with non-`Copy` fields other than `ManuallyDrop<T>`, references, and tuples of such types are unstable
2-
--> $DIR/feature-gate-untagged_unions.rs:25:5
2+
--> $DIR/feature-gate-untagged_unions.rs:29:5
33
|
44
LL | a: std::cell::RefCell<i32>,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | a: std::cell::RefCell<i32>,
88
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable
99

1010
error[E0740]: unions cannot contain fields that may need dropping
11-
--> $DIR/feature-gate-untagged_unions.rs:21:5
11+
--> $DIR/feature-gate-untagged_unions.rs:25:5
1212
|
1313
LL | a: String,
1414
| ^^^^^^^^^
@@ -20,7 +20,7 @@ LL | a: std::mem::ManuallyDrop<String>,
2020
| +++++++++++++++++++++++ +
2121

2222
error[E0740]: unions cannot contain fields that may need dropping
23-
--> $DIR/feature-gate-untagged_unions.rs:29:5
23+
--> $DIR/feature-gate-untagged_unions.rs:33:5
2424
|
2525
LL | a: T,
2626
| ^^^^
@@ -32,7 +32,7 @@ LL | a: std::mem::ManuallyDrop<T>,
3232
| +++++++++++++++++++++++ +
3333

3434
error[E0740]: unions cannot contain fields that may need dropping
35-
--> $DIR/feature-gate-untagged_unions.rs:41:5
35+
--> $DIR/feature-gate-untagged_unions.rs:45:5
3636
|
3737
LL | nest: U5,
3838
| ^^^^^^^^

0 commit comments

Comments
 (0)