diff options
| author | bors <bors@rust-lang.org> | 2022-07-13 23:42:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-13 23:42:05 +0000 |
| commit | cbb07c27a4d78f95557a6b9cdcc32f98d67a0c22 (patch) | |
| tree | c6ca234d183a8002b09848b116cd547ff2d01b14 /compiler/rustc_mir_transform/src | |
| parent | 87588a2afd9ca903366f0deaf84d805f34469384 (diff) | |
| parent | 07fe9882cc6e03682fcfa7b18c8f5b998219bdd2 (diff) | |
| download | rust-cbb07c27a4d78f95557a6b9cdcc32f98d67a0c22.tar.gz rust-cbb07c27a4d78f95557a6b9cdcc32f98d67a0c22.zip | |
Auto merge of #97995 - RalfJung:union-more-nodrop, r=Mark-Simulacrum
allow unions with mutable references and tuples of allowed types We currently allow shared references in unions, but not mutable references. That seems somewhat inconsistent. So let's allow all references, and while we are at it, let's make sure the set of allowed types is closed under tuples. This will need T-lang FCP (at least). Then remove the `tagged_unions` feature, since we do not plan to stabilize any more of it. Closes https://github.com/rust-lang/rust/issues/55149
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_unsafety.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 1f73b7da815..ded1f0462cb 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -219,22 +219,15 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { // We have to check the actual type of the assignment, as that determines if the // old value is being dropped. let assigned_ty = place.ty(&self.body.local_decls, self.tcx).ty; - // To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping. - let manually_drop = assigned_ty - .ty_adt_def() - .map_or(false, |adt_def| adt_def.is_manually_drop()); - let nodrop = manually_drop - || assigned_ty.is_copy_modulo_regions( - self.tcx.at(self.source_info.span), - self.param_env, + if assigned_ty.needs_drop( + self.tcx, + self.tcx.param_env(base_ty.ty_adt_def().unwrap().did()), + ) { + // This would be unsafe, but should be outright impossible since we reject such unions. + self.tcx.sess.delay_span_bug( + self.source_info.span, + "union fields that need dropping should be impossible", ); - if !nodrop { - self.require_unsafe( - UnsafetyViolationKind::General, - UnsafetyViolationDetails::AssignToDroppingUnionField, - ); - } else { - // write to non-drop union field, safe } } else { self.require_unsafe( |
