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

Document how self: Self receiver types *actually* interact with object safety #1455

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

steffahn
Copy link
Member

@steffahn steffahn commented Jan 26, 2024

Fixes #1247

The description here on how this works is based purely on experiments on what the compiler does or does not accept (without unstable features), not on any inspection of the implementation in rustc. The term of “implicitly non-dispatchable functions” is one I just made up, as far as I’m aware, because it makes sense in this context. The motivation of future-compatibility is just my guess, too.

I might want to read up some actual sources around relevant RFCs and/or PRs, for precise (intended) behavior, terminology, and motivation of the behavior of self: Self but not Self: Sized methods in traits.

For review, especially if any of my “guesses” here are wrong, I’d thus also appreciate relevant links to relevant discussions to learn from.

@steffahn
Copy link
Member Author

cc @QuineDot since you recently opened #1445, so you might have some ideas or feedback here

@steffahn steffahn changed the title Document how Self receiver types *actually* interact with object safety Document how self: Self receiver types *actually* interact with object safety Jan 26, 2024
@QuineDot
Copy link

QuineDot commented Jun 5, 2024

See this PR -- it's not just Self: Sized that makes a method non-dispatchable, it's TypeInvolvingSelf: NonAutoTrait... plus some others. See also.

I haven't experimented enough to feel 💯 confident in what is and isn't accepted, and there is some wonkiness around the check. Such as the "empty bounds" in the examples below...

Example where clauses which are fine (do not make the method non-dispatchable):

  • Self: Send
  • Self: 'a
  • Self:
  • Self::AssociatedType: Debug
  • Box<Self>: 'a

Example where clauses which make the method non-dispatchable:

  • Self: Debug
  • Box<Self>: Debug
  • Box<Self>: Send
  • Box<Self>: 🤷
  • dyn Trait<Assoc = Box<Self>>: Debug

Tangential aside: Self: Sized in an implied bound (e.g. where Self: Clone) also counts as explicitly non-dispatchable.

@traviscross
Copy link
Contributor

We reviewed this PR in the rustdocs call, and we've asked for review of this by the types team in:

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 this pull request may close these issues.

Rule around non-dispatchable functions doesn't match the compiler behavior
3 participants