Skip to content

Reimplement Self in impls in the compiler #23909

Closed
@nrc

Description

@nrc

Currently the Self:: shorthand in the body of an impl is implemented by syntactic expansion in libsyntax. That leads to a bug if another item shadows the concrete type. E.g.,

struct Foo;

impl Foo {
    fn foo() {}
    fn bar() {
        let Foo = ...;
        Self::foo(); // Whoops!
    }
}

The Self on the commented line will cause an error in name resolution, since Self ends up referring to the local variable Foo, not the self type.

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions