Skip to content

Strange error for use of self when a impl declares a method as static but the trait doesn't #4142

Closed
@huonw

Description

@huonw

If you try to implement a trait, but accidentally implement a non-static method as static, rustc gives a error message for any use of self in the body of the function (with and without explicit self) rather than for the conflict in static-ness.

test-static-self.rs:7:8: 7:12 error: unresolved name: self
test-static-self.rs:7         self
                              ^~~~
error: aborting due to previous error

Testcase:

trait A {
   fn a(self) -> int;
}

impl int : A {
    static fn a(self) -> int {
        self
    }
}

fn main() {}

If there are no references to self in the body, rustc gives the more useful error: method 'a' is declared as static in its impl, but not in its trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions