Replace tcx.mk_trait_ref
with ty::TraitRef::new
This commit is contained in:
parent
2d8c905e15
commit
46b01abbcd
41 changed files with 193 additions and 125 deletions
|
@ -169,8 +169,11 @@ pub trait Printer<'tcx>: Sized {
|
|||
self.path_append(
|
||||
|cx: Self| {
|
||||
if trait_qualify_parent {
|
||||
let trait_ref =
|
||||
cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied());
|
||||
let trait_ref = ty::TraitRef::new(
|
||||
cx.tcx(),
|
||||
parent_def_id,
|
||||
parent_substs.iter().copied(),
|
||||
);
|
||||
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
|
||||
} else {
|
||||
cx.print_def_path(parent_def_id, parent_substs)
|
||||
|
|
|
@ -315,7 +315,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
|
|||
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
|
||||
} else {
|
||||
let substs = relate_substs(relation, a.substs, b.substs)?;
|
||||
Ok(relation.tcx().mk_trait_ref(a.def_id, substs))
|
||||
Ok(ty::TraitRef::new(relation.tcx(), a.def_id, substs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -728,13 +728,13 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
|
|||
ExistentialPredicate::AutoTrait(did) => {
|
||||
let generics = tcx.generics_of(did);
|
||||
let trait_ref = if generics.params.len() == 1 {
|
||||
tcx.mk_trait_ref(did, [self_ty])
|
||||
ty::TraitRef::new(tcx, did, [self_ty])
|
||||
} else {
|
||||
// If this is an ill-formed auto trait, then synthesize
|
||||
// new error substs for the missing generics.
|
||||
let err_substs =
|
||||
ty::InternalSubsts::extend_with_error(tcx, did, &[self_ty.into()]);
|
||||
tcx.mk_trait_ref(did, err_substs)
|
||||
ty::TraitRef::new(tcx, did, err_substs)
|
||||
};
|
||||
self.rebind(trait_ref).without_const().to_predicate(tcx)
|
||||
}
|
||||
|
@ -850,17 +850,22 @@ impl<'tcx> TraitRef<'tcx> {
|
|||
substs: SubstsRef<'tcx>,
|
||||
) -> ty::TraitRef<'tcx> {
|
||||
let defs = tcx.generics_of(trait_id);
|
||||
tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
|
||||
ty::TraitRef::new(tcx, trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
|
||||
}
|
||||
|
||||
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
|
||||
/// are the parameters defined on trait.
|
||||
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
|
||||
ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
|
||||
ty::Binder::dummy(ty::TraitRef::new(
|
||||
tcx,
|
||||
def_id,
|
||||
InternalSubsts::identity_for_item(tcx, def_id),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||
tcx.mk_trait_ref(
|
||||
ty::TraitRef::new(
|
||||
tcx,
|
||||
self.def_id,
|
||||
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
|
||||
)
|
||||
|
@ -926,7 +931,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
|
|||
// otherwise the escaping vars would be captured by the binder
|
||||
// debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||
|
||||
tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
|
||||
ty::TraitRef::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1245,7 +1250,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
let trait_def_id = self.trait_def_id(tcx);
|
||||
let trait_generics = tcx.generics_of(trait_def_id);
|
||||
(
|
||||
tcx.mk_trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
|
||||
ty::TraitRef::new(tcx, trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
|
||||
&self.substs[trait_generics.count()..],
|
||||
)
|
||||
}
|
||||
|
@ -1259,7 +1264,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
/// as well.
|
||||
pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
|
||||
let def_id = self.trait_def_id(tcx);
|
||||
tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
|
||||
ty::TraitRef::new(tcx, def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
|
||||
}
|
||||
|
||||
pub fn self_ty(self) -> Ty<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue