Skip to content

Commit fe512da

Browse files
committed
Remove awful hack concerning Trait impl Trait in method resolution code that I've been longing to remove for quite some time.
1 parent 8f5d225 commit fe512da

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/librustc_typeck/check/method/confirm.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -404,26 +404,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
404404
all_substs.repr(self.tcx()));
405405

406406
// Instantiate the bounds on the method with the
407-
// type/early-bound-regions substitutions performed. The only
408-
// late-bound-regions that can appear in bounds are from the
409-
// impl, and those were already instantiated above.
410-
//
411-
// FIXME(DST). Super hack. For a method on a trait object
412-
// `Trait`, the generic signature requires that
413-
// `Self:Trait`. Since, for an object, we bind `Self` to the
414-
// type `Trait`, this leads to an obligation
415-
// `Trait:Trait`. Until such time we DST is fully implemented,
416-
// that obligation is not necessarily satisfied. (In the
417-
// future, it would be.) But we know that the true `Self` DOES implement
418-
// the trait. So we just delete this requirement. Hack hack hack.
419-
let mut method_predicates = pick.method_ty.predicates.instantiate(self.tcx(), &all_substs);
420-
match pick.kind {
421-
probe::ObjectPick(..) => {
422-
assert_eq!(method_predicates.predicates.get_slice(subst::SelfSpace).len(), 1);
423-
method_predicates.predicates.pop(subst::SelfSpace);
424-
}
425-
_ => { }
426-
}
407+
// type/early-bound-regions substitutions performed. There can
408+
// be no late-bound regions appearing here.
409+
let method_predicates = pick.method_ty.predicates.instantiate(self.tcx(), &all_substs);
427410
let method_predicates = self.fcx.normalize_associated_types_in(self.span,
428411
&method_predicates);
429412

src/test/compile-fail/issue-18959.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ impl Foo for Thing {
1717
fn foo<T>(&self, _: &T) {}
1818
}
1919

20-
#[inline(never)] fn foo(b: &Bar) { b.foo(&0_usize) }
20+
#[inline(never)]
21+
fn foo(b: &Bar) {
22+
b.foo(&0usize)
23+
//~^ ERROR the trait `Foo` is not implemented for the type `Bar`
24+
}
2125

2226
fn main() {
2327
let mut thing = Thing;

src/test/compile-fail/trait-test-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ fn main() {
1818
10.dup::<i32>(); //~ ERROR does not take type parameters
1919
10.blah::<i32, i32>(); //~ ERROR incorrect number of type parameters
2020
(box 10 as Box<bar>).dup(); //~ ERROR cannot convert to a trait object
21+
//~^ ERROR the trait `bar` is not implemented for the type `bar`
2122
}

0 commit comments

Comments
 (0)