Skip to content

Self receiver does *not* imply Self: Sized #1445

New issue

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

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

Already on GitHub? # to your account

Closed
QuineDot opened this issue Jan 1, 2024 · 1 comment
Closed

Self receiver does *not* imply Self: Sized #1445

QuineDot opened this issue Jan 1, 2024 · 1 comment

Comments

@QuineDot
Copy link

QuineDot commented Jan 1, 2024

The object safety page says

  • All associated functions must either be dispatchable from a trait object or be explicitly non-dispatchable:
    • Dispatchable functions must:
      • [...]
      • Not have a where Self: Sized bound (receiver type of Self (i.e. self) implies this).
    • Explicitly non-dispatchable functions require:
      • Have a where Self: Sized bound (receiver type of Self (i.e. self) implies this).

However, it is not true that a receiver type of Self implies Self: Sized.

// Minimal example; it also can be demonstrated with bounds that
// require `Sized`, like `<G: From<Self>>` say, even without a
// function body
trait Trait {
    // Fails without an explicit `where Self: Sized` bound
    fn method(self) {}
}

Accepting self-receiving methods as object-safe methods was a separate consideration from a Self: Sized bound in the RFC.

This is why all methods that require Self:Sized are exempt from the typical rules. This is also why by-value self methods are permitted, since currently one cannot invoke pass an unsized type by-value (though we consider that a useful future extension).

@ehuss
Copy link
Contributor

ehuss commented Jan 1, 2024

Thanks for the report! I believe this is a duplicate of #1247, so closing in favor of that.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants