@@ -751,27 +751,56 @@ fn check_region_bounds_on_impl_item<'tcx>(
751
751
. get_generics ( impl_m. def_id . expect_local ( ) )
752
752
. expect ( "expected impl item to have generics or else we can't compare them" )
753
753
. span ;
754
- let generics_span = if let Some ( local_def_id) = trait_m. def_id . as_local ( ) {
755
- Some (
756
- tcx. hir ( )
757
- . get_generics ( local_def_id)
758
- . expect ( "expected trait item to have generics or else we can't compare them" )
759
- . span ,
760
- )
761
- } else {
762
- None
763
- } ;
764
754
755
+ let mut generics_span = None ;
756
+ let mut bounds_span = vec ! [ ] ;
757
+ let mut where_span = None ;
758
+ if let Some ( trait_node) = tcx. hir ( ) . get_if_local ( trait_m. def_id )
759
+ && let Some ( trait_generics) = trait_node. generics ( )
760
+ {
761
+ generics_span = Some ( trait_generics. span ) ;
762
+ // FIXME: we could potentially look at the impl's bounds to not point at bounds that
763
+ // *are* present in the impl.
764
+ for p in trait_generics. predicates {
765
+ if let hir:: WherePredicate :: BoundPredicate ( pred) = p {
766
+ for b in pred. bounds {
767
+ if let hir:: GenericBound :: Outlives ( lt) = b {
768
+ bounds_span. push ( lt. ident . span ) ;
769
+ }
770
+ }
771
+ }
772
+ }
773
+ if let Some ( impl_node) = tcx. hir ( ) . get_if_local ( impl_m. def_id )
774
+ && let Some ( impl_generics) = impl_node. generics ( )
775
+ {
776
+ let mut impl_bounds = 0 ;
777
+ for p in impl_generics. predicates {
778
+ if let hir:: WherePredicate :: BoundPredicate ( pred) = p {
779
+ for b in pred. bounds {
780
+ if let hir:: GenericBound :: Outlives ( _) = b {
781
+ impl_bounds += 1 ;
782
+ }
783
+ }
784
+ }
785
+ }
786
+ if impl_bounds == bounds_span. len ( ) {
787
+ bounds_span = vec ! [ ] ;
788
+ } else if impl_generics. has_where_clause_predicates {
789
+ where_span = Some ( impl_generics. where_clause_span ) ;
790
+ }
791
+ }
792
+ }
765
793
let reported = tcx
766
794
. sess
767
795
. create_err ( LifetimesOrBoundsMismatchOnTrait {
768
796
span,
769
797
item_kind : assoc_item_kind_str ( impl_m) ,
770
798
ident : impl_m. ident ( tcx) ,
771
799
generics_span,
800
+ bounds_span,
801
+ where_span,
772
802
} )
773
803
. emit_unless ( delay) ;
774
-
775
804
return Err ( reported) ;
776
805
}
777
806
0 commit comments