@@ -304,8 +304,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
304
304
self . report_concrete_failure ( region_scope_tree, origin, sub, sup) . emit ( ) ;
305
305
}
306
306
307
- RegionResolutionError :: GenericBoundFailure ( kind, param_ty, sub) => {
308
- self . report_generic_bound_failure ( region_scope_tree, kind, param_ty, sub) ;
307
+ RegionResolutionError :: GenericBoundFailure ( origin, param_ty, sub) => {
308
+ self . report_generic_bound_failure (
309
+ region_scope_tree,
310
+ origin. span ( ) ,
311
+ Some ( origin) ,
312
+ param_ty,
313
+ sub,
314
+ ) ;
309
315
}
310
316
311
317
RegionResolutionError :: SubSupConflict ( var_origin,
@@ -901,11 +907,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
901
907
DiagnosticStyledString :: highlighted ( format ! ( "{}" , exp_found. found) ) ) )
902
908
}
903
909
904
- fn report_generic_bound_failure ( & self ,
905
- region_scope_tree : & region:: ScopeTree ,
906
- origin : SubregionOrigin < ' tcx > ,
907
- bound_kind : GenericKind < ' tcx > ,
908
- sub : Region < ' tcx > )
910
+ pub fn report_generic_bound_failure ( & self ,
911
+ region_scope_tree : & region:: ScopeTree ,
912
+ span : Span ,
913
+ origin : Option < SubregionOrigin < ' tcx > > ,
914
+ bound_kind : GenericKind < ' tcx > ,
915
+ sub : Region < ' tcx > )
909
916
{
910
917
// Attempt to obtain the span of the parameter so we can
911
918
// suggest adding an explicit lifetime bound to it.
@@ -953,9 +960,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
953
960
format ! ( "the associated type `{}`" , p) ,
954
961
} ;
955
962
956
- if let SubregionOrigin :: CompareImplMethodObligation {
963
+ if let Some ( SubregionOrigin :: CompareImplMethodObligation {
957
964
span, item_name, impl_item_def_id, trait_item_def_id,
958
- } = origin {
965
+ } ) = origin {
959
966
self . report_extra_impl_obligation ( span,
960
967
item_name,
961
968
impl_item_def_id,
@@ -990,7 +997,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
990
997
ty:: ReFree ( ty:: FreeRegion { bound_region : ty:: BrNamed ( ..) , ..} ) => {
991
998
// Does the required lifetime have a nice name we can print?
992
999
let mut err = struct_span_err ! ( self . tcx. sess,
993
- origin . span( ) ,
1000
+ span,
994
1001
E0309 ,
995
1002
"{} may not live long enough" ,
996
1003
labeled_user_string) ;
@@ -1001,7 +1008,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1001
1008
ty:: ReStatic => {
1002
1009
// Does the required lifetime have a nice name we can print?
1003
1010
let mut err = struct_span_err ! ( self . tcx. sess,
1004
- origin . span( ) ,
1011
+ span,
1005
1012
E0310 ,
1006
1013
"{} may not live long enough" ,
1007
1014
labeled_user_string) ;
@@ -1012,7 +1019,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1012
1019
_ => {
1013
1020
// If not, be less specific.
1014
1021
let mut err = struct_span_err ! ( self . tcx. sess,
1015
- origin . span( ) ,
1022
+ span,
1016
1023
E0311 ,
1017
1024
"{} may not live long enough" ,
1018
1025
labeled_user_string) ;
@@ -1028,7 +1035,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1028
1035
}
1029
1036
} ;
1030
1037
1031
- self . note_region_origin ( & mut err, & origin) ;
1038
+ if let Some ( origin) = origin {
1039
+ self . note_region_origin ( & mut err, & origin) ;
1040
+ }
1032
1041
err. emit ( ) ;
1033
1042
}
1034
1043
0 commit comments