diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index c5ef55154de00..ac782729bc3f7 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -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>, SelectionError<'tcx>> { @@ -1892,6 +1892,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { -> VtableDefaultImplData> { 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::>(); - 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 { diff --git a/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs b/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs index cb3f50c8d8702..c9bfdff6c0e49 100644 --- a/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs +++ b/src/test/compile-fail/typeck-default-trait-impl-supertrait.rs @@ -24,6 +24,6 @@ fn foo() { bar::() } fn bar() { } fn main() { - foo::(); //~ ERROR XXX - bar::(); //~ ERROR XXX + foo::(); //~ ERROR the trait `NotImplemented` is not implemented for the type `i32` + bar::(); //~ ERROR the trait `NotImplemented` is not implemented for the type `i64` } diff --git a/src/test/compile-fail/typeck-default-trait-impl-trait-where-clause.rs b/src/test/compile-fail/typeck-default-trait-impl-trait-where-clause.rs index 85bca7f248cd4..06f365211572b 100644 --- a/src/test/compile-fail/typeck-default-trait-impl-trait-where-clause.rs +++ b/src/test/compile-fail/typeck-default-trait-impl-trait-where-clause.rs @@ -25,14 +25,19 @@ impl MyTrait for .. {} fn foo() { bar::>() - //~^ ERROR not implemented for the type `Option` - // - // This should probably typecheck. This is #20671. + //~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option` + // + // This should probably typecheck. This is #20671. } fn bar() { } +fn test() { + bar::>(); + //~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option` +} + fn main() { - foo::(); //~ ERROR not implemented for the type `i32` - bar::>(); //~ ERROR not implemented for the type `Option` + foo::(); + //~^ ERROR the trait `NotImplemented` is not implemented for the type `core::option::Option` }