@@ -18,6 +18,7 @@ use util::nodemap::FnvHashSet;
18
18
19
19
use syntax:: ast;
20
20
use syntax:: codemap:: { self , Span } ;
21
+ use syntax:: parse:: token:: special_idents;
21
22
22
23
/// check_drop_impl confirms that the Drop implementation identfied by
23
24
/// `drop_impl_did` is not any more specialized than the type it is
@@ -286,27 +287,26 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>
286
287
// was somehow on the root.
287
288
}
288
289
TypeContext :: ADT { def_id, variant, field, field_index } => {
289
- // FIXME (pnkfelix): eventually lookup arg_name
290
- // for the given index on struct variants.
291
- // TODO: be saner
292
- if let ty:: ADTKind :: Enum = tcx. lookup_adt_def ( def_id) . adt_kind ( ) {
293
- span_note ! (
294
- rcx. tcx( ) . sess,
295
- span,
296
- "overflowed on enum {} variant {} argument {} type: {}" ,
297
- tcx. item_path_str( def_id) ,
298
- variant,
299
- field_index,
300
- detected_on_typ) ;
290
+ let adt = tcx. lookup_adt_def ( def_id) ;
291
+ let variant_name = match adt. adt_kind ( ) {
292
+ ty:: ADTKind :: Enum => format ! ( "enum {} variant {}" ,
293
+ tcx. item_path_str( def_id) ,
294
+ variant) ,
295
+ ty:: ADTKind :: Struct => format ! ( "struct {}" ,
296
+ tcx. item_path_str( def_id) )
297
+ } ;
298
+ let field_name = if field == special_idents:: unnamed_field. name {
299
+ format ! ( "#{}" , field_index)
301
300
} else {
302
- span_note ! (
303
- rcx. tcx( ) . sess,
304
- span,
305
- "overflowed on struct {} field {} type: {}" ,
306
- tcx. item_path_str( def_id) ,
307
- field,
308
- detected_on_typ) ;
309
- }
301
+ format ! ( "`{}`" , field)
302
+ } ;
303
+ span_note ! (
304
+ rcx. tcx( ) . sess,
305
+ span,
306
+ "overflowed on {} field {} type: {}" ,
307
+ variant_name,
308
+ field_name,
309
+ detected_on_typ) ;
310
310
}
311
311
}
312
312
}
0 commit comments