-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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).
rust/src/libsyntax_ext/deriving/generic/mod.rs
Lines 350 to 352 in 9fae153
/// This method helps to extract all the type parameters referenced from a | |
/// type. For a type parameter `<T>`, 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: <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.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.