Skip to content

Commit 362e636

Browse files
committed
Do not call generate_fn_name_span in typeck.
1 parent 613dc22 commit 362e636

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,7 @@ fn compare_synthetic_generics<'tcx>(
858858
{
859859
if impl_synthetic != trait_synthetic {
860860
let impl_def_id = impl_def_id.expect_local();
861-
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_def_id);
862-
let impl_span = tcx.hir().span(impl_hir_id);
861+
let impl_span = tcx.def_span(impl_def_id);
863862
let trait_span = tcx.def_span(trait_def_id);
864863
let mut err = struct_span_err!(
865864
tcx.sess,
@@ -878,17 +877,16 @@ fn compare_synthetic_generics<'tcx>(
878877
// try taking the name from the trait impl
879878
// FIXME: this is obviously suboptimal since the name can already be used
880879
// as another generic argument
881-
let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?;
880+
let new_name = tcx.opt_item_name(trait_def_id)?;
882881
let trait_m = trait_m.def_id.as_local()?;
883-
let trait_m = tcx.hir().trait_item(hir::TraitItemId { def_id: trait_m });
882+
let trait_m = tcx.hir().expect_trait_item(trait_m);
884883

885884
let impl_m = impl_m.def_id.as_local()?;
886-
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
885+
let impl_m = tcx.hir().expect_impl_item(impl_m);
887886

888887
// in case there are no generics, take the spot between the function name
889888
// and the opening paren of the argument list
890-
let new_generics_span =
891-
tcx.sess.source_map().generate_fn_name_span(impl_span)?.shrink_to_hi();
889+
let new_generics_span = tcx.def_ident_span(impl_def_id)?.shrink_to_hi();
892890
// in case there are generics, just replace them
893891
let generics_span =
894892
impl_m.generics.span.substitute_dummy(new_generics_span);
@@ -900,7 +898,7 @@ fn compare_synthetic_generics<'tcx>(
900898
"try changing the `impl Trait` argument to a generic parameter",
901899
vec![
902900
// replace `impl Trait` with `T`
903-
(impl_span, new_name),
901+
(impl_span, new_name.to_string()),
904902
// replace impl method generics with trait method generics
905903
// This isn't quite right, as users might have changed the names
906904
// of the generics, but it works for the common case
@@ -917,7 +915,7 @@ fn compare_synthetic_generics<'tcx>(
917915
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
918916
(|| {
919917
let impl_m = impl_m.def_id.as_local()?;
920-
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
918+
let impl_m = tcx.hir().expect_impl_item(impl_m);
921919
let input_tys = match impl_m.kind {
922920
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
923921
_ => unreachable!(),

0 commit comments

Comments
 (0)