@@ -431,16 +431,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
431
431
let lhs = & self . thir [ lhs] ;
432
432
if let ty:: Adt ( adt_def, _) = lhs. ty . kind ( ) && adt_def. is_union ( ) {
433
433
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" ) ;
444
437
}
445
438
} else {
446
439
self . requires_unsafe ( expr. span , AccessToUnionField ) ;
@@ -537,7 +530,6 @@ enum UnsafeOpKind {
537
530
UseOfMutableStatic ,
538
531
UseOfExternStatic ,
539
532
DerefOfRawPointer ,
540
- AssignToDroppingUnionField ,
541
533
AccessToUnionField ,
542
534
MutationOfLayoutConstrainedField ,
543
535
BorrowOfLayoutConstrainedField ,
@@ -555,7 +547,6 @@ impl UnsafeOpKind {
555
547
UseOfMutableStatic => "use of mutable static" ,
556
548
UseOfExternStatic => "use of extern static" ,
557
549
DerefOfRawPointer => "dereference of raw pointer" ,
558
- AssignToDroppingUnionField => "assignment to union field that might need dropping" ,
559
550
AccessToUnionField => "access to union field" ,
560
551
MutationOfLayoutConstrainedField => "mutation of layout constrained field" ,
561
552
BorrowOfLayoutConstrainedField => {
@@ -600,11 +591,6 @@ impl UnsafeOpKind {
600
591
"raw pointers may be null, dangling or unaligned; they can violate aliasing rules \
601
592
and cause data races: all of these are undefined behavior",
602
593
) ,
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
- ) ,
608
594
AccessToUnionField => (
609
595
Cow :: Borrowed ( self . simple_description ( ) ) ,
610
596
"the field may not be properly initialized: using uninitialized data will cause \
0 commit comments