Error typechecking lifetime-GAT bound when "parent" bound is inferred · Issue #96230 · rust-lang/rust (original) (raw)
I tried this code:
#![feature(generic_associated_types)]
use std::fmt::Debug;
trait Classic { type Assoc; }
trait Gat { type Assoc<'a>; }
struct Foo;
impl Classic for Foo { type Assoc = (); }
impl Gat for Foo { type Assoc<'i> = (); }
fn classic_debug<T: Classic>(_: T) where T::Assoc: Debug, { }
fn gat_debug<T: Gat>(_: T) where for<'a> T::Assoc<'a>: Debug, { }
fn main() { classic_debug::(Foo); // fine classic_debug(Foo); // fine
gat_debug::<Foo>(Foo); // fine
gat_debug(Foo); // boom
}
I expected to see this happen: It compiles
Instead, this happened: It fails type checking, with:
error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): `<_ as Gat>::Assoc<'a>` doesn't implement `Debug`
[--> src/main.rs:40:5
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) |
40 | gat_debug(Foo); // boom
| ^^^^^^^^^ `<_ as Gat>::Assoc<'a>` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `for<'a> Debug` is not implemented for `<_ as Gat>::Assoc<'a>`
note: required by a bound in `gat_debug`
[--> src/main.rs:31:27
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) |
29 | fn gat_debug<T: Gat>(_: T)
| --------- required by a bound in this
30 | where
31 | for<'a> T::Assoc<'a>: Debug,
| ^^^^^ required by this bound in `gat_debug`