@@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>(
171
171
let trait_m_predicates = tcx. predicates_of ( trait_m. def_id ) ;
172
172
173
173
// 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) ?;
182
175
183
176
// Create obligations for each predicate declared by the impl
184
177
// definition in the context of the trait's parameter
@@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>(
410
403
411
404
fn check_region_bounds_on_impl_item < ' tcx > (
412
405
tcx : TyCtxt < ' tcx > ,
413
- span : Span ,
414
406
impl_m : & ty:: AssocItem ,
415
407
trait_m : & ty:: AssocItem ,
416
408
trait_generics : & ty:: Generics ,
@@ -436,23 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>(
436
428
// are zero. Since I don't quite know how to phrase things at
437
429
// the moment, give a kind of vague error message.
438
430
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
+ } ;
452
446
453
447
let reported = tcx. sess . emit_err ( LifetimesOrBoundsMismatchOnTrait {
454
448
span,
455
- item_kind,
449
+ item_kind : assoc_item_kind_str ( impl_m ) ,
456
450
ident : impl_m. ident ( tcx) ,
457
451
generics_span,
458
452
} ) ;
@@ -1201,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>(
1201
1195
1202
1196
check_region_bounds_on_impl_item (
1203
1197
tcx,
1204
- impl_ty_span,
1205
1198
impl_ty,
1206
1199
trait_ty,
1207
1200
& trait_ty_generics,
0 commit comments