use rustc_data_structures::intern::Interned;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
+use rustc_hir::LangItem;
use rustc_index::vec::Idx;
use rustc_macros::HashStable;
use rustc_span::symbol::{kw, sym, Symbol};
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
}
ExistentialPredicate::AutoTrait(did) => {
- let trait_ref = self.rebind(ty::TraitRef {
- def_id: did,
- substs: tcx.mk_substs_trait(self_ty, &[]),
- });
+ let trait_ref = self.rebind(tcx.mk_trait_ref(did, [self_ty]));
trait_ref.without_const().to_predicate(tcx)
}
}
TraitRef { def_id, substs }
}
+ pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
+ tcx.mk_trait_ref(
+ self.def_id,
+ [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
+ )
+ }
+
/// 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>> {
pub fn def_id(&self) -> DefId {
self.skip_binder().def_id
}
-
- pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
- self.map_bound(|trait_ref| ty::TraitPredicate {
- trait_ref,
- constness: ty::BoundConstness::NotConst,
- polarity: ty::ImplPolarity::Positive,
- })
- }
-
- /// Same as [`PolyTraitRef::to_poly_trait_predicate`] but sets a negative polarity instead.
- pub fn to_poly_trait_predicate_negative_polarity(&self) -> ty::PolyTraitPredicate<'tcx> {
- self.map_bound(|trait_ref| ty::TraitPredicate {
- trait_ref,
- constness: ty::BoundConstness::NotConst,
- polarity: ty::ImplPolarity::Negative,
- })
- }
}
impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {
// otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars());
- ty::TraitRef { def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs) }
+ tcx.mk_trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
}
}
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
ty::Dynamic(..) => {
- let dyn_metadata = tcx.lang_items().dyn_metadata().unwrap();
+ let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
(tcx.bound_type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
},