check supertraits

This commit is contained in:
Flavio Percoco 2015-02-18 23:31:03 +01:00
parent f7a75e0341
commit 64d33d892a
3 changed files with 34 additions and 12 deletions

View file

@ -1423,7 +1423,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
ty::ty_rptr(_, ty::mt { ty: referent_ty, mutbl }) => {
ty::ty_rptr(_, ty::mt { ty: _, mutbl }) => {
// &mut T or &T
match bound {
ty::BoundCopy => {
@ -1871,8 +1871,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
fn confirm_default_impl_candidate(&mut self,
obligation: &TraitObligation<'tcx>,
impl_def_id: ast::DefId)
obligation: &TraitObligation<'tcx>,
impl_def_id: ast::DefId)
-> Result<VtableDefaultImplData<PredicateObligation<'tcx>>,
SelectionError<'tcx>>
{
@ -1892,6 +1892,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
-> VtableDefaultImplData<PredicateObligation<'tcx>>
{
let derived_cause = self.derived_cause(obligation, ImplDerivedObligation);
let obligations = nested.iter().map(|&nested_ty| {
// the obligation might be higher-ranked, e.g. for<'a> &'a
// int : Copy. In that case, we will wind up with
@ -1918,11 +1919,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
})
}).collect::<Result<_, _>>();
let obligations = match obligations {
let mut obligations = match obligations {
Ok(o) => o,
Err(ErrorReported) => Vec::new()
};
let _: Result<(),()> = self.infcx.try(|snapshot| {
let (_, skol_map) =
self.infcx().skolemize_late_bound_regions(&obligation.predicate, snapshot);
let substs = obligation.predicate.to_poly_trait_ref().substs();
let trait_obligations = self.impl_obligations(obligation.cause.clone(),
obligation.recursion_depth + 1,
trait_def_id,
substs,
skol_map,
snapshot);
obligations.push_all(trait_obligations.as_slice());
Ok(())
});
debug!("vtable_default_impl_data: obligations={}", obligations.repr(self.tcx()));
VtableDefaultImplData {

View file

@ -24,6 +24,6 @@ fn foo<T:MyTrait>() { bar::<T>() }
fn bar<T:NotImplemented>() { }
fn main() {
foo::<i32>(); //~ ERROR XXX
bar::<i32>(); //~ ERROR XXX
foo::<i32>(); //~ ERROR the trait `NotImplemented` is not implemented for the type `i32`
bar::<i64>(); //~ ERROR the trait `NotImplemented` is not implemented for the type `i64`
}

View file

@ -25,14 +25,19 @@ impl MyTrait for .. {}
fn foo<T:MyTrait>() {
bar::<Option<T>>()
//~^ ERROR not implemented for the type `Option<T>`
//
// This should probably typecheck. This is #20671.
//~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option<T>`
//
// This should probably typecheck. This is #20671.
}
fn bar<T:NotImplemented>() { }
fn main() {
foo::<i32>(); //~ ERROR not implemented for the type `i32`
bar::<Option<i32>>(); //~ ERROR not implemented for the type `Option<i32>`
fn test() {
bar::<Option<i32>>();
//~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option<i32>`
}
fn main() {
foo::<i32>();
//~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option<i32>`
}