Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huonw opened this issue Dec 8, 2012 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system

Comments

@huonw
Copy link
Member

huonw commented Dec 8, 2012

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.

@catamorphism
Copy link
Contributor

Bumping to 0.7

@catamorphism
Copy link
Contributor

Seems non-critical for 0.7. Nominating for milestone 5, production-ready.

@graydon
Copy link
Contributor

graydon commented May 2, 2013

this is no longer syntactically legal, fixed

@graydon graydon closed this as completed May 2, 2013
RalfJung added a commit to RalfJung/rust that referenced this issue Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

3 participants