#[derive] fails to detect associated type when qualified path is used · Issue #50730 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
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).
/// This method helps to extract all the type parameters referenced from a |
---|
/// type. For a type parameter ``, it looks for either a `TyPath` that |
/// is not global and starts with `T`, or a `TyQPath`. |
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: ::Err }
error[E0277]: `<T as std::str::FromStr>::Err` doesn't implement `std::fmt::Debug`
--> expr.rs🔞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.