@@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>(
171171 let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
172172
173173 // Check region bounds.
174- check_region_bounds_on_impl_item (
175- tcx,
176- impl_m_span,
177- impl_m,
178- trait_m,
179- & trait_m_generics,
180- & impl_m_generics,
181- ) ?;
174+ check_region_bounds_on_impl_item ( tcx, impl_m, trait_m, & trait_m_generics, & impl_m_generics) ?;
182175
183176 // Create obligations for each predicate declared by the impl
184177 // definition in the context of the trait's parameter
@@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>(
410403
411404fn check_region_bounds_on_impl_item < ' tcx > (
412405 tcx : TyCtxt < ' tcx > ,
413- span : Span ,
414406 impl_m : & ty:: AssocItem ,
415407 trait_m : & ty:: AssocItem ,
416408 trait_generics : & ty:: Generics ,
@@ -436,23 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>(
436428 // are zero. Since I don't quite know how to phrase things at
437429 // the moment, give a kind of vague error message.
438430 if trait_params != impl_params {
439- let item_kind = assoc_item_kind_str ( impl_m) ;
440- let span = impl_m
441- . def_id
442- . as_local ( )
443- . and_then ( |did| tcx. hir ( ) . get_generics ( did) )
444- . map_or ( span, |g| g. span ) ;
445- let generics_span = tcx. hir ( ) . span_if_local ( trait_m. def_id ) . map ( |sp| {
446- trait_m
447- . def_id
448- . as_local ( )
449- . and_then ( |did| tcx. hir ( ) . get_generics ( did) )
450- . map_or ( sp, |g| g. span )
451- } ) ;
431+ let span = tcx
432+ . hir ( )
433+ . get_generics ( impl_m. def_id . expect_local ( ) )
434+ . expect ( "expected impl item to have generics or else we can't compare them" )
435+ . span ;
436+ let generics_span = if let Some ( local_def_id) = trait_m. def_id . as_local ( ) {
437+ Some (
438+ tcx. hir ( )
439+ . get_generics ( local_def_id)
440+ . expect ( "expected trait item to have generics or else we can't compare them" )
441+ . span ,
442+ )
443+ } else {
444+ None
445+ } ;
452446
453447 let reported = tcx. sess . emit_err ( LifetimesOrBoundsMismatchOnTrait {
454448 span,
455- item_kind,
449+ item_kind : assoc_item_kind_str ( impl_m ) ,
456450 ident : impl_m. ident ( tcx) ,
457451 generics_span,
458452 } ) ;
@@ -1201,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>(
12011195
12021196 check_region_bounds_on_impl_item (
12031197 tcx,
1204- impl_ty_span,
12051198 impl_ty,
12061199 trait_ty,
12071200 & trait_ty_generics,
0 commit comments