Report even duplilcate errors in case the feature gat is not active

This commit is contained in:
Oliver Scherer 2019-10-21 10:12:09 +02:00
parent 0653694fdc
commit 875bdd5dbe
3 changed files with 29 additions and 9 deletions

View File

@ -1394,11 +1394,6 @@ fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
/// When the `#![feature(untagged_unions)]` gate is active,
/// check that the fields of the `union` does not contain fields that need dropping.
fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: DefId) -> bool {
// Without the feature we check that all fields are `Copy` in our stability checking
// infrastructure.
if !tcx.features().untagged_unions {
return true;
}
let item_type = tcx.type_of(item_def_id);
if let ty::Adt(def, substs) = item_type.kind {
assert!(def.is_union());

View File

@ -7,11 +7,11 @@ union U2<T: Copy> { // OK
}
union U3 { //~ ERROR unions with non-`Copy` fields are unstable
a: String,
a: String, //~ ERROR unions may not contain fields that need dropping
}
union U4<T> { //~ ERROR unions with non-`Copy` fields are unstable
a: T,
a: T, //~ ERROR unions may not contain fields that need dropping
}
union U5 { //~ ERROR unions with `Drop` implementations are unstable

View File

@ -31,6 +31,31 @@ LL | | }
= note: for more information, see https://github.com/rust-lang/rust/issues/32836
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable
error: aborting due to 3 previous errors
error[E0740]: unions may not contain fields that need dropping
--> $DIR/feature-gate-untagged_unions.rs:10:5
|
LL | a: String,
| ^^^^^^^^^
|
note: `std::mem::ManuallyDrop` can be used to wrap the type
--> $DIR/feature-gate-untagged_unions.rs:10:5
|
LL | a: String,
| ^^^^^^^^^
For more information about this error, try `rustc --explain E0658`.
error[E0740]: unions may not contain fields that need dropping
--> $DIR/feature-gate-untagged_unions.rs:14:5
|
LL | a: T,
| ^^^^
|
note: `std::mem::ManuallyDrop` can be used to wrap the type
--> $DIR/feature-gate-untagged_unions.rs:14:5
|
LL | a: T,
| ^^^^
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0658, E0740.
For more information about an error, try `rustc --explain E0658`.