rust-lang / rust-lang/reference

document difference between T:: and <T>:: in paths

Open
#2,256 3 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

Background: this is something that I stumbled across while researching #24.

The Paths section has distinct syntax for PathInExpression and QualifiedPathInExpression. What isn't clear is the semantic difference between, say, T::func and <T>::func where T is a type.

I think T in <T>::func is not subject to inference, and therefore all of its generic type arguments must be explicitly specified, or defaulted. I'm not quite able to conclusively show it to my satisfaction, though.

It is clear that <Trait>::func isn't valid, and possibly this should be documented (even though it's implied by the production names).

#[derive(Debug)]
struct S(u8);
trait Tr {
    fn foo() -> Self;
}
impl Tr for S {
    fn foo() -> Self { Self(1) }
}
fn main() {
    // The following is an error, because Tr is a trait, not a type.
    // let x: S = <Tr>::foo();

    let x: S = Tr::foo();
    println!("{:?}", x);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=c7f60a975096972761bcaaa58f692379

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 in the Reference's Paths section and compare the PathInExpression and QualifiedPathInExpression definitions, using the linked playground example to verify their behavior. Document the semantic difference between T::func and ::func, including generic argument inference and why ::func is invalid; the section is done when these cases are explained with a clear example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.