Change:
<ins> error[E0277]: the trait bound `for<'a> &'a u32: Foo2<'_, u32>` is not satisfied --> $DIR/issue-54302-cases.rs:73:5 | LL |     <u32 as RefFoo<u32>>::ref_foo(a) |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Foo2<'_, u32>` is not implemented for `&'a u32` | = help: the following implementations were found: <&'x u32 as Foo2<'x, u32>> = note: required because of the requirements on the impl of `for<'a> Foo<'static, u32>` for `&'a u32` = note: required because of the requirements on the impl of `RefFoo<u32>` for `u32` note: required by `RefFoo::ref_foo` --> $DIR/issue-54302-cases.rs:61:5 | LL |     fn ref_foo(&self) -> &'static T; |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0279]: the requirement `for<'a> 'a : ` is not satisfied (`expected bound lifetime parameter 'a, found concrete lifetime`) --> $DIR/issue-54302-cases.rs:79:5 | LL |     <i32 as RefFoo<i32>>::ref_foo(a) |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: required because of the requirements on the impl of `for<'a> Foo2<'_, i32>` for `&'a i32` = note: required because of the requirements on the impl of `for<'a> Foo<'static, i32>` for `&'a i32` = note: required because of the requirements on the impl of `RefFoo<i32>` for `i32` note: required by `RefFoo::ref_foo` --> $DIR/issue-54302-cases.rs:61:5 | LL |     fn ref_foo(&self) -> &'static T; |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0271]: type mismatch resolving `for<'a> <&'a u64 as Mirror>::Image == &u64` --> $DIR/issue-54302-cases.rs:85:5 | LL |     <u64 as RefFoo<u64>>::ref_foo(a) |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter 'a, found concrete lifetime | = note: required because of the requirements on the impl of `for<'a> Foo2<'_, u64>` for `&'a u64` = note: required because of the requirements on the impl of `for<'a> Foo<'static, u64>` for `&'a u64` = note: required because of the requirements on the impl of `RefFoo<u64>` for `u64` note: required by `RefFoo::ref_foo` --> $DIR/issue-54302-cases.rs:61:5 | LL |     fn ref_foo(&self) -> &'static T; |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0271]: type mismatch resolving `for<'a> <&'a i64 as Mirror>::Image == &i64` --> $DIR/issue-54302-cases.rs:91:5 | LL |     <i64 as RefFoo<i64>>::ref_foo(a) |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected bound lifetime parameter 'a, found concrete lifetime | = note: required because of the requirements on the impl of `for<'a> Foo2<'_, i64>` for `&'a i64` = note: required because of the requirements on the impl of `for<'a> Foo<'static, i64>` for `&'a i64` = note: required because of the requirements on the impl of `RefFoo<i64>` for `i64` note: required by `RefFoo::ref_foo` --> $DIR/issue-54302-cases.rs:61:5 | LL |     fn ref_foo(&self) -> &'static T; |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors Some errors occurred: E0271, E0277, E0279. For more information about an error, try `rustc --explain E0271`. </ins>

Discussion:
This is a regression between rustc 1.20.0 and 1.21.0. 20 correctly rejects this code with the following error.
Tagging P-high because this very much affects Serde.
Same issue using Serde traits: (One possible) output:
Even better, :
Perhaps we can bisect this regression? (e.g., with )
Bisected to correct behavior in nightly-2017-07-07 -- rustc 1.20.0-nightly ( 2017-07-06), incorrect behavior in nightly-2017-07-08 -- rustc 1.20.0-nightly ( 2017-07-07). That range is Looks like
visited for triage. Assigning to
thanks, very helpful!
I think the bug is here: In particular, I think the condition is not strong enough. doesn't consider region annotations, so we probably need to not use this logic if there are any regions. But I'm wondering if the whole concept is flawed. I'm a bit fearful of regions being introduced through associated type normalization.
I have a fix.
Of course, any approach that relies on any lifetimes in the affected trait-ref is fatally flawed - here's an example where the trait ref is the region-free .
I'm not really sure what your example is meant to illustrate. That said, running that on my branch gives an error: This seems like the error I would expect, more or less. We try to use the impl to prove that but we fail to do so (because of the side condition that it adds).
BTW, the check looks like it happened because I used there, and an explicit check when he changed in to note be made true by late-bound regions.
visited for triage. bug seems to be being dealt with, assuming that PR is eventually deemed as passing muster...
Yes, I think that the "no late-bound regions" check was basically a workaround for this same problem; I removed it in the PR since I think it has a "more correct" fix.