@@ -246,7 +246,9 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
246246 let mut counter = 0 ;
247247 let mut has_sub = None ;
248248 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 ;
250252
251253 self . tcx ( ) . for_each_free_region ( & expected_trait_ref, |r| {
252254 if Some ( r) == sub_placeholder && has_sub. is_none ( ) {
@@ -256,11 +258,16 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
256258 has_sup = Some ( counter) ;
257259 counter += 1 ;
258260 }
261+
262+ if Some ( r) == vid && expected_has_vid. is_none ( ) {
263+ expected_has_vid = Some ( counter) ;
264+ counter += 1 ;
265+ }
259266 } ) ;
260267
261268 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) ;
264271 counter += 1 ;
265272 }
266273 } ) ;
@@ -274,60 +281,67 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
274281 match ( has_sub, has_sup) {
275282 ( Some ( n1) , Some ( n2) ) => {
276283 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 `'{}`",
280286 expected_trait_ref,
287+ expected_trait_ref. self_ty( ) ,
281288 std:: cmp:: min( n1, n2) ,
282289 std:: cmp:: max( n1, n2) ,
283290 ) ) ;
284291 }
285292 ( Some ( n) , _) | ( _, Some ( n) ) => {
286293 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 `'{}`",
290296 expected_trait_ref,
297+ expected_trait_ref. self_ty( ) ,
291298 n,
292299 ) ) ;
293300 }
294301 ( None , None ) => {
295302 err. note ( & format ! (
296- "`{}` must implement `{}`" ,
297- expected_trait_ref. self_ty( ) ,
303+ "`{}` would have to be implemented for the type `{}`" ,
298304 expected_trait_ref,
305+ expected_trait_ref. self_ty( ) ,
299306 ) ) ;
300307 }
301308 }
302309 } )
303310 } ) ;
304311
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+ _ => {
308337 err. note ( & format ! (
309- "but `{}` only implements `{}` for the lifetime `'{}`" ,
310- actual_trait_ref. self_ty( ) ,
338+ "but `{}` is actually implemented for the type `{}`" ,
311339 actual_trait_ref,
312- n
313- ) ) ;
314- } else {
315- err. note ( & format ! (
316- "but `{}` only implements `{}` for some lifetime `'{}`" ,
317340 actual_trait_ref. self_ty( ) ,
318- actual_trait_ref,
319- n
320341 ) ) ;
321342 }
322343 }
323- None => {
324- err. note ( & format ! (
325- "but `{}` only implements `{}`" ,
326- actual_trait_ref. self_ty( ) ,
327- actual_trait_ref,
328- ) ) ;
329- }
330- } ) ;
344+ ) ;
331345
332346 err. emit ( ) ;
333347 ErrorReported
0 commit comments