@@ -251,10 +251,16 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
251
251
}
252
252
} ) ;
253
253
254
- let self_ty_has_vid = self
254
+ let actual_self_ty_has_vid = self
255
255
. tcx ( )
256
256
. any_free_region_meets ( & actual_trait_ref. self_ty ( ) , |r| Some ( r) == vid) ;
257
257
258
+ let expected_self_ty_has_vid = self
259
+ . tcx ( )
260
+ . any_free_region_meets ( & expected_trait_ref. self_ty ( ) , |r| Some ( r) == vid) ;
261
+
262
+ let self_ty_has_vid = actual_self_ty_has_vid || expected_self_ty_has_vid;
263
+
258
264
debug ! (
259
265
"try_report_placeholders_trait: actual_has_vid={:?}" ,
260
266
actual_has_vid
@@ -266,8 +272,12 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
266
272
debug ! ( "try_report_placeholders_trait: has_sub={:?}" , has_sub) ;
267
273
debug ! ( "try_report_placeholders_trait: has_sup={:?}" , has_sup) ;
268
274
debug ! (
269
- "try_report_placeholders_trait: self_ty_has_vid={:?}" ,
270
- self_ty_has_vid
275
+ "try_report_placeholders_trait: actual_self_ty_has_vid={:?}" ,
276
+ actual_self_ty_has_vid
277
+ ) ;
278
+ debug ! (
279
+ "try_report_placeholders_trait: expected_self_ty_has_vid={:?}" ,
280
+ expected_self_ty_has_vid
271
281
) ;
272
282
273
283
// The weird thing here with the `maybe_highlighting_region` calls and the
@@ -289,23 +299,43 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
289
299
RegionHighlightMode :: maybe_highlighting_region ( sup_placeholder, has_sup, || {
290
300
match ( has_sub, has_sup) {
291
301
( Some ( n1) , Some ( n2) ) => {
292
- err. note ( & format ! (
293
- "`{}` would have to be implemented for the type `{}`, \
294
- for any two lifetimes `'{}` and `'{}`",
295
- expected_trait_ref,
296
- expected_trait_ref. self_ty( ) ,
297
- std:: cmp:: min( n1, n2) ,
298
- std:: cmp:: max( n1, n2) ,
299
- ) ) ;
302
+ if self_ty_has_vid {
303
+ err. note ( & format ! (
304
+ "`{}` would have to be implemented for the type `{}`, \
305
+ for any two lifetimes `'{}` and `'{}`",
306
+ expected_trait_ref,
307
+ expected_trait_ref. self_ty( ) ,
308
+ std:: cmp:: min( n1, n2) ,
309
+ std:: cmp:: max( n1, n2) ,
310
+ ) ) ;
311
+ } else {
312
+ err. note ( & format ! (
313
+ "`{}` must implement `{}`, \
314
+ for any two lifetimes `'{}` and `'{}`",
315
+ expected_trait_ref. self_ty( ) ,
316
+ expected_trait_ref,
317
+ std:: cmp:: min( n1, n2) ,
318
+ std:: cmp:: max( n1, n2) ,
319
+ ) ) ;
320
+ }
300
321
}
301
322
( Some ( n) , _) | ( _, Some ( n) ) => {
302
- err. note ( & format ! (
303
- "`{}` would have to be implemented for the type `{}`, \
304
- for any lifetime `'{}`",
305
- expected_trait_ref,
306
- expected_trait_ref. self_ty( ) ,
307
- n,
308
- ) ) ;
323
+ if self_ty_has_vid {
324
+ err. note ( & format ! (
325
+ "`{}` would have to be implemented for the type `{}`, \
326
+ for any lifetime `'{}`",
327
+ expected_trait_ref,
328
+ expected_trait_ref. self_ty( ) ,
329
+ n,
330
+ ) ) ;
331
+ } else {
332
+ err. note ( & format ! (
333
+ "`{}` must implement `{}`, for any lifetime `'{}`" ,
334
+ expected_trait_ref. self_ty( ) ,
335
+ expected_trait_ref,
336
+ n,
337
+ ) ) ;
338
+ }
309
339
}
310
340
( None , None ) => RegionHighlightMode :: maybe_highlighting_region (
311
341
vid,
@@ -320,11 +350,19 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
320
350
n,
321
351
) ) ;
322
352
} else {
323
- err. note ( & format ! (
324
- "`{}` would have to be implemented for the type `{}`" ,
325
- expected_trait_ref,
326
- expected_trait_ref. self_ty( ) ,
327
- ) ) ;
353
+ if self_ty_has_vid {
354
+ err. note ( & format ! (
355
+ "`{}` would have to be implemented for the type `{}`" ,
356
+ expected_trait_ref,
357
+ expected_trait_ref. self_ty( ) ,
358
+ ) ) ;
359
+ } else {
360
+ err. note ( & format ! (
361
+ "`{}` must implement `{}`" ,
362
+ expected_trait_ref. self_ty( ) ,
363
+ expected_trait_ref,
364
+ ) ) ;
365
+ }
328
366
}
329
367
} ,
330
368
) ,
@@ -347,10 +385,9 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
347
385
) ) ;
348
386
} else {
349
387
err. note ( & format ! (
350
- "but `{}` is actually implemented for the type `{}`, \
351
- for some lifetime `'{}`",
352
- actual_trait_ref,
388
+ "but `{}` actually implements `{}`, for some lifetime `'{}`" ,
353
389
actual_trait_ref. self_ty( ) ,
390
+ actual_trait_ref,
354
391
n
355
392
) ) ;
356
393
}
0 commit comments