diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 6b4f08d9f93..c1fa84dcb25 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1132,8 +1132,16 @@ impl<'tcx> ProjectionTy<'tcx> { /// For example, if this is a projection of `::Item`, /// then this function would return a `T: Iterator` trait reference. pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { + // FIXME: This method probably shouldn't exist at all, since it's not + // clear what this method really intends to do. Be careful when + // using this method since the resulting TraitRef additionally + // contains the substs for the assoc_item, which strictly speaking + // is not correct let def_id = tcx.associated_item(self.item_def_id).container.id(); - ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) } + // Include substitutions for generic arguments of associated types + let assoc_item = tcx.associated_item(self.item_def_id); + let substs_assoc_item = self.substs.truncate_to(tcx, tcx.generics_of(assoc_item.def_id)); + ty::TraitRef { def_id, substs: substs_assoc_item } } pub fn self_ty(&self) -> Ty<'tcx> {