1
Fork 0

Remove awful hack concerning Trait impl Trait in method resolution code that I've been longing to remove for quite some time.

This commit is contained in:
Niko Matsakis 2015-02-09 10:44:17 -05:00
parent 8f5d225933
commit fe512dacc8
3 changed files with 9 additions and 21 deletions

View file

@ -404,26 +404,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
all_substs.repr(self.tcx()));
// Instantiate the bounds on the method with the
// type/early-bound-regions substitutions performed. The only
// late-bound-regions that can appear in bounds are from the
// impl, and those were already instantiated above.
//
// FIXME(DST). Super hack. For a method on a trait object
// `Trait`, the generic signature requires that
// `Self:Trait`. Since, for an object, we bind `Self` to the
// type `Trait`, this leads to an obligation
// `Trait:Trait`. Until such time we DST is fully implemented,
// that obligation is not necessarily satisfied. (In the
// future, it would be.) But we know that the true `Self` DOES implement
// the trait. So we just delete this requirement. Hack hack hack.
let mut method_predicates = pick.method_ty.predicates.instantiate(self.tcx(), &all_substs);
match pick.kind {
probe::ObjectPick(..) => {
assert_eq!(method_predicates.predicates.get_slice(subst::SelfSpace).len(), 1);
method_predicates.predicates.pop(subst::SelfSpace);
}
_ => { }
}
// type/early-bound-regions substitutions performed. There can
// be no late-bound regions appearing here.
let method_predicates = pick.method_ty.predicates.instantiate(self.tcx(), &all_substs);
let method_predicates = self.fcx.normalize_associated_types_in(self.span,
&method_predicates);

View file

@ -17,7 +17,11 @@ impl Foo for Thing {
fn foo<T>(&self, _: &T) {}
}
#[inline(never)] fn foo(b: &Bar) { b.foo(&0_usize) }
#[inline(never)]
fn foo(b: &Bar) {
b.foo(&0usize)
//~^ ERROR the trait `Foo` is not implemented for the type `Bar`
}
fn main() {
let mut thing = Thing;

View file

@ -18,4 +18,5 @@ fn main() {
10.dup::<i32>(); //~ ERROR does not take type parameters
10.blah::<i32, i32>(); //~ ERROR incorrect number of type parameters
(box 10 as Box<bar>).dup(); //~ ERROR cannot convert to a trait object
//~^ ERROR the trait `bar` is not implemented for the type `bar`
}