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

A method marked where Self: Sized on a trait should not be considered during object safety checks #22031

Closed
ftxqxd opened this issue Feb 7, 2015 · 2 comments
Labels
A-traits Area: Trait system

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Feb 7, 2015

Because trait objects are never Sized, a method marked where Self: Sized does not have to be implemented on an unsized type (although that’s not currently the case in manual impls due to #20021), so the automatic impl Trait for Trait should also not have to implement the method (and thus should be ignored during object safety checks).

Example:

trait Foo {
    fn foo(&self);

    fn bar<T>(self, x: T) where Self: Sized;
}

impl Foo for () {
    fn foo(&self) {}

    fn bar<T>(self, x: T) {}
}

fn main() {
    let x = &() as &Foo; // error: cannot convert to a trait object because trait `Foo` is
                         //        not object-safe
    // Because the automatic impl of `Foo` for `Foo` should not have to implement `bar`,
    // `bar` should not be considered during object safety checks
}

I’m not very sure if a change like this would require an amendment to the object safety RFC or not, and thus whether this issue belongs in rust-lang/rfcs or here. I’m treating this as a bug because it seems to me that trait Foo is in fact object safe, whereas the compiler says otherwise.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented May 15, 2015

With rust-lang/rfcs#817 accepted and implemented, this is done.

@ftxqxd ftxqxd closed this as completed May 15, 2015
@Monnoroch
Copy link

Monnoroch commented Jun 14, 2018

@P1start I believe this is not done for methods that has no receiver. Is this implemented like this on purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system
Projects
None yet
Development

No branches or pull requests

3 participants