rust-lang / rust-lang/reference

Type paremters constraints in generic implementations description is inaccurate

Open
#1,183 0 comments 0 reactions 0 assignees View on GitHub

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 == V appears in the impl predicates, and T0...Tn are constrained and T0 as Trait<T1...Tn> is not the impl trait reference then V is 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.