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

librustc: Implement explicit self for objects #4068

Closed
wants to merge 3 commits into from

Conversation

pcwalton
Copy link
Contributor

@pcwalton
Copy link
Contributor Author

I'm not sure that's simpler than just enforcing the method restrictions at the call site, on a per-method basis. I'm worried about the loss of flexibility that would result from "if one method is tainted, the entire trait is tainted".

@nikomatsakis
Copy link
Contributor

r+ --- however, I believe that our type system does not currently enforce the various common-sense requirements that the trans code expects. We should open up another bug to draft and enforce those rules.

@nikomatsakis
Copy link
Contributor

@pcwalton the main thing is that the rules get complicated due to the possibility of generic types. Keep in mind that one can always refactor one's traits to include a supertrait with only object-compatible methods and a subtype with the other methods.

In any case, I am also fine with extending the more fine-grained approach we have now. However, I have historically found it hard to explain, even just to other team members, much less the "general public". The fact that it took me an hour to explain it to dherman when it was just us two in a room with a whiteboard made me nervous. But maybe I just did a bad job. For reference, the full set of rules we enforce today are:

  • if you have an object receiver, you cannot invoke the forbidden methods
  • if a trait T contains forbidden methods, then an object @T is not considered to implement the trait T

So I could imagine a rule that says something like:

  • given an object receiver @T, you can call &self or @self methods
  • given an object receiver ~T, you can call &self or ~self methods
  • given an object receiver &T, you can call &self methods
  • if there are any methods that are not &self, then T objects do not implement T

@pcwalton pcwalton closed this Dec 1, 2012
RalfJung added a commit to RalfJung/rust that referenced this pull request Dec 21, 2024
solarish stat following-up, supports for readdir.
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.

2 participants