Skip to content

Commit

Permalink
add array tests, cleanup, tidy, and bless
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 13, 2022
1 parent e4593ef commit 07fe988
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/consts/invalid-union.32bit.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/test/ui/union/field_checks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore-tidy-linelength
use std::mem::ManuallyDrop;

union U1 { // OK
Expand Down Expand Up @@ -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,
Expand All @@ -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() {}
22 changes: 17 additions & 5 deletions src/test/ui/union/field_checks.stderr
Original file line number Diff line number Diff line change
@@ -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,
| ^^^^^^^^^
Expand All @@ -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>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -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,
| ^^^^
Expand All @@ -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,
| ^^^^^^^^
Expand All @@ -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 change: 0 additions & 1 deletion src/test/ui/union/union-nonrepresentable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

union U { //~ ERROR recursive type `U` has infinite size
a: u8,
b: std::mem::ManuallyDrop<U>,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/union/union-nonrepresentable.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/derive.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(untagged_unions)]
#![allow(dead_code)]
#![warn(clippy::expl_impl_clone_on_copy)]


#[derive(Copy)]
struct Qux;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(path_statements)]
#![allow(clippy::deref_addrof)]
#![allow(clippy::redundant_field_names)]
#![feature(untagged_unions)]


struct Unit;
struct Tuple(i32);
Expand Down

0 comments on commit 07fe988

Please sign in to comment.