-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add support for default trait implementations #21689
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6a2f16e
Add support for default trait impls in libsyntax
flaper87 4148d53
Fix fallout from libsyntax implementation
flaper87 a962d47
look for default trait candidates
flaper87 839a9de
Prefer other implementations over default ones
flaper87 ad3e748
Don't allow default impls for traits outside their crate
flaper87 bd511f7
Add negative impls for `*const T` and `*mut T`
flaper87 7ae8889
Add negative impls for Sync
flaper87 58a8103
Fix rustdoc fallout
flaper87 4b09209
Ensure default trait impls hold
flaper87 d523acb
Use a Vec<N> instead of VecPerParamSpace<N>
flaper87 7e38213
Make default_trait_impls private and add accessor
flaper87 d38aab3
Rename DefTrait to DefaultImpl
flaper87 f0e9bd9
address nits
flaper87 1e3ed61
Coherence for default trait implementations
flaper87 d215411
Make Send/Sync go through the default implementation path
flaper87 40fffc9
Some nits and cleanup
nikomatsakis 0be1e43
Fix error codes
flaper87 7213ef1
Test all the things
flaper87 f7a75e0
Add new test case showing that supertraits are not enough
nikomatsakis 64d33d8
check supertraits
flaper87 24bdce4
some comments and nits
nikomatsakis e8df95d
mark candidate set ambig for defaulted traits where self-type is not …
nikomatsakis 38ef5ee
Check constituent types are known
flaper87 1cc5a87
Don't report bug for IntVar and FloatVar
flaper87 640000a
fix treatment of parameters and associated types
nikomatsakis 3ebc2ab
tweak exhaustive matching of ty_infer
nikomatsakis 6d1844c
Record default implementations in a separate step
flaper87 3343e9c
Add new test for impl precedence and remove unnecessary coherence rul…
nikomatsakis d021c55
Restore the coherence visitor and fix fallouts
flaper87 753db88
allow negative impls for traits that have a default impl
flaper87 038d7e6
Fix test fallouts
flaper87 3dcc631
Add additional test case for superregion
nikomatsakis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,6 +221,12 @@ pub enum Vtable<'tcx, N> { | |
/// Vtable identifying a particular impl. | ||
VtableImpl(VtableImplData<'tcx, N>), | ||
|
||
/// Vtable for default trait implementations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's expand this comment a bit more. I think this corresponds to what happens when a |
||
/// This carries the information and nested obligations with regards | ||
/// to a default implementation for a trait `Trait`. The nested obligations | ||
/// ensure the trait implementation holds for all the constituent types. | ||
VtableDefaultImpl(VtableDefaultImplData<N>), | ||
|
||
/// Successful resolution to an obligation provided by the caller | ||
/// for some type parameter. The `Vec<N>` represents the | ||
/// obligations incurred from normalizing the where-clause (if | ||
|
@@ -259,6 +265,12 @@ pub struct VtableImplData<'tcx, N> { | |
pub nested: subst::VecPerParamSpace<N> | ||
} | ||
|
||
#[derive(Debug,Clone)] | ||
pub struct VtableDefaultImplData<N> { | ||
pub trait_def_id: ast::DefId, | ||
pub nested: Vec<N> | ||
} | ||
|
||
#[derive(Debug,Clone)] | ||
pub struct VtableBuiltinData<N> { | ||
pub nested: subst::VecPerParamSpace<N> | ||
|
@@ -513,17 +525,18 @@ impl<'tcx, N> Vtable<'tcx, N> { | |
pub fn iter_nested(&self) -> Iter<N> { | ||
match *self { | ||
VtableImpl(ref i) => i.iter_nested(), | ||
VtableFnPointer(..) => (&[]).iter(), | ||
VtableClosure(..) => (&[]).iter(), | ||
VtableParam(ref n) => n.iter(), | ||
VtableObject(_) => (&[]).iter(), | ||
VtableBuiltin(ref i) => i.iter_nested(), | ||
VtableObject(_) | | ||
VtableDefaultImpl(..) | VtableFnPointer(..) | | ||
VtableClosure(..) => (&[]).iter(), | ||
} | ||
} | ||
|
||
pub fn map_nested<M, F>(&self, op: F) -> Vtable<'tcx, M> where F: FnMut(&N) -> M { | ||
match *self { | ||
VtableImpl(ref i) => VtableImpl(i.map_nested(op)), | ||
VtableDefaultImpl(ref t) => VtableDefaultImpl(t.map_nested(op)), | ||
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()), | ||
VtableClosure(d, ref s) => VtableClosure(d, s.clone()), | ||
VtableParam(ref n) => VtableParam(n.iter().map(op).collect()), | ||
|
@@ -539,6 +552,7 @@ impl<'tcx, N> Vtable<'tcx, N> { | |
VtableImpl(i) => VtableImpl(i.map_move_nested(op)), | ||
VtableFnPointer(sig) => VtableFnPointer(sig), | ||
VtableClosure(d, s) => VtableClosure(d, s), | ||
VtableDefaultImpl(t) => VtableDefaultImpl(t.map_move_nested(op)), | ||
VtableParam(n) => VtableParam(n.into_iter().map(op).collect()), | ||
VtableObject(p) => VtableObject(p), | ||
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)), | ||
|
@@ -573,6 +587,31 @@ impl<'tcx, N> VtableImplData<'tcx, N> { | |
} | ||
} | ||
|
||
impl<N> VtableDefaultImplData<N> { | ||
pub fn iter_nested(&self) -> Iter<N> { | ||
self.nested.iter() | ||
} | ||
|
||
pub fn map_nested<M, F>(&self, op: F) -> VtableDefaultImplData<M> where | ||
F: FnMut(&N) -> M, | ||
{ | ||
VtableDefaultImplData { | ||
trait_def_id: self.trait_def_id, | ||
nested: self.nested.iter().map(op).collect() | ||
} | ||
} | ||
|
||
pub fn map_move_nested<M, F>(self, op: F) -> VtableDefaultImplData<M> where | ||
F: FnMut(N) -> M, | ||
{ | ||
let VtableDefaultImplData { trait_def_id, nested } = self; | ||
VtableDefaultImplData { | ||
trait_def_id: trait_def_id, | ||
nested: nested.into_iter().map(op).collect() | ||
} | ||
} | ||
} | ||
|
||
impl<N> VtableBuiltinData<N> { | ||
pub fn iter_nested(&self) -> Iter<N> { | ||
self.nested.iter() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we add a comment explaining what this is checking for? I haven't finished reading yet but i'm definitely a bit confused as to what a "default trait" is -- the name says trait, but it's treated like an impl.