@@ -371,14 +371,12 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
371
371
let param_env = tcx. param_env ( item_def_id) ;
372
372
for field in fields {
373
373
let field_ty = field. ty ( tcx, substs) ;
374
- let ( field_span, ty_span) =
375
- // We are currently checking the type this field came from, so it must be local.
376
- if let Node :: Field ( field) = tcx. hir ( ) . get_if_local ( field. did ) . unwrap ( ) {
377
- ( field. span , field. ty . span )
378
- } else {
379
- unreachable ! ( "mir field has to correspond to hir field" ) ;
380
- } ;
381
374
if field_ty. needs_drop ( tcx, param_env) {
375
+ let ( field_span, ty_span) = match tcx. hir ( ) . get_if_local ( field. did ) {
376
+ // We are currently checking the type this field came from, so it must be local.
377
+ Some ( Node :: Field ( field) ) => ( field. span , field. ty . span ) ,
378
+ _ => unreachable ! ( "mir field has to correspond to hir field" ) ,
379
+ } ;
382
380
struct_span_err ! (
383
381
tcx. sess,
384
382
field_span,
@@ -387,7 +385,10 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
387
385
)
388
386
. multipart_suggestion_verbose (
389
387
"wrap the type with `std::mem::ManuallyDrop` and ensure it is manually dropped" ,
390
- vec ! [ ( ty_span, format!( "std::mem::ManuallyDrop<{}>" , field_ty) ) ] ,
388
+ vec ! [
389
+ ( ty_span. shrink_to_lo( ) , format!( "std::mem::ManuallyDrop<" ) ) ,
390
+ ( ty_span. shrink_to_hi( ) , ">" . into( ) ) ,
391
+ ] ,
391
392
Applicability :: MaybeIncorrect ,
392
393
)
393
394
. emit ( ) ;
0 commit comments