Skip to content

Commit 612760b

Browse files
author
Ariel Ben-Yehuda
committed
fix dropck overflow error message
Perf numbers: Before this patchset: 572.70user 5.52system 7:33.21elapsed 127%CPU (0avgtext+0avgdata 1173368maxresident)k llvm-time: 385.858 After this patch: 557.84user 5.73system 7:22.10elapsed 127%CPU (0avgtext+0avgdata 1142848maxresident)k llvm-time: 385.834 nice 2.5% perf improvement
1 parent c533f96 commit 612760b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/librustc_typeck/check/dropck.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use util::nodemap::FnvHashSet;
1818

1919
use syntax::ast;
2020
use 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

Comments
 (0)