Skip to content

Self should be consistently usable within method bodies #24389

Closed
@Diggsey

Description

@Diggsey

The following code will fail to compile at "Self::new()" with the message, "error: failed to resolve. Use of undeclared type or module Self"

struct Foo;

impl Foo {
    fn new() -> Self { Foo }
    fn bar() { Self::new(); }
}

While either of the following will work:

    fn bar() { <Self>::new(); }
    fn bar() { let x: Self = Foo::new(); }

The first example should compile as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions