Skip to content

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

@tlyu

Description

@tlyu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions