Open
Conversation
Proposes associated traits — named trait constraints declared abstractly in a trait and given concrete values in implementations. This is the trait-level analog of associated types and the Rust equivalent of Haskell's ConstraintKinds. Based on rust-lang#2190 (76+ upvotes, 2017-present) and a working prototype implementation on the rust-lang/rust associated-traits branch with 57 tests and full UI suite passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dyn T::Elem is not supported because Rust type-checks generic bodies before monomorphization, so the vtable layout (which depends on T) is not yet known. Remove dyn binding syntax from future possibilities.
Bound expansion in method bodies and impl Self::AssocTrait in method arguments are both implemented. Remove from unresolved questions.
Move from unresolved questions and future possibilities to implemented features. Add guide-level documentation.
… restructure scope sections
Replace implementation details (AST variants, HIR representations, DefKind, solver internals) with language-level reference material: - Associated trait declarations (grammar, declaration bounds, defaults) - Associated trait implementations (values, validation, restrictions) - Usage as bounds (shorthand, UFCS, where clauses, impl Trait) - Positions where rejected (type, dyn, inherent impl) - Generic associated traits - Interaction with associated types, GATs, trait inheritance, auto-traits - Cross-crate usage - Comparison table Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow traits to declare associated traits — named trait constraints that are defined abstractly in a trait and given concrete values in implementations. Just as associated types let a trait abstract over which type is used, associated traits let a trait abstract over which constraints are imposed. This is the trait-level analog of associated types.
Previous discussion in #2190.
Prototype implementation: https://github.com/sandersaares/rust/tree/associated-traits
Rendered
Important
When responding to RFCs, try to use inline review comments (it is possible to leave an inline review comment for the entire file at the top) instead of direct comments for normal comments and keep normal comments for procedural matters like starting FCPs.
This keeps the discussion more organized.