add array tests, cleanup, tidy, and bless
This commit is contained in:
parent
e4593ef0f2
commit
07fe9882cc
10 changed files with 35 additions and 15 deletions
|
@ -182,7 +182,7 @@ declare_features! (
|
|||
(removed, unsafe_no_drop_flag, "1.0.0", None, None, None),
|
||||
/// Allows `union` fields that don't implement `Copy` as long as they don't have any drop glue.
|
||||
(removed, untagged_unions, "1.13.0", Some(55149), None,
|
||||
Some("unions with `Copy` and `MaybeUninit` fields are stable; there is no intent to stabilize more")),
|
||||
Some("unions with `Copy` and `ManuallyDrop` fields are stable; there is no intent to stabilize more")),
|
||||
/// Allows `#[unwind(..)]`.
|
||||
///
|
||||
/// Permits specifying whether a function should permit unwinding or abort on unwind.
|
||||
|
|
|
@ -422,7 +422,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
|
|||
}
|
||||
_ => {
|
||||
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
|
||||
ty.ty_adt_def().map_or(false, |adt_def| adt_def.is_manually_drop())
|
||||
ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop())
|
||||
|| ty.is_copy_modulo_regions(tcx.at(span), param_env)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ This API is completely unstable and subject to change.
|
|||
#![feature(once_cell)]
|
||||
#![feature(slice_partition_dedup)]
|
||||
#![feature(try_blocks)]
|
||||
#![feature(is_some_with)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/invalid-union.rs:40:1
|
||||
--> $DIR/invalid-union.rs:41:1
|
||||
|
|
||||
LL | fn main() {
|
||||
| ^^^^^^^^^ constructing invalid value at .<deref>.y.<enum-variant(B)>.0: encountered `UnsafeCell` in a `const`
|
||||
|
@ -10,7 +10,7 @@ LL | fn main() {
|
|||
}
|
||||
|
||||
error: erroneous constant used
|
||||
--> $DIR/invalid-union.rs:41:25
|
||||
--> $DIR/invalid-union.rs:42:25
|
||||
|
|
||||
LL | let _: &'static _ = &C;
|
||||
| ^^ referenced constant has errors
|
||||
|
@ -24,7 +24,7 @@ error: aborting due to 2 previous errors
|
|||
For more information about this error, try `rustc --explain E0080`.
|
||||
Future incompatibility report: Future breakage diagnostic:
|
||||
error: erroneous constant used
|
||||
--> $DIR/invalid-union.rs:41:25
|
||||
--> $DIR/invalid-union.rs:42:25
|
||||
|
|
||||
LL | let _: &'static _ = &C;
|
||||
| ^^ referenced constant has errors
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
// ignore-tidy-linelength
|
||||
use std::mem::ManuallyDrop;
|
||||
|
||||
union U1 { // OK
|
||||
|
@ -45,6 +44,10 @@ union U5Nested { // a nested union that drops is NOT OK
|
|||
nest: U5, //~ ERROR unions cannot contain fields that may need dropping
|
||||
}
|
||||
|
||||
union U5Nested2 { // for now we don't special-case empty arrays
|
||||
nest: [U5; 0], //~ ERROR unions cannot contain fields that may need dropping
|
||||
}
|
||||
|
||||
union U6 { // OK
|
||||
s: &'static i32,
|
||||
m: &'static mut i32,
|
||||
|
@ -54,4 +57,9 @@ union U7<T> { // OK
|
|||
f: (&'static mut i32, ManuallyDrop<T>, i32),
|
||||
}
|
||||
|
||||
union U8<T> { // OK
|
||||
f1: [(&'static mut i32, i32); 8],
|
||||
f2: [ManuallyDrop<T>; 2],
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0740]: unions cannot contain fields that may need dropping
|
||||
--> $DIR/field_checks.rs:25:5
|
||||
--> $DIR/field_checks.rs:24:5
|
||||
|
|
||||
LL | a: String,
|
||||
| ^^^^^^^^^
|
||||
|
@ -11,7 +11,7 @@ LL | a: std::mem::ManuallyDrop<String>,
|
|||
| +++++++++++++++++++++++ +
|
||||
|
||||
error[E0740]: unions cannot contain fields that may need dropping
|
||||
--> $DIR/field_checks.rs:29:5
|
||||
--> $DIR/field_checks.rs:28:5
|
||||
|
|
||||
LL | a: std::cell::RefCell<i32>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -23,7 +23,7 @@ LL | a: std::mem::ManuallyDrop<std::cell::RefCell<i32>>,
|
|||
| +++++++++++++++++++++++ +
|
||||
|
||||
error[E0740]: unions cannot contain fields that may need dropping
|
||||
--> $DIR/field_checks.rs:33:5
|
||||
--> $DIR/field_checks.rs:32:5
|
||||
|
|
||||
LL | a: T,
|
||||
| ^^^^
|
||||
|
@ -35,7 +35,7 @@ LL | a: std::mem::ManuallyDrop<T>,
|
|||
| +++++++++++++++++++++++ +
|
||||
|
||||
error[E0740]: unions cannot contain fields that may need dropping
|
||||
--> $DIR/field_checks.rs:45:5
|
||||
--> $DIR/field_checks.rs:44:5
|
||||
|
|
||||
LL | nest: U5,
|
||||
| ^^^^^^^^
|
||||
|
@ -46,6 +46,18 @@ help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>
|
|||
LL | nest: std::mem::ManuallyDrop<U5>,
|
||||
| +++++++++++++++++++++++ +
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error[E0740]: unions cannot contain fields that may need dropping
|
||||
--> $DIR/field_checks.rs:48:5
|
||||
|
|
||||
LL | nest: [U5; 0],
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: a type is guaranteed not to need dropping when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type
|
||||
help: when the type does not implement `Copy`, wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped
|
||||
|
|
||||
LL | nest: std::mem::ManuallyDrop<[U5; 0]>,
|
||||
| +++++++++++++++++++++++ +
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0740`.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
union U { //~ ERROR recursive type `U` has infinite size
|
||||
a: u8,
|
||||
b: std::mem::ManuallyDrop<U>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0072]: recursive type `U` has infinite size
|
||||
--> $DIR/union-nonrepresentable.rs:2:1
|
||||
--> $DIR/union-nonrepresentable.rs:1:1
|
||||
|
|
||||
LL | union U {
|
||||
| ^^^^^^^ recursive type has infinite size
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#![feature(untagged_unions)]
|
||||
#![allow(dead_code)]
|
||||
#![warn(clippy::expl_impl_clone_on_copy)]
|
||||
|
||||
|
||||
#[derive(Copy)]
|
||||
struct Qux;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#![allow(path_statements)]
|
||||
#![allow(clippy::deref_addrof)]
|
||||
#![allow(clippy::redundant_field_names)]
|
||||
#![feature(untagged_unions)]
|
||||
|
||||
|
||||
struct Unit;
|
||||
struct Tuple(i32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue