@@ -74,14 +74,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
74
74
) ,
75
75
) ;
76
76
}
77
- infer:: RelateParamBound ( span, t) => {
77
+ infer:: RelateParamBound ( span, t, opt_span ) => {
78
78
label_or_note (
79
79
span,
80
80
& 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 { "" } ,
83
84
) ,
84
85
) ;
86
+ if let Some ( span) = opt_span {
87
+ err. span_note ( span, "...that is required by this bound" ) ;
88
+ }
85
89
}
86
90
infer:: RelateRegionParamBound ( span) => {
87
91
label_or_note (
@@ -117,6 +121,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
117
121
"" ,
118
122
sup,
119
123
" doesn't meet the lifetime requirements" ,
124
+ None ,
120
125
) ;
121
126
}
122
127
( _, ty:: RePlaceholder ( _) ) => {
@@ -126,16 +131,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
126
131
"the required lifetime does not necessarily outlive " ,
127
132
sub,
128
133
"" ,
134
+ None ,
129
135
) ;
130
136
}
131
137
_ => {
132
- note_and_explain_region ( self . tcx , & mut err, "" , sup, "..." ) ;
138
+ note_and_explain_region ( self . tcx , & mut err, "" , sup, "..." , None ) ;
133
139
note_and_explain_region (
134
140
self . tcx ,
135
141
& mut err,
136
142
"...does not necessarily outlive " ,
137
143
sub,
138
144
"" ,
145
+ None ,
139
146
) ;
140
147
}
141
148
}
@@ -154,13 +161,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
154
161
"...the reference is valid for " ,
155
162
sub,
156
163
"..." ,
164
+ None ,
157
165
) ;
158
166
note_and_explain_region (
159
167
self . tcx ,
160
168
& mut err,
161
169
"...but the borrowed content is only valid for " ,
162
170
sup,
163
171
"" ,
172
+ None ,
164
173
) ;
165
174
err
166
175
}
@@ -179,13 +188,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
179
188
"...the borrowed pointer is valid for " ,
180
189
sub,
181
190
"..." ,
191
+ None ,
182
192
) ;
183
193
note_and_explain_region (
184
194
self . tcx ,
185
195
& mut err,
186
196
& format ! ( "...but `{}` is only valid for " , var_name) ,
187
197
sup,
188
198
"" ,
199
+ None ,
189
200
) ;
190
201
err
191
202
}
@@ -197,17 +208,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
197
208
"lifetime of the source pointer does not outlive lifetime bound of the \
198
209
object type"
199
210
) ;
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
+ ) ;
201
219
note_and_explain_region (
202
220
self . tcx ,
203
221
& mut err,
204
222
"source pointer is only valid for " ,
205
223
sup,
206
224
"" ,
225
+ None ,
207
226
) ;
208
227
err
209
228
}
210
- infer:: RelateParamBound ( span, ty) => {
229
+ infer:: RelateParamBound ( span, ty, opt_span ) => {
211
230
let mut err = struct_span_err ! (
212
231
self . tcx. sess,
213
232
span,
@@ -216,10 +235,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
216
235
self . ty_to_string( ty)
217
236
) ;
218
237
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
+ ) ,
223
254
}
224
255
err
225
256
}
@@ -232,13 +263,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
232
263
"lifetime parameter instantiated with " ,
233
264
sup,
234
265
"" ,
266
+ None ,
235
267
) ;
236
268
note_and_explain_region (
237
269
self . tcx ,
238
270
& mut err,
239
271
"but lifetime parameter must outlive " ,
240
272
sub,
241
273
"" ,
274
+ None ,
242
275
) ;
243
276
err
244
277
}
@@ -255,6 +288,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
255
288
"the return value is only valid for " ,
256
289
sup,
257
290
"" ,
291
+ None ,
258
292
) ;
259
293
err
260
294
}
@@ -266,8 +300,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
266
300
"a value of type `{}` is borrowed for too long" ,
267
301
self . ty_to_string( ty)
268
302
) ;
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
+ ) ;
271
319
err
272
320
}
273
321
infer:: ReferenceOutlivesReferent ( ty, span) => {
@@ -278,13 +326,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
278
326
"in type `{}`, reference has a longer lifetime than the data it references" ,
279
327
self . ty_to_string( ty)
280
328
) ;
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
+ ) ;
282
337
note_and_explain_region (
283
338
self . tcx ,
284
339
& mut err,
285
340
"but the referenced data is only valid for " ,
286
341
sup,
287
342
"" ,
343
+ None ,
288
344
) ;
289
345
err
290
346
}
0 commit comments