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

Apply stricter orphan rules for traits with defaulted impls #23038

Merged
merged 4 commits into from
Mar 10, 2015

Conversation

nikomatsakis
Copy link
Contributor

Fixes #22978.

r? @flaper87

@nikomatsakis nikomatsakis force-pushed the issue-22978-defaulted-coherence branch from c579929 to d81dab6 Compare March 4, 2015 20:29
self.tcx.sess.span_err(
item.span,
"cross-crate traits with a default impl \
can only be implemented for a struct/enum type \
Copy link
Contributor

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

@bors
Copy link
Contributor

bors commented Mar 5, 2015

☔ 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.
@nikomatsakis nikomatsakis force-pushed the issue-22978-defaulted-coherence branch from d81dab6 to 4e789e0 Compare March 6, 2015 23:28
@nikomatsakis
Copy link
Contributor Author

@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>`.
Copy link
Contributor

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

@flaper87
Copy link
Contributor

flaper87 commented Mar 7, 2015

Couple of nits, otherwise, it looks good to me.

@nikomatsakis
Copy link
Contributor Author

@bors r=flaper87 17358d1

Did a quick poll and found at least one other person of my opinion (that using the same code seems good), so I'm going to leave it that way :)

@bors
Copy link
Contributor

bors commented Mar 9, 2015

⌛ Testing commit 17358d1 with merge 12b846a...

bors added a commit that referenced this pull request Mar 9, 2015
@bors bors merged commit 17358d1 into rust-lang:master Mar 10, 2015
@nikomatsakis nikomatsakis deleted the issue-22978-defaulted-coherence 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.

defaulted traits ought to be have more restrictive coherence rules
3 participants