rust-lang / rust-lang/reference
Type paremters constraints in generic implementations description is inaccurate
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
https://doc.rust-lang.org/reference/items/implementations.html#generic-implementations
Generic parameters constrain an implementation if the parameter appears at least once in one of:
- ...
- As an associated type in the bounds of a type that contains another parameter that constrains the implementation
However, RFC 447 says that all parameters should be constrained:
Type parameters are legal if they are "constrained" according to the following inference rules:
- ...
- If
<T0 as Trait<T1...Tn>>::U == Vappears in the impl predicates, andT0...Tnare constrained andT0 as Trait<T1...Tn>is not the impl trait reference thenVis constrained.
This is also what implemented by the compiler.
See also Why does Fn() -> T constrain T but Fn(T) -> T does not.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generic implementations section in the Rust Reference and compare its constraint description with RFC 447 and compiler/rustc_typeck/src/constrained_generic_params.rs around the linked implementation. Verify the associated-type inference rule, including the Fn() -> T versus Fn(T) -> T distinction. Done when the Reference accurately describes the compiler's constraint behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100