@@ -74,14 +74,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
7474 ) ,
7575 ) ;
7676 }
77- infer:: RelateParamBound ( span, t) => {
77+ infer:: RelateParamBound ( span, t, opt_span ) => {
7878 label_or_note (
7979 span,
8080 & format ! (
81- "...so that the type `{}` will meet its required lifetime bounds" ,
82- self . ty_to_string( t)
81+ "...so that the type `{}` will meet its required lifetime bounds{}" ,
82+ self . ty_to_string( t) ,
83+ if opt_span. is_some( ) { "..." } else { "" } ,
8384 ) ,
8485 ) ;
86+ if let Some ( span) = opt_span {
87+ err. span_note ( span, "...that is required by this bound" ) ;
88+ }
8589 }
8690 infer:: RelateRegionParamBound ( span) => {
8791 label_or_note (
@@ -117,6 +121,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
117121 "" ,
118122 sup,
119123 " doesn't meet the lifetime requirements" ,
124+ None ,
120125 ) ;
121126 }
122127 ( _, ty:: RePlaceholder ( _) ) => {
@@ -126,16 +131,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
126131 "the required lifetime does not necessarily outlive " ,
127132 sub,
128133 "" ,
134+ None ,
129135 ) ;
130136 }
131137 _ => {
132- note_and_explain_region ( self . tcx , & mut err, "" , sup, "..." ) ;
138+ note_and_explain_region ( self . tcx , & mut err, "" , sup, "..." , None ) ;
133139 note_and_explain_region (
134140 self . tcx ,
135141 & mut err,
136142 "...does not necessarily outlive " ,
137143 sub,
138144 "" ,
145+ None ,
139146 ) ;
140147 }
141148 }
@@ -154,13 +161,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
154161 "...the reference is valid for " ,
155162 sub,
156163 "..." ,
164+ None ,
157165 ) ;
158166 note_and_explain_region (
159167 self . tcx ,
160168 & mut err,
161169 "...but the borrowed content is only valid for " ,
162170 sup,
163171 "" ,
172+ None ,
164173 ) ;
165174 err
166175 }
@@ -179,13 +188,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
179188 "...the borrowed pointer is valid for " ,
180189 sub,
181190 "..." ,
191+ None ,
182192 ) ;
183193 note_and_explain_region (
184194 self . tcx ,
185195 & mut err,
186196 & format ! ( "...but `{}` is only valid for " , var_name) ,
187197 sup,
188198 "" ,
199+ None ,
189200 ) ;
190201 err
191202 }
@@ -197,17 +208,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
197208 "lifetime of the source pointer does not outlive lifetime bound of the \
198209 object type"
199210 ) ;
200- note_and_explain_region ( self . tcx , & mut err, "object type is valid for " , sub, "" ) ;
211+ note_and_explain_region (
212+ self . tcx ,
213+ & mut err,
214+ "object type is valid for " ,
215+ sub,
216+ "" ,
217+ None ,
218+ ) ;
201219 note_and_explain_region (
202220 self . tcx ,
203221 & mut err,
204222 "source pointer is only valid for " ,
205223 sup,
206224 "" ,
225+ None ,
207226 ) ;
208227 err
209228 }
210- infer:: RelateParamBound ( span, ty) => {
229+ infer:: RelateParamBound ( span, ty, opt_span ) => {
211230 let mut err = struct_span_err ! (
212231 self . tcx. sess,
213232 span,
@@ -216,10 +235,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
216235 self . ty_to_string( ty)
217236 ) ;
218237 match * sub {
219- ty:: ReStatic => {
220- note_and_explain_region ( self . tcx , & mut err, "type must satisfy " , sub, "" )
221- }
222- _ => note_and_explain_region ( self . tcx , & mut err, "type must outlive " , sub, "" ) ,
238+ ty:: ReStatic => note_and_explain_region (
239+ self . tcx ,
240+ & mut err,
241+ "type must satisfy " ,
242+ sub,
243+ if opt_span. is_some ( ) { " as required by this binding" } else { "" } ,
244+ opt_span,
245+ ) ,
246+ _ => note_and_explain_region (
247+ self . tcx ,
248+ & mut err,
249+ "type must outlive " ,
250+ sub,
251+ if opt_span. is_some ( ) { " as required by this binding" } else { "" } ,
252+ opt_span,
253+ ) ,
223254 }
224255 err
225256 }
@@ -232,13 +263,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
232263 "lifetime parameter instantiated with " ,
233264 sup,
234265 "" ,
266+ None ,
235267 ) ;
236268 note_and_explain_region (
237269 self . tcx ,
238270 & mut err,
239271 "but lifetime parameter must outlive " ,
240272 sub,
241273 "" ,
274+ None ,
242275 ) ;
243276 err
244277 }
@@ -255,6 +288,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
255288 "the return value is only valid for " ,
256289 sup,
257290 "" ,
291+ None ,
258292 ) ;
259293 err
260294 }
@@ -266,8 +300,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
266300 "a value of type `{}` is borrowed for too long" ,
267301 self . ty_to_string( ty)
268302 ) ;
269- note_and_explain_region ( self . tcx , & mut err, "the type is valid for " , sub, "" ) ;
270- note_and_explain_region ( self . tcx , & mut err, "but the borrow lasts for " , sup, "" ) ;
303+ note_and_explain_region (
304+ self . tcx ,
305+ & mut err,
306+ "the type is valid for " ,
307+ sub,
308+ "" ,
309+ None ,
310+ ) ;
311+ note_and_explain_region (
312+ self . tcx ,
313+ & mut err,
314+ "but the borrow lasts for " ,
315+ sup,
316+ "" ,
317+ None ,
318+ ) ;
271319 err
272320 }
273321 infer:: ReferenceOutlivesReferent ( ty, span) => {
@@ -278,13 +326,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
278326 "in type `{}`, reference has a longer lifetime than the data it references" ,
279327 self . ty_to_string( ty)
280328 ) ;
281- note_and_explain_region ( self . tcx , & mut err, "the pointer is valid for " , sub, "" ) ;
329+ note_and_explain_region (
330+ self . tcx ,
331+ & mut err,
332+ "the pointer is valid for " ,
333+ sub,
334+ "" ,
335+ None ,
336+ ) ;
282337 note_and_explain_region (
283338 self . tcx ,
284339 & mut err,
285340 "but the referenced data is only valid for " ,
286341 sup,
287342 "" ,
343+ None ,
288344 ) ;
289345 err
290346 }
0 commit comments