-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Apply stricter orphan rules for traits with defaulted impls #23038
Apply stricter orphan rules for traits with defaulted impls #23038
Conversation
c579929
to
d81dab6
Compare
self.tcx.sess.span_err( | ||
item.span, | ||
"cross-crate traits with a default impl \ | ||
can only be implemented for a struct/enum type \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we make these 2 error messages consistent struct/enum
vs struct or enum
☔ The latest upstream changes (presumably #23026) made this pull request unmergeable. Please resolve the merge conflicts. |
now have a simple set of trait def-ids. During coherence, we use a separate table to track the default impls for any given trait so that we can report a nice error. This fixes various bugs in the metadata encoding that led to `ty::trait_has_default_impl` yielding the wrong values in the cross-crate case. (In particular, default impl def-ids were not included in the list of all impl def-ids; I debated fixing just that, but this approach seemed cleaner overall, since we usually treat the "defaulted" bit on traits as being a property of the trait, and now iterating over a list of impls doesn't intermingle default impls with normal impls.)
since there are separate checks that apply to Copy (and Send uses the generic defaulted trait rules). Also prohibit `Sized` from being manually implemented for now.
d81dab6
to
4e789e0
Compare
@flaper87 I addressed your nits. Can you please r? the final commit, it's got new material. |
// We only want to permit structs/enums, but not *all* structs/enums. | ||
// They must be local to the current crate, so that people | ||
// can't do `unsafe impl Send for Rc<SomethingLocal>` or | ||
// `unsafe impl !Send for Box<SomethingLocalAndSend>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: negative impls aren't unsafe
Couple of nits, otherwise, it looks good to me. |
Fixes #22978.
r? @flaper87