Record default implementations in a separate step
This commit is contained in:
parent
3ebc2abc6a
commit
6d1844c806
8 changed files with 43 additions and 12 deletions
|
@ -847,6 +847,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
self.assemble_candidates_from_projected_tys(obligation, &mut candidates);
|
||||
try!(self.assemble_candidates_from_caller_bounds(stack, &mut candidates));
|
||||
// Default implementations have lower priority, so we only
|
||||
// consider triggering a default if there is no other impl that can apply.
|
||||
if candidates.vec.len() == 0 {
|
||||
try!(self.assemble_candidates_from_default_impls(obligation, &mut candidates));
|
||||
}
|
||||
debug!("candidate list size: {}", candidates.vec.len());
|
||||
Ok(candidates)
|
||||
}
|
||||
|
@ -1142,6 +1147,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assemble_candidates_from_default_impls(&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>)
|
||||
-> Result<(), SelectionError<'tcx>>
|
||||
{
|
||||
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
|
||||
debug!("assemble_candidates_from_default_impls(self_ty={})", self_ty.repr(self.tcx()));
|
||||
|
||||
let def_id = obligation.predicate.def_id();
|
||||
|
||||
if ty::trait_has_default_impl(self.tcx(), def_id) {
|
||||
match self_ty.sty {
|
||||
ty::ty_trait(..) |
|
||||
|
@ -1323,7 +1342,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
(&DefaultImplCandidate(_), _) => {
|
||||
// Prefer other candidates over default implementations.
|
||||
true
|
||||
self.tcx().sess.bug(
|
||||
"default implementations shouldn't be recorded \
|
||||
when there are other valid candidates");
|
||||
}
|
||||
(&ProjectionCandidate, &ParamCandidate(_)) => {
|
||||
// FIXME(#20297) -- this gives where clauses precedent
|
||||
|
|
|
@ -332,6 +332,7 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
|
|||
|
||||
/// Returns a HashMap with the number of occurrences of every element in the
|
||||
/// sequence that the iterator exposes.
|
||||
#[cfg(not(stage0))]
|
||||
pub fn freq_count<T, U>(iter: T) -> hash_map::HashMap<U, uint>
|
||||
where T: Iterator<Item=U>, U: Eq + Clone + Hash
|
||||
{
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait MyTrait {}
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait MyTrait: MarkerTrait {}
|
||||
|
||||
impl MyTrait for .. {}
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait MyTrait {}
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait MyTrait: MarkerTrait {}
|
||||
|
||||
impl MyTrait for .. {}
|
||||
|
||||
|
|
|
@ -10,7 +10,9 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait MyTrait {}
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait MyTrait: MarkerTrait {}
|
||||
|
||||
impl MyTrait for .. {}
|
||||
impl<T> !MyTrait for *mut T {}
|
||||
|
@ -30,7 +32,4 @@ fn main() {
|
|||
|
||||
is_mytrait::<MyS2>();
|
||||
//~^ ERROR the trait `MyTrait` is not implemented for the type `MyS2`
|
||||
|
||||
is_mytrait::<Vec<MyS3>>();
|
||||
//~^ ERROR the trait `MyTrait` is not implemented for the type `*mut MyS3`
|
||||
}
|
||||
|
|
|
@ -10,11 +10,13 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait MyTrait {}
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait MyTrait: MarkerTrait {}
|
||||
|
||||
impl MyTrait for .. {}
|
||||
|
||||
unsafe trait MyUnsafeTrait {}
|
||||
unsafe trait MyUnsafeTrait: MarkerTrait {}
|
||||
|
||||
unsafe impl MyUnsafeTrait for .. {}
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait NotImplemented { }
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait NotImplemented: MarkerTrait { }
|
||||
|
||||
trait MyTrait : NotImplemented {}
|
||||
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait NotImplemented { }
|
||||
use std::marker::MarkerTrait;
|
||||
|
||||
trait MyTrait
|
||||
trait NotImplemented: MarkerTrait { }
|
||||
|
||||
trait MyTrait: MarkerTrait
|
||||
where Option<Self> : NotImplemented
|
||||
{}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue