rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.42k stars 12.73k forks source link

#[derive] fails to detect associated type when qualified path is used #50730

Open durka opened 6 years ago

durka commented 6 years ago

The deriving code scans the field types in order to generate bounds on associated types, if they happen to be used as a field type (this isn't foolproof but it catches a lot of cases).

https://github.com/rust-lang/rust/blob/9fae1537462bb10fd17d07816efc17cfe4786806/src/libsyntax_ext/deriving/generic/mod.rs#L350-L352

The comment in this code implies that field: T::Assoc and field: <T as Trait>::Assoc would both work. However, the second one is missed and the required bound is not generated, resulting in a type error:

#[derive(Debug)]
struct Foo<T: FromStr> {
    field: <T as FromStr>::Err
}
error[E0277]: `<T as std::str::FromStr>::Err` doesn't implement `std::fmt::Debug`
  --> expr.rs:18:77
   |
18 |     field: <T as FromStr>::Err
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ `<T as std::str::FromStr>::Err` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `<T as std::str::FromStr>::Err`
   = help: consider adding a `where <T as std::str::FromStr>::Err: std::fmt::Debug` bound
   = note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as std::str::FromStr>::Err`
   = note: required for the cast to the object type `std::fmt::Debug`

cc #26925.

fmease commented 2 months ago

Triage 2024: No change.