@@ -1393,31 +1393,32 @@ fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
1393
1393
1394
1394
/// When the `#![feature(untagged_unions)]` gate is active,
1395
1395
/// check that the fields of the `union` does not contain fields that need dropping.
1396
- fn check_union_fields ( tcx : TyCtxt < ' _ > , _ : Span , item_def_id : DefId ) -> bool {
1396
+ fn check_union_fields ( tcx : TyCtxt < ' _ > , span : Span , item_def_id : DefId ) -> bool {
1397
1397
// Without the feature we check that all fields are `Copy` in our stability checking
1398
1398
// infrastructure.
1399
1399
if !tcx. features ( ) . untagged_unions {
1400
1400
return true ;
1401
1401
}
1402
1402
let item_type = tcx. type_of ( item_def_id) ;
1403
1403
if let ty:: Adt ( def, substs) = item_type. kind {
1404
- if def. is_union ( ) {
1405
- let fields = & def. non_enum_variant ( ) . fields ;
1406
- for field in fields {
1407
- let field_ty = field. ty ( tcx, substs) ;
1408
- // We are currently checking the type this field came from, so it must be local.
1409
- let field_span = tcx. hir ( ) . span_if_local ( field. did ) . unwrap ( ) ;
1410
- let param_env = tcx. param_env ( field. did ) ;
1411
- if field_ty. needs_drop ( tcx, param_env) {
1412
- struct_span_err ! ( tcx. sess, field_span, E0740 ,
1413
- "unions may not contain fields that need dropping" )
1414
- . span_note ( field_span,
1415
- "`std::mem::ManuallyDrop` can be used to wrap the type" )
1416
- . emit ( ) ;
1417
- return false ;
1418
- }
1404
+ assert ! ( def. is_union( ) ) ;
1405
+ let fields = & def. non_enum_variant ( ) . fields ;
1406
+ for field in fields {
1407
+ let field_ty = field. ty ( tcx, substs) ;
1408
+ // We are currently checking the type this field came from, so it must be local.
1409
+ let field_span = tcx. hir ( ) . span_if_local ( field. did ) . unwrap ( ) ;
1410
+ let param_env = tcx. param_env ( field. did ) ;
1411
+ if field_ty. needs_drop ( tcx, param_env) {
1412
+ struct_span_err ! ( tcx. sess, field_span, E0740 ,
1413
+ "unions may not contain fields that need dropping" )
1414
+ . span_note ( field_span,
1415
+ "`std::mem::ManuallyDrop` can be used to wrap the type" )
1416
+ . emit ( ) ;
1417
+ return false ;
1419
1418
}
1420
1419
}
1420
+ } else {
1421
+ span_bug ! ( span, "unions must be ty::Adt, but got {:?}" , item_type. kind) ;
1421
1422
}
1422
1423
return true ;
1423
1424
}
0 commit comments