@@ -246,7 +246,9 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
246
246
let mut counter = 0 ;
247
247
let mut has_sub = None ;
248
248
let mut has_sup = None ;
249
- let mut has_vid = None ;
249
+
250
+ let mut actual_has_vid = None ;
251
+ let mut expected_has_vid = None ;
250
252
251
253
self . tcx ( ) . for_each_free_region ( & expected_trait_ref, |r| {
252
254
if Some ( r) == sub_placeholder && has_sub. is_none ( ) {
@@ -256,11 +258,16 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
256
258
has_sup = Some ( counter) ;
257
259
counter += 1 ;
258
260
}
261
+
262
+ if Some ( r) == vid && expected_has_vid. is_none ( ) {
263
+ expected_has_vid = Some ( counter) ;
264
+ counter += 1 ;
265
+ }
259
266
} ) ;
260
267
261
268
self . tcx ( ) . for_each_free_region ( & actual_trait_ref, |r| {
262
- if Some ( r) == vid && has_vid . is_none ( ) {
263
- has_vid = Some ( counter) ;
269
+ if Some ( r) == vid && actual_has_vid . is_none ( ) {
270
+ actual_has_vid = Some ( counter) ;
264
271
counter += 1 ;
265
272
}
266
273
} ) ;
@@ -274,60 +281,67 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
274
281
match ( has_sub, has_sup) {
275
282
( Some ( n1) , Some ( n2) ) => {
276
283
err. note ( & format ! (
277
- "`{}` must implement `{}` \
278
- for any two lifetimes `'{}` and `'{}`",
279
- expected_trait_ref. self_ty( ) ,
284
+ "`{}` would have to be implemented for the type `{}`, \
285
+ for any two lifetimes `'{}` and `'{}`",
280
286
expected_trait_ref,
287
+ expected_trait_ref. self_ty( ) ,
281
288
std:: cmp:: min( n1, n2) ,
282
289
std:: cmp:: max( n1, n2) ,
283
290
) ) ;
284
291
}
285
292
( Some ( n) , _) | ( _, Some ( n) ) => {
286
293
err. note ( & format ! (
287
- "`{}` must implement `{}` \
288
- for any lifetime `'{}`",
289
- expected_trait_ref. self_ty( ) ,
294
+ "`{}` would have to be implemented for the type `{}`, \
295
+ for any lifetime `'{}`",
290
296
expected_trait_ref,
297
+ expected_trait_ref. self_ty( ) ,
291
298
n,
292
299
) ) ;
293
300
}
294
301
( None , None ) => {
295
302
err. note ( & format ! (
296
- "`{}` must implement `{}`" ,
297
- expected_trait_ref. self_ty( ) ,
303
+ "`{}` would have to be implemented for the type `{}`" ,
298
304
expected_trait_ref,
305
+ expected_trait_ref. self_ty( ) ,
299
306
) ) ;
300
307
}
301
308
}
302
309
} )
303
310
} ) ;
304
311
305
- RegionHighlightMode :: maybe_highlighting_region ( vid, has_vid, || match has_vid {
306
- Some ( n) => {
307
- if self_ty_has_vid {
312
+ RegionHighlightMode :: maybe_highlighting_region (
313
+ vid,
314
+ actual_has_vid. or ( expected_has_vid) ,
315
+ || match actual_has_vid {
316
+ Some ( n) => {
317
+ if self_ty_has_vid {
318
+ err. note ( & format ! (
319
+ "but `{}` is actually implemented for the type `{}`, \
320
+ for the specific lifetime `'{}`",
321
+ actual_trait_ref,
322
+ actual_trait_ref. self_ty( ) ,
323
+ n
324
+ ) ) ;
325
+ } else {
326
+ err. note ( & format ! (
327
+ "but `{}` is actually implemented for the type `{}`, \
328
+ for some lifetime `'{}`",
329
+ actual_trait_ref,
330
+ actual_trait_ref. self_ty( ) ,
331
+ n
332
+ ) ) ;
333
+ }
334
+ }
335
+
336
+ _ => {
308
337
err. note ( & format ! (
309
- "but `{}` only implements `{}` for the lifetime `'{}`" ,
310
- actual_trait_ref. self_ty( ) ,
338
+ "but `{}` is actually implemented for the type `{}`" ,
311
339
actual_trait_ref,
312
- n
313
- ) ) ;
314
- } else {
315
- err. note ( & format ! (
316
- "but `{}` only implements `{}` for some lifetime `'{}`" ,
317
340
actual_trait_ref. self_ty( ) ,
318
- actual_trait_ref,
319
- n
320
341
) ) ;
321
342
}
322
343
}
323
- None => {
324
- err. note ( & format ! (
325
- "but `{}` only implements `{}`" ,
326
- actual_trait_ref. self_ty( ) ,
327
- actual_trait_ref,
328
- ) ) ;
329
- }
330
- } ) ;
344
+ ) ;
331
345
332
346
err. emit ( ) ;
333
347
ErrorReported
0 commit comments