@@ -858,8 +858,7 @@ fn compare_synthetic_generics<'tcx>(
858
858
{
859
859
if impl_synthetic != trait_synthetic {
860
860
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) ;
863
862
let trait_span = tcx. def_span ( trait_def_id) ;
864
863
let mut err = struct_span_err ! (
865
864
tcx. sess,
@@ -878,17 +877,16 @@ fn compare_synthetic_generics<'tcx>(
878
877
// try taking the name from the trait impl
879
878
// FIXME: this is obviously suboptimal since the name can already be used
880
879
// 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 ) ?;
882
881
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) ;
884
883
885
884
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) ;
887
886
888
887
// in case there are no generics, take the spot between the function name
889
888
// 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 ( ) ;
892
890
// in case there are generics, just replace them
893
891
let generics_span =
894
892
impl_m. generics . span . substitute_dummy ( new_generics_span) ;
@@ -900,7 +898,7 @@ fn compare_synthetic_generics<'tcx>(
900
898
"try changing the `impl Trait` argument to a generic parameter" ,
901
899
vec ! [
902
900
// replace `impl Trait` with `T`
903
- ( impl_span, new_name) ,
901
+ ( impl_span, new_name. to_string ( ) ) ,
904
902
// replace impl method generics with trait method generics
905
903
// This isn't quite right, as users might have changed the names
906
904
// of the generics, but it works for the common case
@@ -917,7 +915,7 @@ fn compare_synthetic_generics<'tcx>(
917
915
err. span_label ( impl_span, "expected `impl Trait`, found generic parameter" ) ;
918
916
( || {
919
917
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) ;
921
919
let input_tys = match impl_m. kind {
922
920
hir:: ImplItemKind :: Fn ( ref sig, _) => sig. decl . inputs ,
923
921
_ => unreachable ! ( ) ,
0 commit comments