@@ -18,6 +18,7 @@ use util::nodemap::FnvHashSet;
1818
1919use syntax:: ast;
2020use syntax:: codemap:: { self , Span } ;
21+ use syntax:: parse:: token:: special_idents;
2122
2223/// check_drop_impl confirms that the Drop implementation identfied by
2324/// `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>
286287 // was somehow on the root.
287288 }
288289 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)
301300 } 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) ;
310310 }
311311 }
312312 }
0 commit comments