@@ -175,25 +175,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
175175 ty:: ReEarlyBound ( _) |
176176 ty:: ReFree ( _) => {
177177 let scope = region. free_region_binding_scope ( self ) ;
178- let prefix = match * region {
179- ty:: ReEarlyBound ( ref br) => {
180- format ! ( "the lifetime {} as defined on" , br. name)
181- }
182- ty:: ReFree ( ref fr) => {
183- match fr. bound_region {
184- ty:: BrAnon ( idx) => {
185- format ! ( "the anonymous lifetime #{} defined on" , idx + 1 )
186- }
187- ty:: BrFresh ( _) => "an anonymous lifetime defined on" . to_owned ( ) ,
188- _ => {
189- format ! ( "the lifetime {} as defined on" ,
190- fr. bound_region)
191- }
192- }
193- }
194- _ => bug ! ( )
195- } ;
196-
197178 let node = self . hir . as_local_node_id ( scope)
198179 . unwrap_or ( DUMMY_NODE_ID ) ;
199180 let unknown;
@@ -218,7 +199,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
218199 & unknown
219200 }
220201 } ;
221- let ( msg, opt_span) = explain_span ( self , tag, self . hir . span ( node) ) ;
202+ let ( prefix, span) = match * region {
203+ ty:: ReEarlyBound ( ref br) => {
204+ ( format ! ( "the lifetime {} as defined on" , br. name) ,
205+ self . sess . codemap ( ) . def_span ( self . hir . span ( node) ) )
206+ }
207+ ty:: ReFree ( ref fr) => {
208+ match fr. bound_region {
209+ ty:: BrAnon ( idx) => {
210+ ( format ! ( "the anonymous lifetime #{} defined on" , idx + 1 ) ,
211+ self . hir . span ( node) )
212+ }
213+ ty:: BrFresh ( _) => ( "an anonymous lifetime defined on" . to_owned ( ) ,
214+ self . hir . span ( node) ) ,
215+ _ => ( format ! ( "the lifetime {} as defined on" , fr. bound_region) ,
216+ self . sess . codemap ( ) . def_span ( self . hir . span ( node) ) ) ,
217+ }
218+ }
219+ _ => bug ! ( )
220+ } ;
221+ let ( msg, opt_span) = explain_span ( self , tag, span) ;
222222 ( format ! ( "{} {}" , prefix, msg) , opt_span)
223223 }
224224
@@ -807,7 +807,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
807807 }
808808 } ;
809809
810- let span = cause. span ;
810+ let span = cause. span ( & self . tcx ) ;
811811
812812 diag. span_label ( span, terr. to_string ( ) ) ;
813813 if let Some ( ( sp, msg) ) = secondary_span {
@@ -842,7 +842,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
842842 "did you mean `{}(/* fields */)`?" ,
843843 self . tcx. item_path_str( def_id)
844844 ) ;
845- diag. span_label ( cause . span , message) ;
845+ diag. span_label ( span, message) ;
846846 }
847847 }
848848 }
@@ -870,7 +870,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
870870 trace,
871871 terr) ;
872872
873- let span = trace. cause . span ;
873+ let span = trace. cause . span ( & self . tcx ) ;
874874 let failure_code = trace. cause . as_failure_code ( terr) ;
875875 let mut diag = match failure_code {
876876 FailureCode :: Error0317 ( failure_str) => {
@@ -1076,6 +1076,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10761076 sup_region,
10771077 "..." ) ;
10781078
1079+ match ( & sup_origin, & sub_origin) {
1080+ ( & infer:: Subtype ( ref sup_trace) , & infer:: Subtype ( ref sub_trace) ) => {
1081+ if let ( Some ( ( sup_expected, sup_found) ) ,
1082+ Some ( ( sub_expected, sub_found) ) ) = ( self . values_str ( & sup_trace. values ) ,
1083+ self . values_str ( & sub_trace. values ) ) {
1084+ if sub_expected == sup_expected && sub_found == sup_found {
1085+ self . tcx . note_and_explain_region (
1086+ region_scope_tree,
1087+ & mut err,
1088+ "...but the lifetime must also be valid for " ,
1089+ sub_region,
1090+ "..." ,
1091+ ) ;
1092+ err. note ( & format ! ( "...so that the {}:\n expected {}\n found {}" ,
1093+ sup_trace. cause. as_requirement_str( ) ,
1094+ sup_expected. content( ) ,
1095+ sup_found. content( ) ) ) ;
1096+ err. emit ( ) ;
1097+ return ;
1098+ }
1099+ }
1100+ }
1101+ _ => { }
1102+ }
1103+
10791104 self . note_region_origin ( & mut err, & sup_origin) ;
10801105
10811106 self . tcx . note_and_explain_region ( region_scope_tree, & mut err,
0 commit comments