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

"Static" methods should not be object safe #19949

Closed
nikomatsakis opened this issue Dec 17, 2014 · 2 comments · Fixed by #20325
Closed

"Static" methods should not be object safe #19949

nikomatsakis opened this issue Dec 17, 2014 · 2 comments · Fixed by #20325

Comments

@nikomatsakis
Copy link
Contributor

While reading the object safety code I found this:

ty::StaticExplicitSelfCategory => {
    // Static methods are always object-safe since they
    // can't be called through a trait object
    return msgs
}

I think this is sadly incorrect. The whole idea of object safety is to ensure that an object type Foo implements the trait Foo. But if that is the case, then we can have an example like this one:

trait Foo for Sized? {
    fn make() -> Self; // static method
}

fn use<Sized? F:Foo>() {
    let x = Foo::make();
}

fn main() {
    use::<Foo>();
}

cc @nick29581
cc @aturon

@nikomatsakis
Copy link
Contributor Author

I hope that fixing this doesn't cause another round of annoyed users. :(

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 17, 2014

See #18527, the PR that introduced this, and rust-lang/rfcs#428, which is the same issue as this one.

nrc added a commit to nrc/rust that referenced this issue Dec 30, 2014
Closes rust-lang#19949 and rust-lang/rfcs#428

[breaking change]

If you have traits used with objects with static methods, you'll need to move
the static methods to a different trait.
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 31, 2014
Closes rust-lang#19949 and rust-lang/rfcs#428

[breaking change]

If you have traits used with objects with static methods, you'll need to move
the static methods to a different trait.

r? @cmr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants