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

Tweak handling of Self in object-safety rules and type parameter defaults #22452

Merged
merged 2 commits into from
Feb 19, 2015

Conversation

nikomatsakis
Copy link
Contributor

The big change here is that we update the object-safety rules to prohibit references to Self in the supertrait listing. See #22040 for the motivation. The other change is to handle the interaction of defaults that reference Self and object types (where Self is erased). We force users to give an explicit type in that scenario.

r? @aturon

@nikomatsakis
Copy link
Contributor Author

I'm having second thoughts about my chosen solution here. It's certainly safe but it's overly broad I suspect. Probably the best thing would be to consider "object safety" to be a function not of a trait in the abstract but of a particular instantiation of a trait in a given context. So in that case a supertrait reference like Baz<Self> would be illegal iff it resulted in a method that takes an argument of type Self (unless e.g. that method requires Sized, at least once RFC rust-lang/rfcs#817 is implemented). I was just a bit too lazy to code that up and I couldn't come up with any purpose for a trait type parameter but to appear in the interface, which seemed like it would always yield an error -- but I hadn't thought about the interactions with rust-lang/rfcs#817 and now I'm thinking maybe it's worth the effort.

@nikomatsakis nikomatsakis force-pushed the issue-22040-18956-Self branch from 724507d to ff388c1 Compare February 17, 2015 22:16
@aturon
Copy link
Member

aturon commented Feb 17, 2015

@bors: r+ ff388c1

@nikomatsakis
Copy link
Contributor Author

For future reference -- after some discussion on IRC, @aturon and I decided it made sense to adopt the (slightly) too conservative solution implemented here, and come back to widen the rules later.

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Feb 19, 2015
The big change here is that we update the object-safety rules to prohibit references to `Self` in the supertrait listing. See rust-lang#22040 for the motivation. The other change is to handle the interaction of defaults that reference `Self` and object types (where `Self` is erased). We force users to give an explicit type in that scenario.

r? @aturon
@bors bors merged commit ff388c1 into rust-lang:master Feb 19, 2015
@nikomatsakis nikomatsakis deleted the issue-22040-18956-Self branch March 30, 2016 16:14
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.

3 participants