rust-lang / rust-lang/reference
document difference between T:: and <T>:: in paths
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);
}
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 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