@@ -1302,12 +1302,12 @@ fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1302
1302
def. destructor ( tcx) ; // force the destructor to be evaluated
1303
1303
check_representable ( tcx, span, def_id) ;
1304
1304
1305
- check_dropless ( tcx, span, def_id) ;
1305
+ check_union_fields ( tcx, span, def_id) ;
1306
1306
check_packed ( tcx, span, def_id) ;
1307
1307
}
1308
1308
1309
- fn check_dropless < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1310
- sp : Span ,
1309
+ fn check_union_fields < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1310
+ _sp : Span ,
1311
1311
item_def_id : DefId )
1312
1312
-> bool {
1313
1313
// Without the feature we check Copy types only later
@@ -1320,11 +1320,14 @@ fn check_dropless<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1320
1320
let fields = & def. non_enum_variant ( ) . fields ;
1321
1321
for field in fields {
1322
1322
let field_ty = field. ty ( tcx, substs) ;
1323
+ // We are currently checking the type this field came from, so it must be local
1324
+ let field_span = tcx. hir ( ) . span_if_local ( field. did ) . unwrap ( ) ;
1323
1325
let param_env = tcx. param_env ( field. did ) ;
1324
1326
if field_ty. needs_drop ( tcx, param_env) {
1325
- struct_span_err ! ( tcx. sess, sp , E0730 ,
1327
+ struct_span_err ! ( tcx. sess, field_span , E0730 ,
1326
1328
"unions may not contain fields that need dropping" )
1327
- . span_label ( sp, "ManuallyDrop can be used to wrap such fields" )
1329
+ . span_note ( field_span,
1330
+ "`std::mem::ManuallyDrop` can be used to wrap the type" )
1328
1331
. emit ( ) ;
1329
1332
return false ;
1330
1333
}
0 commit comments