Skip to content

Commit

Permalink
check supertraits
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Feb 22, 2015
1 parent f7a75e0 commit 64d33d8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
25 changes: 21 additions & 4 deletions src/librustc/middle/traits/select.rs
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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>>
{
Expand All @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/typeck-default-trait-impl-supertrait.rs
Expand Up @@ -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`
}
Expand Up @@ -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 test() {
bar::<Option<i32>>();
//~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option<i32>`
}

fn main() {
foo::<i32>(); //~ ERROR not implemented for the type `i32`
bar::<Option<i32>>(); //~ ERROR not implemented for the type `Option<i32>`
foo::<i32>();
//~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option<i32>`
}

0 comments on commit 64d33d8

Please sign in to comment.