@@ -431,16 +431,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
431431 let lhs = & self . thir [ lhs] ;
432432 if let ty:: Adt ( adt_def, _) = lhs. ty . kind ( ) && adt_def. is_union ( ) {
433433 if let Some ( ( assigned_ty, assignment_span) ) = self . assignment_info {
434- // To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping.
435- if !( assigned_ty
436- . ty_adt_def ( )
437- . map_or ( false , |adt| adt. is_manually_drop ( ) )
438- || assigned_ty
439- . is_copy_modulo_regions ( self . tcx . at ( expr. span ) , self . param_env ) )
440- {
441- self . requires_unsafe ( assignment_span, AssignToDroppingUnionField ) ;
442- } else {
443- // write to non-drop union field, safe
434+ if assigned_ty. needs_drop ( self . tcx , self . tcx . param_env ( adt_def. did ( ) ) ) {
435+ // This would be unsafe, but should be outright impossible since we reject such unions.
436+ self . tcx . sess . delay_span_bug ( assignment_span, "union fields that need dropping should be impossible" ) ;
444437 }
445438 } else {
446439 self . requires_unsafe ( expr. span , AccessToUnionField ) ;
@@ -537,7 +530,6 @@ enum UnsafeOpKind {
537530 UseOfMutableStatic ,
538531 UseOfExternStatic ,
539532 DerefOfRawPointer ,
540- AssignToDroppingUnionField ,
541533 AccessToUnionField ,
542534 MutationOfLayoutConstrainedField ,
543535 BorrowOfLayoutConstrainedField ,
@@ -555,7 +547,6 @@ impl UnsafeOpKind {
555547 UseOfMutableStatic => "use of mutable static" ,
556548 UseOfExternStatic => "use of extern static" ,
557549 DerefOfRawPointer => "dereference of raw pointer" ,
558- AssignToDroppingUnionField => "assignment to union field that might need dropping" ,
559550 AccessToUnionField => "access to union field" ,
560551 MutationOfLayoutConstrainedField => "mutation of layout constrained field" ,
561552 BorrowOfLayoutConstrainedField => {
@@ -600,11 +591,6 @@ impl UnsafeOpKind {
600591 "raw pointers may be null, dangling or unaligned; they can violate aliasing rules \
601592 and cause data races: all of these are undefined behavior",
602593 ) ,
603- AssignToDroppingUnionField => (
604- Cow :: Borrowed ( self . simple_description ( ) ) ,
605- "the previous content of the field will be dropped, which causes undefined \
606- behavior if the field was not properly initialized",
607- ) ,
608594 AccessToUnionField => (
609595 Cow :: Borrowed ( self . simple_description ( ) ) ,
610596 "the field may not be properly initialized: using uninitialized data will cause \
0 commit comments