@@ -175,25 +175,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
175
175
ty:: ReEarlyBound ( _) |
176
176
ty:: ReFree ( _) => {
177
177
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
-
197
178
let node = self . hir . as_local_node_id ( scope)
198
179
. unwrap_or ( DUMMY_NODE_ID ) ;
199
180
let unknown;
@@ -218,7 +199,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
218
199
& unknown
219
200
}
220
201
} ;
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) ;
222
222
( format ! ( "{} {}" , prefix, msg) , opt_span)
223
223
}
224
224
@@ -807,7 +807,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
807
807
}
808
808
} ;
809
809
810
- let span = cause. span ;
810
+ let span = cause. span ( & self . tcx ) ;
811
811
812
812
diag. span_label ( span, terr. to_string ( ) ) ;
813
813
if let Some ( ( sp, msg) ) = secondary_span {
@@ -842,7 +842,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
842
842
"did you mean `{}(/* fields */)`?" ,
843
843
self . tcx. item_path_str( def_id)
844
844
) ;
845
- diag. span_label ( cause . span , message) ;
845
+ diag. span_label ( span, message) ;
846
846
}
847
847
}
848
848
}
@@ -870,7 +870,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
870
870
trace,
871
871
terr) ;
872
872
873
- let span = trace. cause . span ;
873
+ let span = trace. cause . span ( & self . tcx ) ;
874
874
let failure_code = trace. cause . as_failure_code ( terr) ;
875
875
let mut diag = match failure_code {
876
876
FailureCode :: Error0317 ( failure_str) => {
@@ -1076,6 +1076,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1076
1076
sup_region,
1077
1077
"..." ) ;
1078
1078
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
+
1079
1104
self . note_region_origin ( & mut err, & sup_origin) ;
1080
1105
1081
1106
self . tcx . note_and_explain_region ( region_scope_tree, & mut err,
0 commit comments