@@ -251,10 +251,16 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
251251 }
252252 } ) ;
253253
254- let self_ty_has_vid = self
254+ let actual_self_ty_has_vid = self
255255 . tcx ( )
256256 . any_free_region_meets ( & actual_trait_ref. self_ty ( ) , |r| Some ( r) == vid) ;
257257
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+
258264 debug ! (
259265 "try_report_placeholders_trait: actual_has_vid={:?}" ,
260266 actual_has_vid
@@ -266,8 +272,12 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
266272 debug ! ( "try_report_placeholders_trait: has_sub={:?}" , has_sub) ;
267273 debug ! ( "try_report_placeholders_trait: has_sup={:?}" , has_sup) ;
268274 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
271281 ) ;
272282
273283 // The weird thing here with the `maybe_highlighting_region` calls and the
@@ -289,23 +299,43 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
289299 RegionHighlightMode :: maybe_highlighting_region ( sup_placeholder, has_sup, || {
290300 match ( has_sub, has_sup) {
291301 ( 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+ }
300321 }
301322 ( 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+ }
309339 }
310340 ( None , None ) => RegionHighlightMode :: maybe_highlighting_region (
311341 vid,
@@ -320,11 +350,19 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
320350 n,
321351 ) ) ;
322352 } 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+ }
328366 }
329367 } ,
330368 ) ,
@@ -347,10 +385,9 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
347385 ) ) ;
348386 } else {
349387 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 `'{}`" ,
353389 actual_trait_ref. self_ty( ) ,
390+ actual_trait_ref,
354391 n
355392 ) ) ;
356393 }
0 commit comments