Skip to content

Commit 6a68966

Browse files
committed
use generic arguments of associated item in trait_ref method
1 parent da2cf9b commit 6a68966

File tree

1 file changed

+9
-1
lines changed
  • compiler/rustc_middle/src/ty

1 file changed

+9
-1
lines changed

compiler/rustc_middle/src/ty/sty.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,16 @@ impl<'tcx> ProjectionTy<'tcx> {
11321132
/// For example, if this is a projection of `<T as Iterator>::Item`,
11331133
/// then this function would return a `T: Iterator` trait reference.
11341134
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
1135+
// FIXME: This method probably shouldn't exist at all, since it's not
1136+
// clear what this method really intends to do. Be careful when
1137+
// using this method since the resulting TraitRef additionally
1138+
// contains the substs for the assoc_item, which strictly speaking
1139+
// is not correct
11351140
let def_id = tcx.associated_item(self.item_def_id).container.id();
1136-
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) }
1141+
// Include substitutions for generic arguments of associated types
1142+
let assoc_item = tcx.associated_item(self.item_def_id);
1143+
let substs_assoc_item = self.substs.truncate_to(tcx, tcx.generics_of(assoc_item.def_id));
1144+
ty::TraitRef { def_id, substs: substs_assoc_item }
11371145
}
11381146

11391147
pub fn self_ty(&self) -> Ty<'tcx> {

0 commit comments

Comments
 (0)