From e21f6c8678b7e3178de15a04ea05db337b733953 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 30 Jan 2023 10:28:19 +0000 Subject: [PATCH 1/8] Introduce `tcx.mk()` --- compiler/rustc_middle/src/ty/context.rs | 3 + compiler/rustc_middle/src/ty/context/mk.rs | 751 +++++++++++++++++++++ 2 files changed, 754 insertions(+) create mode 100644 compiler/rustc_middle/src/ty/context/mk.rs diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d5ba0785fa6d4..0ec487e1f50c5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2,6 +2,7 @@ #![allow(rustc::usage_of_ty_tykind)] +pub mod mk; pub mod tls; use crate::arena::Arena; @@ -1561,6 +1562,8 @@ macro_rules! direct_interners { // Functions with a `mk_` prefix are intended for use outside this file and // crate. Functions with an `intern_` prefix are intended for use within this // file only, and have a corresponding `mk_` function. +// +// FIXME(waffle): move `mk_region`, `mk_const_internal` to `.mk()` direct_interners! { region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>, const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>, diff --git a/compiler/rustc_middle/src/ty/context/mk.rs b/compiler/rustc_middle/src/ty/context/mk.rs new file mode 100644 index 0000000000000..79a306ee91dad --- /dev/null +++ b/compiler/rustc_middle/src/ty/context/mk.rs @@ -0,0 +1,751 @@ +#![allow(rustc::usage_of_ty_tykind)] + +use std::cmp::Ordering; +use std::iter; + +use rustc_error_messages::MultiSpan; +use rustc_errors::ErrorGuaranteed; +use rustc_hir as hir; +use rustc_hir::{def_id::DefId, LangItem}; +use rustc_index::vec::IndexVec; +use rustc_span::{Symbol, DUMMY_SP}; +use rustc_target::abi::{Layout, LayoutS, ReprOptions, VariantIdx}; +use rustc_target::spec::abi::{self}; +use rustc_type_ir::CollectAndApply; +use rustc_type_ir::{sty::TyKind::*, DynKind, FloatVid, InferTy::*, IntVid, TyVid}; + +use crate::infer::canonical::CanonicalVarInfo; +use crate::mir::interpret::{Allocation, ConstAllocation}; +use crate::mir::ProjectionKind; +use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData}; +use crate::ty::{AdtDefData, AdtKind, InternalSubsts}; +use crate::{ + mir::{Field, Local, Place, PlaceElem}, + ty::{ + self, AdtDef, Binder, Const, FloatTy, GenericArg, GenericParamDefKind, IntTy, List, + ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, + SubstsRef, Ty, TyCtxt, TyKind, TypeAndMut, UintTy, + }, +}; + +/// This structure provides convenience functions that make stuff. +/// +/// This replaces `tcx.mk_stuff()` with `tcx.mk().stuff()`, making documentation a bit more bearable. +#[derive(Copy, Clone)] +pub struct MkCtxt<'tcx> { + tcx: TyCtxt<'tcx>, +} + +impl<'tcx> TyCtxt<'tcx> { + /// Returns the "make context" with some extension methods. + /// + /// ## Examples + /// + /// ```rust,no_run + /// # rustc_middle::ty::TyCtxt; + /// let tcx: TyCtxt = todo!(); + /// let unit_ty = tcx.mk().unit(); + /// ``` + #[inline] + pub fn mk(self) -> MkCtxt<'tcx> { + MkCtxt { tcx: self } + } +} + +impl<'tcx> MkCtxt<'tcx> { + pub fn adt_def( + self, + did: DefId, + kind: AdtKind, + variants: IndexVec, + repr: ReprOptions, + ) -> ty::AdtDef<'tcx> { + self.adt_def_from_data(ty::AdtDefData::new(self.tcx, did, kind, variants, repr)) + } + + /// Constructs a `RegionKind::ReError` lifetime. + pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> { + self.tcx.intern_region(ty::ReError(reported)) + } + + /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it + /// gets used. + #[track_caller] + pub fn re_error_misc(self) -> Region<'tcx> { + self.re_error_with_message( + DUMMY_SP, + "RegionKind::ReError constructed but no error reported", + ) + } + + /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given + /// `msg` to ensure it gets used. + #[track_caller] + pub fn re_error_with_message>(self, span: S, msg: &str) -> Region<'tcx> { + let reported = self.tcx.sess.delay_span_bug(span, msg); + self.re_error(reported) + } + + // Avoid this in favour of more specific `mk().*` methods, where possible. + #[allow(rustc::usage_of_ty_tykind)] + #[inline] + pub fn ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> { + self.tcx.interners.intern_ty( + st, + self.tcx.sess, + // This is only used to create a stable hashing context. + &self.tcx.untracked, + ) + } + + #[inline] + pub fn predicate(self, binder: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> { + self.tcx.interners.intern_predicate( + binder, + self.tcx.sess, + // This is only used to create a stable hashing context. + &self.tcx.untracked, + ) + } + + pub fn mach_int(self, tm: IntTy) -> Ty<'tcx> { + match tm { + IntTy::Isize => self.tcx.types.isize, + IntTy::I8 => self.tcx.types.i8, + IntTy::I16 => self.tcx.types.i16, + IntTy::I32 => self.tcx.types.i32, + IntTy::I64 => self.tcx.types.i64, + IntTy::I128 => self.tcx.types.i128, + } + } + + pub fn mach_uint(self, tm: UintTy) -> Ty<'tcx> { + match tm { + UintTy::Usize => self.tcx.types.usize, + UintTy::U8 => self.tcx.types.u8, + UintTy::U16 => self.tcx.types.u16, + UintTy::U32 => self.tcx.types.u32, + UintTy::U64 => self.tcx.types.u64, + UintTy::U128 => self.tcx.types.u128, + } + } + + pub fn mach_float(self, tm: FloatTy) -> Ty<'tcx> { + match tm { + FloatTy::F32 => self.tcx.types.f32, + FloatTy::F64 => self.tcx.types.f64, + } + } + + #[inline] + pub fn static_str(self) -> Ty<'tcx> { + self.imm_ref(self.tcx.lifetimes.re_static, self.tcx.types.str_) + } + + #[inline] + pub fn adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> { + // Take a copy of substs so that we own the vectors inside. + self.ty_from_kind(Adt(def, substs)) + } + + #[inline] + pub fn foreign(self, def_id: DefId) -> Ty<'tcx> { + self.ty_from_kind(Foreign(def_id)) + } + + fn generic_adt(self, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> { + let adt_def = self.tcx.adt_def(wrapper_def_id); + let substs = + InternalSubsts::for_item(self.tcx, wrapper_def_id, |param, substs| match param.kind { + GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(), + GenericParamDefKind::Type { has_default, .. } => { + if param.index == 0 { + ty_param.into() + } else { + assert!(has_default); + self.tcx.type_of(param.def_id).subst(self.tcx, substs).into() + } + } + }); + + self.ty_from_kind(Adt(adt_def, substs)) + } + + #[inline] + pub fn box_(self, ty: Ty<'tcx>) -> Ty<'tcx> { + let def_id = self.tcx.require_lang_item(LangItem::OwnedBox, None); + self.generic_adt(def_id, ty) + } + + #[inline] + pub fn lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option> { + let def_id = self.tcx.lang_items().get(item)?; + Some(self.generic_adt(def_id, ty)) + } + + #[inline] + pub fn diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option> { + let def_id = self.tcx.get_diagnostic_item(name)?; + Some(self.generic_adt(def_id, ty)) + } + + #[inline] + pub fn maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> { + let def_id = self.tcx.require_lang_item(LangItem::MaybeUninit, None); + self.generic_adt(def_id, ty) + } + + #[inline] + pub fn ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(RawPtr(tm)) + } + + #[inline] + pub fn ref_(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Ref(r, tm.ty, tm.mutbl)) + } + + #[inline] + pub fn mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + self.ref_(r, TypeAndMut { ty, mutbl: hir::Mutability::Mut }) + } + + #[inline] + pub fn imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { + self.ref_(r, TypeAndMut { ty, mutbl: hir::Mutability::Not }) + } + + #[inline] + pub fn mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { + self.ptr(TypeAndMut { ty, mutbl: hir::Mutability::Mut }) + } + + #[inline] + pub fn imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { + self.ptr(TypeAndMut { ty, mutbl: hir::Mutability::Not }) + } + + #[inline] + pub fn array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { + self.ty_from_kind(Array(ty, ty::Const::from_target_usize(self.tcx, n))) + } + + #[inline] + pub fn array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Array(ty, ct)) + } + + #[inline] + pub fn slice(self, ty: Ty<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Slice(ty)) + } + + pub fn tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { + if ts.is_empty() { + self.tcx.types.unit + } else { + self.ty_from_kind(Tuple(self.type_list(&ts))) + } + } + + pub fn tup_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, Ty<'tcx>>, + { + T::collect_and_apply(iter, |ts| self.tup(ts)) + } + + #[inline] + pub fn unit(self) -> Ty<'tcx> { + self.tcx.types.unit + } + + #[inline] + pub fn diverging_default(self) -> Ty<'tcx> { + if self.tcx.features().never_type_fallback { + self.tcx.types.never + } else { + self.tcx.types.unit + } + } + + #[inline] + pub fn fn_def( + self, + def_id: DefId, + substs: impl IntoIterator>>, + ) -> Ty<'tcx> { + let substs = self.tcx.check_and_mk_substs(def_id, substs); + self.ty_from_kind(FnDef(def_id, substs)) + } + + #[inline] + pub fn fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(FnPtr(fty)) + } + + #[inline] + pub fn dynamic( + self, + obj: &'tcx List>, + reg: ty::Region<'tcx>, + repr: DynKind, + ) -> Ty<'tcx> { + self.ty_from_kind(Dynamic(obj, reg, repr)) + } + + #[inline] + pub fn projection( + self, + item_def_id: DefId, + substs: impl IntoIterator>>, + ) -> Ty<'tcx> { + self.alias(ty::Projection, self.alias_ty(item_def_id, substs)) + } + + #[inline] + pub fn closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Closure(closure_id, closure_substs)) + } + + #[inline] + pub fn generator( + self, + id: DefId, + generator_substs: SubstsRef<'tcx>, + movability: hir::Movability, + ) -> Ty<'tcx> { + self.ty_from_kind(Generator(id, generator_substs, movability)) + } + + #[inline] + pub fn generator_witness(self, types: ty::Binder<'tcx, &'tcx List>>) -> Ty<'tcx> { + self.ty_from_kind(GeneratorWitness(types)) + } + + /// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes. + pub fn task_context(self) -> Ty<'tcx> { + let context_did = self.tcx.require_lang_item(LangItem::Context, None); + let context_adt_ref = self.tcx.adt_def(context_did); + let context_substs = self.substs(&[self.tcx.lifetimes.re_erased.into()]); + let context_ty = self.adt(context_adt_ref, context_substs); + self.mut_ref(self.tcx.lifetimes.re_erased, context_ty) + } + + #[inline] + pub fn generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(GeneratorWitnessMIR(id, substs)) + } + + #[inline] + pub fn const_(self, kind: impl Into>, ty: Ty<'tcx>) -> Const<'tcx> { + self.tcx.intern_const(ty::ConstData { kind: kind.into(), ty }) + } + + #[inline] + pub fn ty_var(self, v: TyVid) -> Ty<'tcx> { + // Use a pre-interned one when possible. + self.tcx + .types + .ty_vars + .get(v.as_usize()) + .copied() + .unwrap_or_else(|| self.ty_from_kind(Infer(TyVar(v)))) + } + + #[inline] + pub fn int_var(self, v: IntVid) -> Ty<'tcx> { + self.ty_from_kind(Infer(IntVar(v))) + } + + #[inline] + pub fn float_var(self, v: FloatVid) -> Ty<'tcx> { + self.ty_from_kind(Infer(FloatVar(v))) + } + + #[inline] + pub fn fresh_ty(self, n: u32) -> Ty<'tcx> { + // Use a pre-interned one when possible. + self.tcx + .types + .fresh_tys + .get(n as usize) + .copied() + .unwrap_or_else(|| self.ty_from_kind(Infer(ty::FreshTy(n)))) + } + + #[inline] + pub fn fresh_int_ty(self, n: u32) -> Ty<'tcx> { + // Use a pre-interned one when possible. + self.tcx + .types + .fresh_int_tys + .get(n as usize) + .copied() + .unwrap_or_else(|| self.ty_from_kind(Infer(ty::FreshIntTy(n)))) + } + + #[inline] + pub fn fresh_float_ty(self, n: u32) -> Ty<'tcx> { + // Use a pre-interned one when possible. + self.tcx + .types + .fresh_float_tys + .get(n as usize) + .copied() + .unwrap_or_else(|| self.ty_from_kind(Infer(ty::FreshFloatTy(n)))) + } + + #[inline] + pub fn ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> { + self.ty_from_kind(Param(ParamTy { index, name })) + } + + pub fn param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { + match param.kind { + GenericParamDefKind::Lifetime => { + self.re_early_bound(param.to_early_bound_region_data()).into() + } + GenericParamDefKind::Type { .. } => self.ty_param(param.index, param.name).into(), + GenericParamDefKind::Const { .. } => self + .const_( + ParamConst { index: param.index, name: param.name }, + self.tcx + .type_of(param.def_id) + .no_bound_vars() + .expect("const parameter types cannot be generic"), + ) + .into(), + } + } + + #[inline] + pub fn bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> { + self.ty_from_kind(Bound(index, bound_ty)) + } + + #[inline] + pub fn placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> { + self.ty_from_kind(Placeholder(placeholder)) + } + + #[inline] + pub fn alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Alias(kind, alias_ty)) + } + + #[inline] + pub fn opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { + self.ty_from_kind(Alias(ty::Opaque, self.alias_ty(def_id, substs))) + } + + #[inline] + pub fn re_early_bound(self, early_bound_region: ty::EarlyBoundRegion) -> Region<'tcx> { + self.tcx.intern_region(ty::ReEarlyBound(early_bound_region)) + } + + #[inline] + pub fn re_late_bound( + self, + debruijn: ty::DebruijnIndex, + bound_region: ty::BoundRegion, + ) -> Region<'tcx> { + // Use a pre-interned one when possible. + if let ty::BoundRegion { var, kind: ty::BrAnon(v, None) } = bound_region + && var.as_u32() == v + && let Some(inner) = self.tcx.lifetimes.re_late_bounds.get(debruijn.as_usize()) + && let Some(re) = inner.get(v as usize).copied() + { + re + } else { + self.tcx.intern_region(ty::ReLateBound(debruijn, bound_region)) + } + } + + #[inline] + pub fn re_free(self, scope: DefId, bound_region: ty::BoundRegionKind) -> Region<'tcx> { + self.tcx.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region })) + } + + #[inline] + pub fn re_var(self, v: ty::RegionVid) -> Region<'tcx> { + // Use a pre-interned one when possible. + self.tcx + .lifetimes + .re_vars + .get(v.as_usize()) + .copied() + .unwrap_or_else(|| self.tcx.intern_region(ty::ReVar(v))) + } + + #[inline] + pub fn re_placeholder(self, placeholder: ty::PlaceholderRegion) -> Region<'tcx> { + self.tcx.intern_region(ty::RePlaceholder(placeholder)) + } + + // Avoid this in favour of more specific `re_*` methods, where possible, + // to avoid the cost of the `match`. + pub fn region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> { + match kind { + ty::ReEarlyBound(region) => self.re_early_bound(region), + ty::ReLateBound(debruijn, region) => self.re_late_bound(debruijn, region), + ty::ReFree(ty::FreeRegion { scope, bound_region }) => self.re_free(scope, bound_region), + ty::ReStatic => self.tcx.lifetimes.re_static, + ty::ReVar(vid) => self.re_var(vid), + ty::RePlaceholder(region) => self.re_placeholder(region), + ty::ReErased => self.tcx.lifetimes.re_erased, + ty::ReError(reported) => self.re_error(reported), + } + } + + pub fn place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { + self.place_elem(place, PlaceElem::Field(f, ty)) + } + + pub fn place_deref(self, place: Place<'tcx>) -> Place<'tcx> { + self.place_elem(place, PlaceElem::Deref) + } + + pub fn place_downcast( + self, + place: Place<'tcx>, + adt_def: AdtDef<'tcx>, + variant_index: VariantIdx, + ) -> Place<'tcx> { + self.place_elem( + place, + PlaceElem::Downcast(Some(adt_def.variant(variant_index).name), variant_index), + ) + } + + pub fn place_downcast_unnamed( + self, + place: Place<'tcx>, + variant_index: VariantIdx, + ) -> Place<'tcx> { + self.place_elem(place, PlaceElem::Downcast(None, variant_index)) + } + + pub fn place_index(self, place: Place<'tcx>, index: Local) -> Place<'tcx> { + self.place_elem(place, PlaceElem::Index(index)) + } + + /// This method copies `Place`'s projection, add an element and reintern it. Should not be used + /// to build a full `Place` it's just a convenient way to grab a projection and modify it in + /// flight. + pub fn place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> { + let mut projection = place.projection.to_vec(); + projection.push(elem); + + Place { local: place.local, projection: self.place_elems(&projection) } + } + + pub fn poly_existential_predicates( + self, + eps: &[PolyExistentialPredicate<'tcx>], + ) -> &'tcx List> { + assert!(!eps.is_empty()); + assert!( + eps.array_windows() + .all(|[a, b]| a.skip_binder().stable_cmp(self.tcx, &b.skip_binder()) + != Ordering::Greater) + ); + self.tcx.intern_poly_existential_predicates(eps) + } + + pub fn predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List> { + // FIXME consider asking the input slice to be sorted to avoid + // re-interning permutations, in which case that would be asserted + // here. + self.tcx.intern_predicates(preds) + } + + pub fn const_list_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.const_list(xs)) + } + + pub fn type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { + // Actually intern type lists as lists of `GenericArg`s. + // + // Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound + // as explained in `ty_slice_as_generic_arg`. With this, + // we guarantee that even when transmuting between `List>` + // and `List>`, the uniqueness requirement for + // lists is upheld. + let substs = self.substs(ty::subst::ty_slice_as_generic_args(ts)); + substs.try_as_type_list().unwrap() + } + + // Unlike various other `*_from_iter` functions, this one uses `I: + // IntoIterator` instead of `I: Iterator`, and it doesn't have a slice + // variant, because of the need to combine `inputs` and `output`. This + // explains the lack of `_from_iter` suffix. + pub fn fn_sig( + self, + inputs: I, + output: I::Item, + c_variadic: bool, + unsafety: hir::Unsafety, + abi: abi::Abi, + ) -> T::Output + where + I: IntoIterator, + T: CollectAndApply, ty::FnSig<'tcx>>, + { + T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig { + inputs_and_output: self.type_list(xs), + c_variadic, + unsafety, + abi, + }) + } + + pub fn poly_existential_predicates_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply< + PolyExistentialPredicate<'tcx>, + &'tcx List>, + >, + { + T::collect_and_apply(iter, |xs| self.poly_existential_predicates(xs)) + } + + pub fn predicates_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.predicates(xs)) + } + + pub fn type_list_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.type_list(xs)) + } + + pub fn substs_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.substs(xs)) + } + + pub fn canonical_var_infos_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.canonical_var_infos(xs)) + } + + pub fn place_elems_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.place_elems(xs)) + } + + pub fn substs_trait( + self, + self_ty: Ty<'tcx>, + rest: impl IntoIterator>, + ) -> SubstsRef<'tcx> { + self.substs_from_iter(iter::once(self_ty.into()).chain(rest)) + } + + pub fn trait_ref( + self, + trait_def_id: DefId, + substs: impl IntoIterator>>, + ) -> ty::TraitRef<'tcx> { + let substs = self.tcx.check_and_mk_substs(trait_def_id, substs); + ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } + } + + pub fn alias_ty( + self, + def_id: DefId, + substs: impl IntoIterator>>, + ) -> ty::AliasTy<'tcx> { + let substs = self.tcx.check_and_mk_substs(def_id, substs); + ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } + } + + pub fn bound_variable_kinds_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply>, + { + T::collect_and_apply(iter, |xs| self.bound_variable_kinds(xs)) + } + + #[inline] + pub fn const_list(self, v: &[Const<'tcx>]) -> &'tcx List> { + self.tcx.mk_const_list(v) + } + + #[inline] + pub fn substs(self, v: &[GenericArg<'tcx>]) -> &'tcx List> { + self.tcx.mk_substs(v) + } + + #[inline] + pub fn canonical_var_infos( + self, + v: &[CanonicalVarInfo<'tcx>], + ) -> &'tcx List> { + self.tcx.mk_canonical_var_infos(v) + } + + #[inline] + pub fn projs(self, v: &[ProjectionKind]) -> &'tcx List { + self.tcx.mk_projs(v) + } + + #[inline] + pub fn place_elems(self, v: &[PlaceElem<'tcx>]) -> &'tcx List> { + self.tcx.mk_place_elems(v) + } + + #[inline] + pub fn bound_variable_kinds( + self, + v: &[ty::BoundVariableKind], + ) -> &'tcx List { + self.tcx.mk_bound_variable_kinds(v) + } + + #[inline] + pub fn const_alloc(self, v: Allocation) -> ConstAllocation<'tcx> { + self.tcx.mk_const_alloc(v) + } + + #[inline] + pub fn layout(self, v: LayoutS) -> Layout<'tcx> { + self.tcx.mk_layout(v) + } + + #[inline] + pub fn adt_def_from_data(self, v: AdtDefData) -> AdtDef<'tcx> { + self.tcx.mk_adt_def_from_data(v) + } + + #[inline] + pub fn external_constraints( + self, + v: ExternalConstraintsData<'tcx>, + ) -> ExternalConstraints<'tcx> { + self.tcx.mk_external_constraints(v) + } +} From 31c89e052c7f7df3b34c076431ecc0a61cc7e543 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 30 Jan 2023 10:29:11 +0000 Subject: [PATCH 2/8] Deprecate `tcx.mk_*` --- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 83 ++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 45c4a1057d2df..627d07aa1fada 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -23,6 +23,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(deprecated_suggestion)] #![feature(allocator_api)] #![feature(array_windows)] #![feature(assert_matches)] diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 0ec487e1f50c5..a4eb49fb82d47 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -621,6 +621,7 @@ impl<'tcx> TyCtxt<'tcx> { self.arena.alloc(Steal::new(promoted)) } + #[deprecated(suggestion = "mk().adt_def")] pub fn mk_adt_def( self, did: DefId, @@ -744,7 +745,7 @@ impl<'tcx> TyCtxt<'tcx> { } /// Constructs a `RegionKind::ReError` lifetime. - #[track_caller] + #[deprecated(suggestion = "mk().re_error")] pub fn mk_re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> { self.intern_region(ty::ReError(reported)) } @@ -752,6 +753,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it /// gets used. #[track_caller] + #[deprecated(suggestion = "mk().re_error_misc")] pub fn mk_re_error_misc(self) -> Region<'tcx> { self.mk_re_error_with_message( DUMMY_SP, @@ -762,6 +764,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given /// `msg` to ensure it gets used. #[track_caller] + #[deprecated(suggestion = "mk().re_error_with_message")] pub fn mk_re_error_with_message>(self, span: S, msg: &str) -> Region<'tcx> { let reported = self.sess.delay_span_bug(span, msg); self.mk_re_error(reported) @@ -1563,7 +1566,7 @@ macro_rules! direct_interners { // crate. Functions with an `intern_` prefix are intended for use within this // file only, and have a corresponding `mk_` function. // -// FIXME(waffle): move `mk_region`, `mk_const_internal` to `.mk()` +// TODO(waffle): pub mk_* -> intern_* direct_interners! { region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>, const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>, @@ -1593,6 +1596,7 @@ macro_rules! slice_interners { // These functions intern slices. They all have a corresponding // `mk_foo_from_iter` function that interns an iterator. The slice version // should be used when possible, because it's faster. +// TODO: deprecate/make into private `intern_*`/etc all `mk_*` methods here slice_interners!( const_lists: pub mk_const_list(Const<'tcx>), substs: pub mk_substs(GenericArg<'tcx>), @@ -1689,6 +1693,7 @@ impl<'tcx> TyCtxt<'tcx> { // Avoid this in favour of more specific `mk_*` methods, where possible. #[allow(rustc::usage_of_ty_tykind)] #[inline] + #[deprecated(suggestion = "mk().ty_from_kind")] pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> { self.interners.intern_ty( st, @@ -1699,6 +1704,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().predicate")] pub fn mk_predicate(self, binder: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> { self.interners.intern_predicate( binder, @@ -1717,6 +1723,7 @@ impl<'tcx> TyCtxt<'tcx> { if pred.kind() != binder { self.mk_predicate(binder) } else { pred } } + #[deprecated(suggestion = "mk().mach_int")] pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> { match tm { IntTy::Isize => self.types.isize, @@ -1728,6 +1735,7 @@ impl<'tcx> TyCtxt<'tcx> { } } + #[deprecated(suggestion = "mk().mach_uint")] pub fn mk_mach_uint(self, tm: UintTy) -> Ty<'tcx> { match tm { UintTy::Usize => self.types.usize, @@ -1739,6 +1747,7 @@ impl<'tcx> TyCtxt<'tcx> { } } + #[deprecated(suggestion = "mk().mach_float")] pub fn mk_mach_float(self, tm: FloatTy) -> Ty<'tcx> { match tm { FloatTy::F32 => self.types.f32, @@ -1747,17 +1756,20 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().static_str")] pub fn mk_static_str(self) -> Ty<'tcx> { self.mk_imm_ref(self.lifetimes.re_static, self.types.str_) } #[inline] + #[deprecated(suggestion = "mk().adt")] pub fn mk_adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> { // Take a copy of substs so that we own the vectors inside. self.mk_ty_from_kind(Adt(def, substs)) } #[inline] + #[deprecated(suggestion = "mk().foreign")] pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> { self.mk_ty_from_kind(Foreign(def_id)) } @@ -1780,75 +1792,89 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().box_")] pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> { let def_id = self.require_lang_item(LangItem::OwnedBox, None); self.mk_generic_adt(def_id, ty) } #[inline] + #[deprecated(suggestion = "mk().lang_item")] pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option> { let def_id = self.lang_items().get(item)?; Some(self.mk_generic_adt(def_id, ty)) } #[inline] + #[deprecated(suggestion = "mk().diagnostic_item")] pub fn mk_diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option> { let def_id = self.get_diagnostic_item(name)?; Some(self.mk_generic_adt(def_id, ty)) } #[inline] + #[deprecated(suggestion = "mk().maybe_uninit")] pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> { let def_id = self.require_lang_item(LangItem::MaybeUninit, None); self.mk_generic_adt(def_id, ty) } #[inline] + #[deprecated(suggestion = "mk().ptr")] pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(RawPtr(tm)) } #[inline] + #[deprecated(suggestion = "mk().ref_")] pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(Ref(r, tm.ty, tm.mutbl)) } #[inline] + #[deprecated(suggestion = "mk().mut_ref")] pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Mut }) } #[inline] + #[deprecated(suggestion = "mk().imm_ref")] pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Not }) } #[inline] + #[deprecated(suggestion = "mk().mut_ptr")] pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Mut }) } #[inline] + #[deprecated(suggestion = "mk().imm_ptr")] pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Not }) } #[inline] + #[deprecated(suggestion = "mk().array")] pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { self.mk_ty_from_kind(Array(ty, ty::Const::from_target_usize(self, n))) } #[inline] + #[deprecated(suggestion = "mk().array_with_const_len")] pub fn mk_array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(Array(ty, ct)) } #[inline] + #[deprecated(suggestion = "mk().slice")] pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(Slice(ty)) } #[inline] + #[deprecated(suggestion = "mk().tup")] pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { if ts.is_empty() { self.types.unit @@ -1857,6 +1883,7 @@ impl<'tcx> TyCtxt<'tcx> { } } + #[deprecated(suggestion = "mk().tup_from_iter")] pub fn mk_tup_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -1866,16 +1893,19 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().unit")] pub fn mk_unit(self) -> Ty<'tcx> { self.types.unit } #[inline] + #[deprecated(suggestion = "mk().diverging_default")] pub fn mk_diverging_default(self) -> Ty<'tcx> { if self.features().never_type_fallback { self.types.never } else { self.types.unit } } #[inline] + #[deprecated(suggestion = "mk().fn_def")] pub fn mk_fn_def( self, def_id: DefId, @@ -1906,11 +1936,13 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().fn_ptr")] pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(FnPtr(fty)) } #[inline] + #[deprecated(suggestion = "mk().dynamic")] pub fn mk_dynamic( self, obj: &'tcx List>, @@ -1921,6 +1953,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().projection")] pub fn mk_projection( self, item_def_id: DefId, @@ -1930,11 +1963,13 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().closure")] pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(Closure(closure_id, closure_substs)) } #[inline] + #[deprecated(suggestion = "mk().generator")] pub fn mk_generator( self, id: DefId, @@ -1945,11 +1980,13 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().generator_witness")] pub fn mk_generator_witness(self, types: ty::Binder<'tcx, &'tcx List>>) -> Ty<'tcx> { self.mk_ty_from_kind(GeneratorWitness(types)) } /// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes. + #[deprecated(suggestion = "mk().task_context")] pub fn mk_task_context(self) -> Ty<'tcx> { let context_did = self.require_lang_item(LangItem::Context, None); let context_adt_ref = self.adt_def(context_did); @@ -1959,16 +1996,19 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().generator_witness_mir")] pub fn mk_generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(GeneratorWitnessMIR(id, substs)) } #[inline] + #[deprecated(suggestion = "mk().const_")] pub fn mk_const(self, kind: impl Into>, ty: Ty<'tcx>) -> Const<'tcx> { self.intern_const(ty::ConstData { kind: kind.into(), ty }) } #[inline] + #[deprecated(suggestion = "mk().ty_var")] pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> { // Use a pre-interned one when possible. self.types @@ -1979,16 +2019,19 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().int_var")] pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> { self.mk_ty_from_kind(Infer(IntVar(v))) } #[inline] + #[deprecated(suggestion = "mk().float_var")] pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> { self.mk_ty_from_kind(Infer(FloatVar(v))) } #[inline] + #[deprecated(suggestion = "mk().fresh_ty")] pub fn mk_fresh_ty(self, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. self.types @@ -1999,6 +2042,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().fresh_int_ty")] pub fn mk_fresh_int_ty(self, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. self.types @@ -2009,6 +2053,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().fresh_float_ty")] pub fn mk_fresh_float_ty(self, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. self.types @@ -2019,10 +2064,12 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().ty_param")] pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> { self.mk_ty_from_kind(Param(ParamTy { index, name })) } + #[deprecated(suggestion = "mk().param_from_def")] pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { match param.kind { GenericParamDefKind::Lifetime => { @@ -2041,31 +2088,37 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().bound")] pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> { self.mk_ty_from_kind(Bound(index, bound_ty)) } #[inline] + #[deprecated(suggestion = "mk().placeholder")] pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> { self.mk_ty_from_kind(Placeholder(placeholder)) } #[inline] + #[deprecated(suggestion = "mk().alias")] pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { self.mk_ty_from_kind(Alias(kind, alias_ty)) } #[inline] + #[deprecated(suggestion = "mk().opaque")] pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_alias(ty::Opaque, self.mk_alias_ty(def_id, substs)) } #[inline] + #[deprecated(suggestion = "mk().re_early_bound")] pub fn mk_re_early_bound(self, early_bound_region: ty::EarlyBoundRegion) -> Region<'tcx> { self.intern_region(ty::ReEarlyBound(early_bound_region)) } #[inline] + #[deprecated(suggestion = "mk().re_late_bound")] pub fn mk_re_late_bound( self, debruijn: ty::DebruijnIndex, @@ -2084,11 +2137,13 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().re_free")] pub fn mk_re_free(self, scope: DefId, bound_region: ty::BoundRegionKind) -> Region<'tcx> { self.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region })) } #[inline] + #[deprecated(suggestion = "mk().re_var")] pub fn mk_re_var(self, v: ty::RegionVid) -> Region<'tcx> { // Use a pre-interned one when possible. self.lifetimes @@ -2099,12 +2154,14 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] + #[deprecated(suggestion = "mk().re_placeholder")] pub fn mk_re_placeholder(self, placeholder: ty::PlaceholderRegion) -> Region<'tcx> { self.intern_region(ty::RePlaceholder(placeholder)) } // Avoid this in favour of more specific `mk_re_*` methods, where possible, // to avoid the cost of the `match`. + #[deprecated(suggestion = "mk().region_from_kind")] pub fn mk_region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> { match kind { ty::ReEarlyBound(region) => self.mk_re_early_bound(region), @@ -2120,14 +2177,17 @@ impl<'tcx> TyCtxt<'tcx> { } } + #[deprecated(suggestion = "mk().place_field")] pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { self.mk_place_elem(place, PlaceElem::Field(f, ty)) } + #[deprecated(suggestion = "mk().place_deref")] pub fn mk_place_deref(self, place: Place<'tcx>) -> Place<'tcx> { self.mk_place_elem(place, PlaceElem::Deref) } + #[deprecated(suggestion = "mk().place_downcast")] pub fn mk_place_downcast( self, place: Place<'tcx>, @@ -2140,6 +2200,7 @@ impl<'tcx> TyCtxt<'tcx> { ) } + #[deprecated(suggestion = "mk().place_downcast_unnamed")] pub fn mk_place_downcast_unnamed( self, place: Place<'tcx>, @@ -2148,6 +2209,7 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_place_elem(place, PlaceElem::Downcast(None, variant_index)) } + #[deprecated(suggestion = "mk().place_index")] pub fn mk_place_index(self, place: Place<'tcx>, index: Local) -> Place<'tcx> { self.mk_place_elem(place, PlaceElem::Index(index)) } @@ -2155,6 +2217,7 @@ impl<'tcx> TyCtxt<'tcx> { /// This method copies `Place`'s projection, add an element and reintern it. Should not be used /// to build a full `Place` it's just a convenient way to grab a projection and modify it in /// flight. + #[deprecated(suggestion = "mk().place_elem")] pub fn mk_place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> { let mut projection = place.projection.to_vec(); projection.push(elem); @@ -2162,6 +2225,8 @@ impl<'tcx> TyCtxt<'tcx> { Place { local: place.local, projection: self.mk_place_elems(&projection) } } + #[deprecated(suggestion = "mk().poly_existential_predicates")] + pub fn mk_poly_existential_predicates( self, eps: &[PolyExistentialPredicate<'tcx>], @@ -2175,6 +2240,7 @@ impl<'tcx> TyCtxt<'tcx> { self.intern_poly_existential_predicates(eps) } + #[deprecated(suggestion = "mk().predicates")] pub fn mk_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List> { // FIXME consider asking the input slice to be sorted to avoid // re-interning permutations, in which case that would be asserted @@ -2182,6 +2248,7 @@ impl<'tcx> TyCtxt<'tcx> { self.intern_predicates(preds) } + #[deprecated(suggestion = "mk().const_list_from_iter")] pub fn mk_const_list_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2190,6 +2257,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_const_list(xs)) } + #[deprecated(suggestion = "mk().type_list")] pub fn mk_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { // Actually intern type lists as lists of `GenericArg`s. // @@ -2206,6 +2274,7 @@ impl<'tcx> TyCtxt<'tcx> { // IntoIterator` instead of `I: Iterator`, and it doesn't have a slice // variant, because of the need to combine `inputs` and `output`. This // explains the lack of `_from_iter` suffix. + #[deprecated(suggestion = "mk().fn_sig")] pub fn mk_fn_sig( self, inputs: I, @@ -2226,6 +2295,7 @@ impl<'tcx> TyCtxt<'tcx> { }) } + #[deprecated(suggestion = "mk().poly_existential_predicates_from_iter")] pub fn mk_poly_existential_predicates_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2237,6 +2307,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_poly_existential_predicates(xs)) } + #[deprecated(suggestion = "mk().predicates_from_iter")] pub fn mk_predicates_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2245,6 +2316,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_predicates(xs)) } + #[deprecated(suggestion = "mk().type_list_from_iter")] pub fn mk_type_list_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2253,6 +2325,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_type_list(xs)) } + #[deprecated(suggestion = "mk().substs_from_iter")] pub fn mk_substs_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2261,6 +2334,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_substs(xs)) } + #[deprecated(suggestion = "mk().canonical_var_infos_from_iter")] pub fn mk_canonical_var_infos_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2269,6 +2343,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_canonical_var_infos(xs)) } + #[deprecated(suggestion = "mk().place_elems_from_iter")] pub fn mk_place_elems_from_iter(self, iter: I) -> T::Output where I: Iterator, @@ -2277,6 +2352,7 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_place_elems(xs)) } + #[deprecated(suggestion = "mk().substs_trait")] pub fn mk_substs_trait( self, self_ty: Ty<'tcx>, @@ -2285,6 +2361,7 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_substs_from_iter(iter::once(self_ty.into()).chain(rest)) } + #[deprecated(suggestion = "mk().trait_ref")] pub fn mk_trait_ref( self, trait_def_id: DefId, @@ -2294,6 +2371,7 @@ impl<'tcx> TyCtxt<'tcx> { ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } } + #[deprecated(suggestion = "mk().alias_ty")] pub fn mk_alias_ty( self, def_id: DefId, @@ -2303,6 +2381,7 @@ impl<'tcx> TyCtxt<'tcx> { ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } } + #[deprecated(suggestion = "mk().bound_variable_kinds_from_iter")] pub fn mk_bound_variable_kinds_from_iter(self, iter: I) -> T::Output where I: Iterator, From 68c0f9fcf953a803ae4b672edf7ab2027e247a8c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Mar 2023 16:36:27 +0000 Subject: [PATCH 3/8] Use `.mk().*` instead of `.mk_*` part 0 --- .../src/diagnostics/bound_region_errors.rs | 8 +- .../rustc_borrowck/src/diagnostics/mod.rs | 5 +- .../src/diagnostics/region_errors.rs | 2 +- compiler/rustc_borrowck/src/nll.rs | 2 +- .../rustc_borrowck/src/region_infer/mod.rs | 8 +- .../src/region_infer/opaque_types.rs | 4 +- compiler/rustc_borrowck/src/type_check/mod.rs | 11 +- .../rustc_borrowck/src/universal_regions.rs | 24 ++-- compiler/rustc_codegen_llvm/src/abi.rs | 2 +- .../src/coverageinfo/mod.rs | 8 +- .../src/debuginfo/metadata.rs | 13 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/utils.rs | 4 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 12 +- compiler/rustc_codegen_llvm/src/type_of.rs | 4 +- compiler/rustc_codegen_llvm/src/va_arg.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 +- .../rustc_codegen_ssa/src/mir/debuginfo.rs | 3 +- compiler/rustc_codegen_ssa/src/mir/place.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 8 +- .../rustc_const_eval/src/const_eval/mod.rs | 2 +- .../src/interpret/intrinsics.rs | 2 +- .../src/interpret/operator.rs | 2 +- .../rustc_const_eval/src/interpret/place.rs | 10 +- .../src/interpret/projection.rs | 2 +- .../src/interpret/terminator.rs | 6 +- .../src/transform/check_consts/qualifs.rs | 2 +- .../src/transform/promote_consts.rs | 2 +- .../rustc_hir_analysis/src/astconv/errors.rs | 6 +- .../rustc_hir_analysis/src/astconv/mod.rs | 66 ++++----- compiler/rustc_hir_analysis/src/autoderef.rs | 4 +- compiler/rustc_hir_analysis/src/bounds.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 8 +- .../src/check/compare_impl_item.rs | 60 +++++---- .../rustc_hir_analysis/src/check/intrinsic.rs | 127 +++++++++--------- .../rustc_hir_analysis/src/check/wfcheck.rs | 24 ++-- .../src/coherence/builtin.rs | 8 +- .../src/coherence/orphan.rs | 4 +- compiler/rustc_hir_analysis/src/collect.rs | 10 +- .../src/collect/item_bounds.rs | 13 +- .../src/collect/predicates_of.rs | 6 +- .../rustc_hir_analysis/src/collect/type_of.rs | 18 +-- compiler/rustc_hir_analysis/src/lib.rs | 14 +- compiler/rustc_hir_typeck/src/_match.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 2 +- compiler/rustc_hir_typeck/src/cast.rs | 12 +- compiler/rustc_hir_typeck/src/check.rs | 14 +- compiler/rustc_hir_typeck/src/closure.rs | 22 +-- compiler/rustc_hir_typeck/src/coercion.rs | 17 +-- compiler/rustc_hir_typeck/src/demand.rs | 10 +- compiler/rustc_hir_typeck/src/expr.rs | 34 ++--- compiler/rustc_hir_typeck/src/fallback.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 16 ++- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 28 ++-- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 2 +- .../src/fn_ctxt/suggestions.rs | 12 +- .../src/generator_interior/mod.rs | 10 +- .../src/mem_categorization.rs | 5 +- .../rustc_hir_typeck/src/method/confirm.rs | 13 +- compiler/rustc_hir_typeck/src/method/mod.rs | 7 +- compiler/rustc_hir_typeck/src/method/probe.rs | 8 +- .../rustc_hir_typeck/src/method/suggest.rs | 24 ++-- compiler/rustc_hir_typeck/src/op.rs | 2 +- compiler/rustc_hir_typeck/src/pat.rs | 18 +-- compiler/rustc_hir_typeck/src/place_op.rs | 7 +- compiler/rustc_hir_typeck/src/upvar.rs | 8 +- compiler/rustc_infer/src/infer/at.rs | 4 +- .../src/infer/canonical/canonicalizer.rs | 15 +-- .../rustc_infer/src/infer/canonical/mod.rs | 8 +- .../src/infer/canonical/query_response.rs | 14 +- compiler/rustc_infer/src/infer/combine.rs | 18 +-- .../src/infer/error_reporting/mod.rs | 2 +- .../nice_region_error/placeholder_error.rs | 17 +-- .../nice_region_error/static_impl_trait.rs | 2 +- .../trait_impl_difference.rs | 4 +- .../src/infer/error_reporting/note.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 8 +- .../src/infer/higher_ranked/mod.rs | 7 +- .../src/infer/lexical_region_resolve/mod.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 35 ++--- .../rustc_infer/src/infer/nll_relate/mod.rs | 4 +- .../infer/region_constraints/leak_check.rs | 8 +- .../src/infer/region_constraints/mod.rs | 8 +- compiler/rustc_infer/src/traits/engine.rs | 2 +- compiler/rustc_infer/src/traits/mod.rs | 2 +- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 6 +- compiler/rustc_lint/src/context.rs | 2 +- .../src/opaque_hidden_inferred_bound.rs | 4 +- compiler/rustc_lint/src/types.rs | 8 +- compiler/rustc_metadata/src/native_libs.rs | 2 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 9 +- compiler/rustc_middle/src/infer/unify_key.rs | 6 +- compiler/rustc_middle/src/mir/mod.rs | 6 +- compiler/rustc_middle/src/mir/query.rs | 2 +- compiler/rustc_middle/src/mir/tcx.rs | 28 ++-- compiler/rustc_middle/src/ty/adjustment.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 25 ++-- compiler/rustc_middle/src/ty/consts.rs | 12 +- compiler/rustc_middle/src/ty/context.rs | 16 +-- compiler/rustc_middle/src/ty/diagnostics.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 27 ++-- compiler/rustc_middle/src/ty/generics.rs | 2 +- compiler/rustc_middle/src/ty/instance.rs | 10 +- compiler/rustc_middle/src/ty/layout.rs | 25 ++-- compiler/rustc_middle/src/ty/mod.rs | 12 +- compiler/rustc_middle/src/ty/opaque_types.rs | 10 +- compiler/rustc_middle/src/ty/print/mod.rs | 6 +- compiler/rustc_middle/src/ty/print/pretty.rs | 18 +-- compiler/rustc_middle/src/ty/relate.rs | 55 ++++---- .../rustc_middle/src/ty/structural_impls.rs | 8 +- compiler/rustc_middle/src/ty/sty.rs | 46 ++++--- compiler/rustc_middle/src/ty/subst.rs | 10 +- compiler/rustc_middle/src/ty/util.rs | 14 +- compiler/rustc_middle/src/values.rs | 2 +- .../src/build/expr/as_constant.rs | 2 +- .../src/build/expr/as_place.rs | 2 +- .../src/build/expr/as_rvalue.rs | 10 +- .../rustc_mir_build/src/build/matches/mod.rs | 4 +- .../rustc_mir_build/src/build/matches/test.rs | 8 +- compiler/rustc_mir_build/src/build/mod.rs | 2 +- compiler/rustc_mir_build/src/build/scope.rs | 2 +- compiler/rustc_mir_build/src/thir/constant.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 9 +- compiler/rustc_mir_build/src/thir/cx/mod.rs | 4 +- .../src/thir/pattern/const_to_pat.rs | 2 +- .../rustc_mir_dataflow/src/elaborate_drops.rs | 39 +++--- .../src/move_paths/builder.rs | 6 +- .../src/elaborate_box_derefs.rs | 2 +- compiler/rustc_mir_transform/src/generator.rs | 19 +-- compiler/rustc_mir_transform/src/inline.rs | 4 +- .../rustc_mir_transform/src/large_enums.rs | 10 +- .../src/lower_intrinsics.rs | 4 +- .../src/lower_slice_len.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 39 +++--- compiler/rustc_mir_transform/src/sroa.rs | 4 +- compiler/rustc_privacy/src/lib.rs | 2 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 48 +++---- compiler/rustc_symbol_mangling/src/v0.rs | 4 +- compiler/rustc_trait_selection/src/infer.rs | 2 +- .../src/solve/canonical/canonicalize.rs | 10 +- .../src/solve/canonical/mod.rs | 8 +- .../src/solve/project_goals.rs | 10 +- .../src/solve/trait_goals.rs | 20 +-- .../solve/trait_goals/structural_traits.rs | 6 +- .../src/traits/auto_trait.rs | 10 +- .../src/traits/engine.rs | 2 +- .../src/traits/error_reporting/mod.rs | 10 +- .../src/traits/error_reporting/suggestions.rs | 26 ++-- .../rustc_trait_selection/src/traits/mod.rs | 10 +- .../src/traits/object_safety.rs | 24 ++-- .../src/traits/project.rs | 29 ++-- .../src/traits/select/candidate_assembly.rs | 4 +- .../src/traits/select/confirmation.rs | 76 ++++++----- .../src/traits/select/mod.rs | 8 +- .../src/traits/specialize/mod.rs | 2 +- .../rustc_trait_selection/src/traits/util.rs | 10 +- .../src/traits/vtable.rs | 2 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- compiler/rustc_traits/src/chalk/db.rs | 11 +- compiler/rustc_traits/src/chalk/lowering.rs | 48 ++++--- compiler/rustc_traits/src/chalk/mod.rs | 4 +- compiler/rustc_ty_utils/src/abi.rs | 28 ++-- compiler/rustc_ty_utils/src/assoc.rs | 2 +- compiler/rustc_ty_utils/src/consts.rs | 24 ++-- compiler/rustc_ty_utils/src/implied_bounds.rs | 6 +- compiler/rustc_ty_utils/src/layout.rs | 4 +- compiler/rustc_ty_utils/src/needs_drop.rs | 4 +- compiler/rustc_ty_utils/src/ty.rs | 16 +-- 172 files changed, 1030 insertions(+), 966 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 68205fa45587b..240168cc50cdc 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -180,7 +180,7 @@ trait TypeOpInfo<'tcx> { return; }; - let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder { + let placeholder_region = tcx.mk().re_placeholder(ty::Placeholder { name: placeholder.name, universe: adjusted_universe.into(), }); @@ -190,7 +190,7 @@ trait TypeOpInfo<'tcx> { let adjusted_universe = error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32()); adjusted_universe.map(|adjusted| { - tcx.mk_re_placeholder(ty::Placeholder { + tcx.mk().re_placeholder(ty::Placeholder { name: error_placeholder.name, universe: adjusted.into(), }) @@ -390,7 +390,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>( error_region, ®ion_constraints, |vid| ocx.infcx.region_var_origin(vid), - |vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_re_var(vid)), + |vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk().re_var(vid)), ) } @@ -411,7 +411,7 @@ fn try_extract_error_from_region_constraints<'tcx>( } // FIXME: Should this check the universe of the var? Constraint::VarSubReg(vid, sup) if sup == placeholder_region => { - Some((infcx.tcx.mk_re_var(vid), cause.clone())) + Some((infcx.tcx.mk().re_var(vid), cause.clone())) } _ => None, } diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index af705e6a80fef..963b354b2a5da 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1076,7 +1076,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { type_known_to_meet_bound_modulo_regions( &infcx, self.param_env, - tcx.mk_imm_ref(tcx.lifetimes.re_erased, tcx.erase_regions(ty)), + tcx.mk() + .imm_ref(tcx.lifetimes.re_erased, tcx.erase_regions(ty)), def_id, DUMMY_SP, ) @@ -1153,7 +1154,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } if let Some(clone_trait) = tcx.lang_items().clone_trait() - && let trait_ref = tcx.mk_trait_ref(clone_trait, [ty]) + && let trait_ref = tcx.mk().trait_ref(clone_trait, [ty]) && let o = Obligation::new( tcx, ObligationCause::dummy(), diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index ffe82b46cfd67..188291208b76a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -508,7 +508,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let generic_arg = substs[param_index as usize]; let identity_substs = InternalSubsts::identity_for_item(self.infcx.tcx, adt.did()); - let base_ty = self.infcx.tcx.mk_adt(*adt, identity_substs); + let base_ty = self.infcx.tcx.mk().adt(*adt, identity_substs); let base_generic_arg = identity_substs[param_index as usize]; let adt_desc = adt.descr(); diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 96228338a4c22..b1dafe81651f7 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -436,7 +436,7 @@ fn for_each_region_constraint<'tcx>( let subject = match req.subject { ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject), ClosureOutlivesSubject::Ty(ty) => { - format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid))) + format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk().re_var(vid))) } }; with_msg(&format!("where {}: {:?}", subject, req.outlived_free_region,))?; diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 905d8c42b28bc..e8a21a5589a51 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1122,7 +1122,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { _ => arg.fold_with(self), } }); - tcx.mk_opaque(def_id, tcx.mk_substs_from_iter(substs)) + tcx.mk().opaque(def_id, tcx.mk().substs_from_iter(substs)) } } @@ -1141,7 +1141,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { .universal_regions_outlived_by(r_scc) .filter(|&u_r| !self.universal_regions.is_local_free_region(u_r)) .find(|&u_r| self.eval_equal(u_r, r_vid)) - .map(|u_r| tcx.mk_re_var(u_r)) + .map(|u_r| tcx.mk().re_var(u_r)) // In the case of a failure, use `ReErased`. We will eventually // return `None` in this case. .unwrap_or(tcx.lifetimes.re_erased) @@ -1338,7 +1338,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let vid = self.to_region_vid(r); let scc = self.constraint_sccs.scc(vid); let repr = self.scc_representatives[scc]; - tcx.mk_re_var(repr) + tcx.mk().re_var(repr) }) } @@ -1762,7 +1762,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } // If not, report an error. - let member_region = infcx.tcx.mk_re_var(member_region_vid); + let member_region = infcx.tcx.mk().re_var(member_region_vid); errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion { span: m_c.definition_span, hidden_ty: m_c.hidden_ty, diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 748c8b9e4420c..1b3324f2a52f4 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -92,7 +92,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { } None => { subst_regions.push(vid); - infcx.tcx.mk_re_error_with_message( + infcx.tcx.mk().re_error_with_message( concrete_type.span, "opaque type with non-universal region substs", ) @@ -288,7 +288,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { // Require that the hidden type actually fulfills all the bounds of the opaque type, even without // the bounds that the function supplies. - let opaque_ty = self.tcx.mk_opaque(def_id.to_def_id(), id_substs); + let opaque_ty = self.tcx.mk().opaque(def_id.to_def_id(), id_substs); if let Err(err) = ocx.eq( &ObligationCause::misc(instantiated_ty.span, def_id), param_env, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 3919c4793a06f..8f1ab7c7b2070 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -137,7 +137,7 @@ pub(crate) fn type_check<'mir, 'tcx>( upvars: &[Upvar<'tcx>], use_polonius: bool, ) -> MirTypeckResults<'tcx> { - let implicit_region_bound = infcx.tcx.mk_re_var(universal_regions.fr_fn_body); + let implicit_region_bound = infcx.tcx.mk().re_var(universal_regions.fr_fn_body); let mut constraints = MirTypeckRegionConstraints { placeholder_indices: PlaceholderIndices::default(), placeholder_index_to_region: IndexVec::default(), @@ -669,7 +669,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { PlaceTy::from_ty(match base_ty.kind() { ty::Array(inner, _) => { assert!(!from_end, "array subslices should not use from_end"); - tcx.mk_array(*inner, to - from) + tcx.mk().array(*inner, to - from) } ty::Slice(..) => { assert!(from_end, "slice subslices should use from_end"); @@ -1866,7 +1866,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // and hence may contain unnormalized results. let fn_sig = self.normalize(fn_sig, location); - let ty_fn_ptr_from = tcx.mk_fn_ptr(fn_sig); + let ty_fn_ptr_from = tcx.mk().fn_ptr(fn_sig); if let Err(terr) = self.eq_types( *ty, @@ -1890,7 +1890,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ty::Closure(_, substs) => substs.as_closure().sig(), _ => bug!(), }; - let ty_fn_ptr_from = tcx.mk_fn_ptr(tcx.signature_unclosure(sig, *unsafety)); + let ty_fn_ptr_from = + tcx.mk().fn_ptr(tcx.signature_unclosure(sig, *unsafety)); if let Err(terr) = self.eq_types( *ty, @@ -1971,7 +1972,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); let outlives_predicate = - tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause( + tcx.mk().predicate(Binder::dummy(ty::PredicateKind::Clause( ty::Clause::TypeOutlives(ty::OutlivesPredicate(self_ty, *region)), ))); self.prove_predicate( diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 68c86051364ed..de21d151756b0 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -510,11 +510,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { .next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic"))) .to_region_vid(); - let region = self.infcx.tcx.mk_re_var(reg_vid); + let region = self.infcx.tcx.mk().re_var(reg_vid); let va_list_ty = self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]); - unnormalized_input_tys = self.infcx.tcx.mk_type_list_from_iter( + unnormalized_input_tys = self.infcx.tcx.mk().type_list_from_iter( unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)), ); } @@ -660,7 +660,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), def_id); let closure_sig = substs.as_closure().sig(); let inputs_and_output = closure_sig.inputs_and_output(); - let bound_vars = tcx.mk_bound_variable_kinds_from_iter( + let bound_vars = tcx.mk().bound_variable_kinds_from_iter( inputs_and_output .bound_vars() .iter() @@ -670,7 +670,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BrEnv, }; - let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br); + let env_region = tcx.mk().re_late_bound(ty::INNERMOST, br); let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap(); // The "inputs" of the closure in the @@ -684,7 +684,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { }; ty::Binder::bind_with_vars( - tcx.mk_type_list_from_iter( + tcx.mk().type_list_from_iter( iter::once(closure_ty).chain(inputs).chain(iter::once(output)), ), bound_vars, @@ -695,9 +695,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), def_id); let resume_ty = substs.as_generator().resume_ty(); let output = substs.as_generator().return_ty(); - let generator_ty = tcx.mk_generator(def_id, substs, movability); + let generator_ty = tcx.mk().generator(def_id, substs, movability); let inputs_and_output = - self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]); + self.infcx.tcx.mk().type_list(&[generator_ty, resume_ty, output]); ty::Binder::dummy(inputs_and_output) } @@ -713,13 +713,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), def_id); let ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity(); let ty = indices.fold_to_region_vids(tcx, ty); - ty::Binder::dummy(tcx.mk_type_list(&[ty])) + ty::Binder::dummy(tcx.mk().type_list(&[ty])) } DefiningTy::InlineConst(def_id, substs) => { assert_eq!(self.mir_def.did.to_def_id(), def_id); let ty = substs.as_inline_const().ty(); - ty::Binder::dummy(tcx.mk_type_list(&[ty])) + ty::Binder::dummy(tcx.mk().type_list(&[ty])) } } } @@ -793,7 +793,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { { let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| { debug!(?br); - let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind); + let liberated_region = self.tcx.mk().re_free(all_outlive_scope.to_def_id(), br.kind); let region_vid = { let name = match br.kind.get_name() { Some(name) => name, @@ -912,7 +912,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> { where T: TypeFoldable>, { - tcx.fold_regions(value, |region, _| tcx.mk_re_var(self.to_region_vid(region))) + tcx.fold_regions(value, |region, _| tcx.mk().re_var(self.to_region_vid(region))) } } @@ -952,7 +952,7 @@ fn for_each_late_bound_region_in_item<'tcx>( for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) { let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; }; - let liberated_region = tcx.mk_re_free(mir_def_id.to_def_id(), bound_region); + let liberated_region = tcx.mk().re_free(mir_def_id.to_def_id(), bound_region); f(liberated_region); } } diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 28be6d033f8bf..333d5fb19b5c4 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -351,7 +351,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { continue; } PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => { - let ptr_ty = cx.tcx.mk_mut_ptr(arg.layout.ty); + let ptr_ty = cx.tcx.mk().mut_ptr(arg.layout.ty); let ptr_layout = cx.layout_of(ptr_ty); llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 0, true)); llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true)); diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 3dc0ac03312e9..561bc0e320bdc 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -190,7 +190,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance< if let ty::GenericParamDefKind::Lifetime = param.kind { tcx.lifetimes.re_erased.into() } else { - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) } }), ); @@ -198,9 +198,9 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance< let llfn = cx.declare_fn( tcx.symbol_name(instance).name, cx.fn_abi_of_fn_ptr( - ty::Binder::dummy(tcx.mk_fn_sig( - [tcx.mk_unit()], - tcx.mk_unit(), + ty::Binder::dummy(tcx.mk().fn_sig( + [tcx.mk().unit()], + tcx.mk().unit(), false, hir::Unsafety::Unsafe, Abi::Rust, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index c1b3f34e5a6d4..1a7b47142ad95 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -169,7 +169,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( // a (fat) pointer. Make sure it is not called for e.g. `Box`. debug_assert_eq!( cx.size_and_align_of(ptr_type), - cx.size_and_align_of(cx.tcx.mk_mut_ptr(pointee_type)) + cx.size_and_align_of(cx.tcx.mk().mut_ptr(pointee_type)) ); let pointee_type_di_node = type_di_node(cx, pointee_type); @@ -177,7 +177,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( return_if_di_node_created_in_meantime!(cx, unique_type_id); let (thin_pointer_size, thin_pointer_align) = - cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.types.unit)); + cx.size_and_align_of(cx.tcx.mk().imm_ptr(cx.tcx.types.unit)); let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true); match fat_pointer_kind(cx, pointee_type) { @@ -225,8 +225,11 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( // at all and instead emit regular struct debuginfo for it. We just // need to make sure that we don't break existing debuginfo consumers // by doing that (at least not without a warning period). - let layout_type = - if ptr_type.is_box() { cx.tcx.mk_mut_ptr(pointee_type) } else { ptr_type }; + let layout_type = if ptr_type.is_box() { + cx.tcx.mk().mut_ptr(pointee_type) + } else { + ptr_type + }; let layout = cx.layout_of(layout_type); let addr_field = layout.field(cx, abi::FAT_PTR_ADDR); @@ -1331,7 +1334,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>( // All function pointers are described as opaque pointers. This could be improved in the future // by describing them as actual function pointers. - let void_pointer_ty = tcx.mk_imm_ptr(tcx.types.unit); + let void_pointer_ty = tcx.mk().imm_ptr(tcx.types.unit); let void_pointer_type_di_node = type_di_node(cx, void_pointer_ty); let usize_di_node = type_di_node(cx, tcx.types.usize); let (pointer_size, pointer_align) = cx.size_and_align_of(void_pointer_ty); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 5392534cfcb79..9f5f2e77cbfa7 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -433,7 +433,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { ty::Array(ct, _) if (*ct == cx.tcx.types.u8) || cx.layout_of(*ct).is_zst() => { - cx.tcx.mk_imm_ptr(*ct) + cx.tcx.mk().imm_ptr(*ct) } _ => t, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index 6bcd3e5bf58f3..be8d5664129f5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -82,8 +82,8 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>( ty::Foreign(_) => { // Assert that pointers to foreign types really are thin: debug_assert_eq!( - cx.size_of(cx.tcx.mk_imm_ptr(pointee_tail_ty)), - cx.size_of(cx.tcx.mk_imm_ptr(cx.tcx.types.u8)) + cx.size_of(cx.tcx.mk().imm_ptr(pointee_tail_ty)), + cx.size_of(cx.tcx.mk().imm_ptr(cx.tcx.types.u8)) ); None } diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 9c921989ca9a7..c15f9268cbbb4 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -796,25 +796,25 @@ fn get_rust_try_fn<'ll, 'tcx>( // Define the type up front for the signature of the rust_try function. let tcx = cx.tcx; - let i8p = tcx.mk_mut_ptr(tcx.types.i8); + let i8p = tcx.mk().mut_ptr(tcx.types.i8); // `unsafe fn(*mut i8) -> ()` - let try_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( + let try_fn_ty = tcx.mk().fn_ptr(ty::Binder::dummy(tcx.mk().fn_sig( [i8p], - tcx.mk_unit(), + tcx.mk().unit(), false, hir::Unsafety::Unsafe, Abi::Rust, ))); // `unsafe fn(*mut i8, *mut i8) -> ()` - let catch_fn_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( + let catch_fn_ty = tcx.mk().fn_ptr(ty::Binder::dummy(tcx.mk().fn_sig( [i8p, i8p], - tcx.mk_unit(), + tcx.mk().unit(), false, hir::Unsafety::Unsafe, Abi::Rust, ))); // `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32` - let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig( + let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk().fn_sig( [try_fn_ty, i8p, catch_fn_ty], tcx.types.i32, false, diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index e264ce78f0d67..b49e2c645740f 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -336,12 +336,12 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { // only wide pointer boxes are handled as pointers // thin pointer boxes with scalar allocators are handled by the general logic below ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => { - let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty()); + let ptr_ty = cx.tcx.mk().mut_ptr(self.ty.boxed_ty()); return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); } // `dyn* Trait` has the same ABI as `*mut dyn Trait` ty::Dynamic(bounds, region, ty::DynStar) => { - let ptr_ty = cx.tcx.mk_mut_ptr(cx.tcx.mk_dynamic(bounds, region, ty::Dyn)); + let ptr_ty = cx.tcx.mk().mut_ptr(cx.tcx.mk().dynamic(bounds, region, ty::Dyn)); return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate); } _ => {} diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index b19398e68c260..2767bb9caf375 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -73,7 +73,7 @@ fn emit_ptr_va_arg<'ll, 'tcx>( let layout = bx.cx.layout_of(target_ty); let (llty, size, align) = if indirect { ( - bx.cx.layout_of(bx.cx.tcx.mk_imm_ptr(target_ty)).llvm_type(bx.cx), + bx.cx.layout_of(bx.cx.tcx.mk().imm_ptr(target_ty)).llvm_type(bx.cx), bx.cx.data_layout().pointer_size, bx.cx.data_layout().pointer_align, ) diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index abc510e360d56..f7072fe4da311 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -203,7 +203,7 @@ fn vtable_ptr_ty<'tcx, Cx: CodegenMethods<'tcx>>( cx.scalar_pair_element_backend_type( cx.layout_of(match kind { // vtable is the second field of `*mut dyn Trait` - ty::Dyn => cx.tcx().mk_mut_ptr(target), + ty::Dyn => cx.tcx().mk().mut_ptr(target), // vtable is the second field of `dyn* Trait` ty::DynStar => target, }), diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 71c71d59b7ab9..41340f23777e2 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -766,7 +766,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; let extra_args = &args[sig.inputs().skip_binder().len()..]; - let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| { + let extra_args = bx.tcx().mk().type_list_from_iter(extra_args.iter().map(|op_arg| { let op_ty = op_arg.ty(self.mir, bx.tcx()); self.monomorphize(op_ty) })); @@ -1526,7 +1526,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { slot } else { let layout = cx.layout_of( - cx.tcx().mk_tup(&[cx.tcx().mk_mut_ptr(cx.tcx().types.u8), cx.tcx().types.i32]), + cx.tcx().mk().tup(&[cx.tcx().mk().mut_ptr(cx.tcx().types.u8), cx.tcx().types.i32]), ); let slot = PlaceRef::alloca(bx, layout); self.personality_slot = Some(slot); diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 708f3bc0c78f9..4cc2c01b63091 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -387,7 +387,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Create a variable which will be a pointer to the actual value let ptr_ty = bx .tcx() - .mk_ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty }); + .mk() + .ptr(ty::TypeAndMut { mutbl: mir::Mutability::Mut, ty: place.layout.ty }); let ptr_layout = bx.layout_of(ptr_ty); let alloca = PlaceRef::alloca(bx, ptr_layout); bx.set_var_name(alloca.llval, &(var.name.to_string() + ".dbg.spill")); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index cf02f59f67b97..6a145faeb1180 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { layout: TyAndLayout<'tcx>, ) -> Self { assert!(layout.is_unsized(), "tried to allocate indirect place for sized values"); - let ptr_ty = bx.cx().tcx().mk_mut_ptr(layout.ty); + let ptr_ty = bx.cx().tcx().mk().mut_ptr(layout.ty); let ptr_layout = bx.cx().layout_of(ptr_ty); Self::alloca(bx, ptr_layout) } diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 3d856986fb4f7..7ecc5d91481ca 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -350,7 +350,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Ref(_, bk, place) => { let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { - tcx.mk_ref( + tcx.mk().ref_( tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() }, ) @@ -361,7 +361,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::CopyForDeref(place) => self.codegen_operand(bx, &Operand::Copy(place)), mir::Rvalue::AddressOf(mutability, place) => { let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { - tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability }) + tcx.mk().ptr(ty::TypeAndMut { ty, mutbl: mutability }) }; self.codegen_place_to_pointer(bx, place, mk_ptr) } @@ -413,7 +413,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { lhs.layout.ty, ); let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty); - let operand_ty = bx.tcx().mk_tup(&[val_ty, bx.tcx().types.bool]); + let operand_ty = bx.tcx().mk().tup(&[val_ty, bx.tcx().types.bool]); OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) } } @@ -478,7 +478,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let lloperand = operand.immediate(); let content_ty = self.monomorphize(content_ty); - let box_layout = bx.cx().layout_of(bx.tcx().mk_box(content_ty)); + let box_layout = bx.cx().layout_of(bx.tcx().mk().box_(content_ty)); let llty_ptr = bx.cx().backend_type(box_layout); let val = bx.pointercast(lloperand, llty_ptr); diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index 3cdf1e6e30c99..ba7e5281f9dbe 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -155,7 +155,7 @@ pub(crate) fn deref_mir_constant<'tcx>( // In case of unsized types, figure out the real type behind. MemPlaceMeta::Meta(scalar) => match mplace.layout.ty.kind() { ty::Str => bug!("there's no sized equivalent of a `str`"), - ty::Slice(elem_ty) => tcx.mk_array(*elem_ty, scalar.to_target_usize(&tcx).unwrap()), + ty::Slice(elem_ty) => tcx.mk().array(*elem_ty, scalar.to_target_usize(&tcx).unwrap()), _ => bug!( "type {} should not have metadata, but had {:?}", mplace.layout.ty, diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index a29cdade02343..ad91227ba9a75 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -169,7 +169,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { sym::pref_align_of | sym::variant_count => self.tcx.types.usize, sym::needs_drop => self.tcx.types.bool, sym::type_id => self.tcx.types.u64, - sym::type_name => self.tcx.mk_static_str(), + sym::type_name => self.tcx.mk().static_str(), _ => bug!(), }; let val = self.ctfe_query(None, |tcx| { diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 4decfe863e634..8ffb970b14f09 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -19,7 +19,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx> { let (val, overflowed, ty) = self.overflowing_binary_op(op, &left, &right)?; debug_assert_eq!( - self.tcx.mk_tup(&[ty, self.tcx.types.bool]), + self.tcx.mk().tup(&[ty, self.tcx.types.bool]), dest.layout.ty, "type mismatch for result of {:?}", op, diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 3c463500a609e..8075c3e6e64bb 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -394,7 +394,7 @@ where // (Transmuting is okay since this is an in-memory place. We also double-check the size // stays the same.) let (len, e_ty) = mplace.layout.ty.simd_size_and_type(*self.tcx); - let array = self.tcx.mk_array(e_ty, len); + let array = self.tcx.mk().array(e_ty, len); let layout = self.layout_of(array)?; assert_eq!(layout.size, mplace.layout.size); Ok((MPlaceTy { layout, ..*mplace }, len)) @@ -774,10 +774,10 @@ where let meta = Scalar::from_target_usize(u64::try_from(str.len()).unwrap(), self); let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) }; - let ty = self.tcx.mk_ref( - self.tcx.lifetimes.re_static, - ty::TypeAndMut { ty: self.tcx.types.str_, mutbl }, - ); + let ty = self + .tcx + .mk() + .ref_(self.tcx.lifetimes.re_static, ty::TypeAndMut { ty: self.tcx.types.str_, mutbl }); let layout = self.layout_of(ty).unwrap(); Ok(MPlaceTy { mplace, layout, align: layout.align.abi }) } diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs index 91da930db4fbf..6d7281006550b 100644 --- a/compiler/rustc_const_eval/src/interpret/projection.rs +++ b/compiler/rustc_const_eval/src/interpret/projection.rs @@ -317,7 +317,7 @@ where let (meta, ty) = match base.layout.ty.kind() { // It is not nice to match on the type, but that seems to be the only way to // implement this. - ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(*inner, inner_len)), + ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk().array(*inner, inner_len)), ty::Slice(..) => { let len = Scalar::from_target_usize(inner_len, self); (MemPlaceMeta::Meta(len), base.layout.ty) diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 685a5599cdedf..518c67f8a92a1 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -74,7 +74,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder); let extra_args = &args[fn_sig.inputs().len()..]; let extra_args = - self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout.ty)); + self.tcx.mk().type_list_from_iter(extra_args.iter().map(|arg| arg.layout.ty)); let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() { ty::FnPtr(_sig) => { @@ -647,7 +647,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Adjust receiver argument. Layout can be any (thin) ptr. args[0] = ImmTy::from_immediate( Scalar::from_maybe_pointer(adjusted_receiver, self).into(), - self.layout_of(self.tcx.mk_mut_ptr(dyn_ty))?, + self.layout_of(self.tcx.mk().mut_ptr(dyn_ty))?, ) .into(); trace!("Patched receiver operand to {:#?}", args[0]); @@ -700,7 +700,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let arg = ImmTy::from_immediate( place.to_ref(self), - self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?, + self.layout_of(self.tcx.mk().mut_ptr(place.layout.ty))?, ); let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index bb4b7ad50b8f2..b1aabee6b68af 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -220,7 +220,7 @@ impl Qualif for CustomEq { def: AdtDef<'tcx>, substs: SubstsRef<'tcx>, ) -> bool { - let ty = cx.tcx.mk_adt(def, substs); + let ty = cx.tcx.mk().adt(def, substs); !ty.is_structural_eq_shallow(cx.tcx) } } diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index 3f3b66b0645a8..ab7ac1941b0b6 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -857,7 +857,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let ty = local_decls[place.local].ty; let span = statement.source_info.span; - let ref_ty = tcx.mk_ref( + let ref_ty = tcx.mk().ref_( tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() }, ); diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 156334fe785b9..aa1ee784b488b 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -348,13 +348,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // `::Item = String`. let projection_ty = pred.skip_binder().projection_ty; - let substs_with_infer_self = tcx.mk_substs_from_iter( - std::iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) + let substs_with_infer_self = tcx.mk().substs_from_iter( + std::iter::once(tcx.mk().ty_var(ty::TyVid::from_u32(0)).into()) .chain(projection_ty.substs.iter().skip(1)), ); let quiet_projection_ty = - tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self); + tcx.mk().alias_ty(projection_ty.def_id, substs_with_infer_self); let term = pred.skip_binder().term; diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f830269b45dae..ab4265bed4f6d 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -236,7 +236,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { var: ty::BoundVar::from_u32(index), kind: ty::BrNamed(def_id, name), }; - tcx.mk_re_late_bound(debruijn, br) + tcx.mk().re_late_bound(debruijn, br) } Some(rbv::ResolvedArg::EarlyBound(def_id)) => { @@ -244,12 +244,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local()); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; - tcx.mk_re_early_bound(ty::EarlyBoundRegion { def_id, index, name }) + tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id, index, name }) } Some(rbv::ResolvedArg::Free(scope, id)) => { let name = lifetime_name(id.expect_local()); - tcx.mk_re_free(scope, ty::BrNamed(id, name)) + tcx.mk().re_free(scope, ty::BrNamed(id, name)) // (*) -- not late-bound, won't change } @@ -266,7 +266,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // elision. `resolve_lifetime` should have // reported an error in this case -- but if // not, let's error out. - tcx.mk_re_error_with_message( + tcx.mk().re_error_with_message( lifetime.ident.span, "unelided lifetime in signature", ) @@ -487,10 +487,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?param, "unelided lifetime in signature"); // This indicates an illegal lifetime in a non-assoc-trait position - tcx.mk_re_error_with_message( - self.span, - "unelided lifetime in signature", - ) + tcx.mk() + .re_error_with_message(self.span, "unelided lifetime in signature") }) .into(), GenericParamDefKind::Type { has_default, .. } => { @@ -693,7 +691,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let assoc_bindings = self.create_assoc_bindings_for_generic_args(args); let poly_trait_ref = - ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars); + ty::Binder::bind_with_vars(tcx.mk().trait_ref(trait_def_id, substs), bound_vars); debug!(?poly_trait_ref, ?assoc_bindings); bounds.push_trait_bound(tcx, poly_trait_ref, span, constness); @@ -826,7 +824,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(b) = trait_segment.args().bindings.first() { prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span))); } - self.tcx().mk_trait_ref(trait_def_id, substs) + self.tcx().mk().trait_ref(trait_def_id, substs) } #[instrument(level = "debug", skip(self, span))] @@ -1164,7 +1162,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?substs_trait_ref_and_assoc_item); - self.tcx().mk_alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item) + self.tcx().mk().alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item) }); if !speculative { @@ -1265,7 +1263,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // // Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty` // parameter to have a skipped binder. - let param_ty = tcx.mk_alias(ty::Projection, projection_ty.skip_binder()); + let param_ty = tcx.mk().alias(ty::Projection, projection_ty.skip_binder()); self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars()); } } @@ -1614,7 +1612,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .collect::>(); v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); v.dedup(); - let existential_predicates = tcx.mk_poly_existential_predicates(&v); + let existential_predicates = tcx.mk().poly_existential_predicates(&v); // Use explicitly-specified region bound. let region_bound = if !lifetime.is_elided() { @@ -1639,14 +1637,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } else { err.emit() }; - tcx.mk_re_error(e) + tcx.mk().re_error(e) }) } }) }; debug!("region_bound: {:?}", region_bound); - let ty = tcx.mk_dynamic(existential_predicates, region_bound, representation); + let ty = tcx.mk().dynamic(existential_predicates, region_bound, representation); debug!("trait_object_type: {:?}", ty); ty } @@ -2493,7 +2491,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!("qpath_to_ty: trait_ref={:?}", trait_ref); - tcx.mk_projection(item_def_id, item_substs) + tcx.mk().projection(item_def_id, item_substs) } pub fn prohibit_generics<'a>( @@ -2756,7 +2754,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.note("`impl Trait` types can't have type parameters"); }); let substs = self.ast_path_substs_for_ty(span, did, item_segment.0); - tcx.mk_opaque(did, substs) + tcx.mk().opaque(did, substs) } Res::Def( DefKind::Enum @@ -2808,14 +2806,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { var: ty::BoundVar::from_u32(index), kind: ty::BoundTyKind::Param(def_id, name), }; - tcx.mk_bound(debruijn, br) + tcx.mk().bound(debruijn, br) } Some(rbv::ResolvedArg::EarlyBound(_)) => { let def_id = def_id.expect_local(); let item_def_id = tcx.hir().ty_param_owner(def_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id.to_def_id()]; - tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id)) + tcx.mk().ty_param(index, tcx.hir().ty_param_name(def_id)) } Some(rbv::ResolvedArg::Error(guar)) => tcx.ty_error(guar), arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"), @@ -2970,9 +2968,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { match prim_ty { hir::PrimTy::Bool => tcx.types.bool, hir::PrimTy::Char => tcx.types.char, - hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)), - hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)), - hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)), + hir::PrimTy::Int(it) => tcx.mk().mach_int(ty::int_ty(it)), + hir::PrimTy::Uint(uit) => tcx.mk().mach_uint(ty::uint_ty(uit)), + hir::PrimTy::Float(ft) => tcx.mk().mach_float(ty::float_ty(ft)), hir::PrimTy::Str => tcx.types.str_, } } @@ -3007,24 +3005,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.tcx(); let result_ty = match &ast_ty.kind { - hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)), + hir::TyKind::Slice(ty) => tcx.mk().slice(self.ast_ty_to_ty(ty)), hir::TyKind::Ptr(mt) => { - tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) + tcx.mk().ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) } hir::TyKind::Ref(region, mt) => { let r = self.ast_region_to_region(region, None); debug!(?r); let t = self.ast_ty_to_ty_inner(mt.ty, true, false); - tcx.mk_ref(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) + tcx.mk().ref_(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) } hir::TyKind::Never => tcx.types.never, hir::TyKind::Tup(fields) => { - tcx.mk_tup_from_iter(fields.iter().map(|t| self.ast_ty_to_ty(t))) + tcx.mk().tup_from_iter(fields.iter().map(|t| self.ast_ty_to_ty(t))) } hir::TyKind::BareFn(bf) => { require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span); - tcx.mk_fn_ptr(self.ty_of_fn( + tcx.mk().fn_ptr(self.ty_of_fn( ast_ty.hir_id, bf.unsafety, bf.abi, @@ -3095,7 +3093,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } }; - tcx.mk_array_with_const_len(self.ast_ty_to_ty(ty), length) + tcx.mk().array_with_const_len(self.ast_ty_to_ty(ty), length) } hir::TyKind::Typeof(e) => { let ty_erased = tcx.type_of(e.def_id).subst_identity(); @@ -3147,12 +3145,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] else { bug!() }; self.ast_region_to_region(lifetime, None).into() } else { - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) } }); debug!("impl_trait_ty_to_ty: substs={:?}", substs); - if in_trait { tcx.mk_projection(def_id, substs) } else { tcx.mk_opaque(def_id, substs) } + if in_trait { tcx.mk().projection(def_id, substs) } else { tcx.mk().opaque(def_id, substs) } } pub fn ty_of_arg(&self, ty: &hir::Ty<'_>, expected_ty: Option>) -> Ty<'tcx> { @@ -3221,12 +3219,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.ast_ty_to_ty(output) } } - hir::FnRetTy::DefaultReturn(..) => tcx.mk_unit(), + hir::FnRetTy::DefaultReturn(..) => tcx.mk().unit(), }; debug!(?output_ty); - let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi); + let fn_ty = tcx.mk().fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi); let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars); if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) { @@ -3315,7 +3313,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let fn_sig = tcx.fn_sig(assoc.def_id).subst( tcx, - trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)), + trait_ref + .substs + .extend_to(tcx, assoc.def_id, |param, _| tcx.mk().param_from_def(param)), ); let ty = if let Some(arg_idx) = arg_idx { fn_sig.input(arg_idx) } else { fn_sig.output() }; diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index ba2d4319af6e2..ab358191e1f9a 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { let tcx = self.infcx.tcx; // - let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]); + let trait_ref = tcx.mk().trait_ref(tcx.lang_items().deref_trait()?, [ty]); let cause = traits::ObligationCause::misc(self.span, self.body_id); @@ -141,7 +141,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { let normalized_ty = self .infcx .at(&cause, self.param_env) - .normalize(tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs)); + .normalize(tcx.mk().projection(tcx.lang_items().deref_target()?, trait_ref.substs)); let mut fulfillcx = >::new_in_snapshot(tcx); let normalized_ty = normalized_ty.into_value_registering_obligations(self.infcx, &mut *fulfillcx); diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index 0880c8c15f2e0..c534344697321 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -57,7 +57,7 @@ impl<'tcx> Bounds<'tcx> { pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) { let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span)); - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [ty])); + let trait_ref = ty::Binder::dummy(tcx.mk().trait_ref(sized_def_id, [ty])); // Preferrable to put this obligation first, since we report better errors for sized ambiguity. self.predicates.insert(0, (trait_ref.without_const().to_predicate(tcx), span)); } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 14dc9d8918000..2a41a7e7c0291 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -306,9 +306,9 @@ pub(super) fn check_opaque_for_inheriting_lifetimes( { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); let opaque_identity_ty = if in_trait { - tcx.mk_projection(def_id.to_def_id(), substs) + tcx.mk().projection(def_id.to_def_id(), substs) } else { - tcx.mk_opaque(def_id.to_def_id(), substs) + tcx.mk().opaque(def_id.to_def_id(), substs) }; let mut visitor = ProhibitOpaqueVisitor { opaque_identity_ty, @@ -407,7 +407,7 @@ fn check_opaque_meets_bounds<'tcx>( .with_opaque_type_inference(DefiningAnchor::Bind(defining_use_anchor)) .build(); let ocx = ObligationCtxt::new(&infcx); - let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs); + let opaque_ty = tcx.mk().opaque(def_id.to_def_id(), substs); // `ReErased` regions appear in the "parent_substs" of closures/generators. // We're ignoring them here and replacing them with fresh region variables. @@ -540,7 +540,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { tcx, assoc_item, assoc_item, - tcx.mk_trait_ref(id.owner_id.to_def_id(), trait_substs), + tcx.mk().trait_ref(id.owner_id.to_def_id(), trait_substs), ); } _ => {} diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 123207249d27d..bc3de03747971 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -195,7 +195,7 @@ fn compare_method_predicate_entailment<'tcx>( // the new hybrid bounds we computed. let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id); let param_env = ty::ParamEnv::new( - tcx.mk_predicates(&hybrid_preds.predicates), + tcx.mk().predicates(&hybrid_preds.predicates), Reveal::UserFacing, hir::Constness::NotConst, ); @@ -246,7 +246,7 @@ fn compare_method_predicate_entailment<'tcx>( infer::HigherRankedType, tcx.fn_sig(impl_m.def_id).subst_identity(), ); - let unnormalized_impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(unnormalized_impl_sig)); + let unnormalized_impl_fty = tcx.mk().fn_ptr(ty::Binder::dummy(unnormalized_impl_sig)); let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id); let impl_sig = ocx.normalize(&norm_cause, param_env, unnormalized_impl_sig); @@ -263,7 +263,7 @@ fn compare_method_predicate_entailment<'tcx>( // We also have to add the normalized trait signature // as we don't normalize during implied bounds computation. wf_tys.extend(trait_sig.inputs_and_output.iter()); - let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig)); + let trait_fty = tcx.mk().fn_ptr(ty::Binder::dummy(trait_sig)); debug!("compare_impl_method: trait_fty={:?}", trait_fty); @@ -463,7 +463,7 @@ impl<'tcx> TypeFolder> for RemapLateBound<'_, 'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { if let ty::ReFree(fr) = *r { - self.tcx.mk_re_free( + self.tcx.mk().re_free( fr.scope, self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region), ) @@ -778,9 +778,9 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( } let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind()) else { - return tcx.mk_re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound") + return tcx.mk().re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound") }; - tcx.mk_re_early_bound(ty::EarlyBoundRegion { + tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: e.def_id, name: e.name, index: (e.index as usize - num_trait_substs + num_impl_substs) as u32, @@ -1799,7 +1799,7 @@ fn compare_type_predicate_entailment<'tcx>( let impl_ty_span = tcx.def_span(impl_ty_def_id); let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_def_id); let param_env = ty::ParamEnv::new( - tcx.mk_predicates(&hybrid_preds.predicates), + tcx.mk().predicates(&hybrid_preds.predicates), Reveal::UserFacing, hir::Constness::NotConst, ); @@ -1905,7 +1905,7 @@ pub(super) fn check_type_bounds<'tcx>( if let Some(def_id) = defs.parent { let parent_defs = tcx.generics_of(def_id); InternalSubsts::fill_item(&mut substs, tcx, parent_defs, &mut |param, _| { - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) }); } let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> = @@ -1915,30 +1915,36 @@ pub(super) fn check_type_bounds<'tcx>( let kind = ty::BoundTyKind::Param(param.def_id, param.name); let bound_var = ty::BoundVariableKind::Ty(kind); bound_vars.push(bound_var); - tcx.mk_bound( - ty::INNERMOST, - ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, - ) - .into() + tcx.mk() + .bound( + ty::INNERMOST, + ty::BoundTy { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, + ) + .into() } GenericParamDefKind::Lifetime => { let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); let bound_var = ty::BoundVariableKind::Region(kind); bound_vars.push(bound_var); - tcx.mk_re_late_bound( - ty::INNERMOST, - ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, - ) - .into() + tcx.mk() + .re_late_bound( + ty::INNERMOST, + ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, + ) + .into() } GenericParamDefKind::Const { .. } => { let bound_var = ty::BoundVariableKind::Const; bound_vars.push(bound_var); - tcx.mk_const( - ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)), - tcx.type_of(param.def_id).subst_identity(), - ) - .into() + tcx.mk() + .const_( + ty::ConstKind::Bound( + ty::INNERMOST, + ty::BoundVar::from_usize(bound_vars.len() - 1), + ), + tcx.type_of(param.def_id).subst_identity(), + ) + .into() } }); let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); @@ -1974,7 +1980,7 @@ pub(super) fn check_type_bounds<'tcx>( _ => predicates.push( ty::Binder::bind_with_vars( ty::ProjectionPredicate { - projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_substs), + projection_ty: tcx.mk().alias_ty(trait_ty.def_id, rebased_substs), term: impl_ty_value.into(), }, bound_vars, @@ -1982,7 +1988,11 @@ pub(super) fn check_type_bounds<'tcx>( .to_predicate(tcx), ), }; - ty::ParamEnv::new(tcx.mk_predicates(&predicates), Reveal::UserFacing, param_env.constness()) + ty::ParamEnv::new( + tcx.mk().predicates(&predicates), + Reveal::UserFacing, + param_env.constness(), + ) }; debug!(?normalize_param_env); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 8c364a4f3b2b8..efd58aea42472 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -53,13 +53,13 @@ fn equate_intrinsic_type<'tcx>( && gen_count_ok(own_counts.types, n_tps, "type") && gen_count_ok(own_counts.consts, 0, "const") { - let fty = tcx.mk_fn_ptr(sig); + let fty = tcx.mk().fn_ptr(sig); let it_def_id = it.owner_id.def_id; let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType); require_same_types( tcx, &cause, - tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()), + tcx.mk().fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()), fty, ); } @@ -132,7 +132,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir /// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`, /// and in `library/core/src/intrinsics.rs`. pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { - let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n))); + let param = |n| tcx.mk().ty_param(n, Symbol::intern(&format!("P{}", n))); let intrinsic_id = it.owner_id.to_def_id(); let intrinsic_name = tcx.item_name(intrinsic_id); let name_str = intrinsic_name.as_str(); @@ -143,16 +143,16 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { ]); let mk_va_list_ty = |mutbl| { tcx.lang_items().va_list().map(|did| { - let region = tcx.mk_re_late_bound( + let region = tcx.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }, ); - let env_region = tcx.mk_re_late_bound( + let env_region = tcx.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv }, ); let va_list_ty = tcx.type_of(did).subst(tcx, &[region.into()]); - (tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) + (tcx.mk().ref_(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) }) }; @@ -164,15 +164,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let (n_tps, inputs, output) = match split[1] { "cxchg" | "cxchgweak" => ( 1, - vec![tcx.mk_mut_ptr(param(0)), param(0), param(0)], - tcx.mk_tup(&[param(0), tcx.types.bool]), + vec![tcx.mk().mut_ptr(param(0)), param(0), param(0)], + tcx.mk().tup(&[param(0), tcx.types.bool]), ), - "load" => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)), - "store" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), + "load" => (1, vec![tcx.mk().imm_ptr(param(0))], param(0)), + "store" => (1, vec![tcx.mk().mut_ptr(param(0)), param(0)], tcx.mk().unit()), "xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" | "min" | "umax" - | "umin" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], param(0)), - "fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk_unit()), + | "umin" => (1, vec![tcx.mk().mut_ptr(param(0)), param(0)], param(0)), + "fence" | "singlethreadfence" => (0, Vec::new(), tcx.mk().unit()), op => { tcx.sess.emit_err(UnrecognizedAtomicOperation { span: it.span, op }); return; @@ -184,19 +184,19 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let (n_tps, inputs, output) = match intrinsic_name { sym::abort => (0, Vec::new(), tcx.types.never), sym::unreachable => (0, Vec::new(), tcx.types.never), - sym::breakpoint => (0, Vec::new(), tcx.mk_unit()), + sym::breakpoint => (0, Vec::new(), tcx.mk().unit()), sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => { (1, Vec::new(), tcx.types.usize) } sym::size_of_val | sym::min_align_of_val => { - (1, vec![tcx.mk_imm_ptr(param(0))], tcx.types.usize) + (1, vec![tcx.mk().imm_ptr(param(0))], tcx.types.usize) } sym::rustc_peek => (1, vec![param(0)], param(0)), sym::caller_location => (0, vec![], tcx.caller_location_ty()), sym::assert_inhabited | sym::assert_zero_valid - | sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()), - sym::forget => (1, vec![param(0)], tcx.mk_unit()), + | sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk().unit()), + sym::forget => (1, vec![param(0)], tcx.mk().unit()), sym::transmute => (2, vec![param(0)], param(1)), sym::prefetch_read_data | sym::prefetch_write_data @@ -204,59 +204,59 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { | sym::prefetch_write_instruction => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), tcx.types.i32, ], - tcx.mk_unit(), + tcx.mk().unit(), ), - sym::drop_in_place => (1, vec![tcx.mk_mut_ptr(param(0))], tcx.mk_unit()), + sym::drop_in_place => (1, vec![tcx.mk().mut_ptr(param(0))], tcx.mk().unit()), sym::needs_drop => (1, Vec::new(), tcx.types.bool), - sym::type_name => (1, Vec::new(), tcx.mk_static_str()), + sym::type_name => (1, Vec::new(), tcx.mk().static_str()), sym::type_id => (1, Vec::new(), tcx.types.u64), sym::offset | sym::arith_offset => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), tcx.types.isize, ], - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), ), sym::ptr_mask => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), tcx.types.usize, ], - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), ), sym::copy | sym::copy_nonoverlapping => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), tcx.types.usize, ], - tcx.mk_unit(), + tcx.mk().unit(), ), sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }), tcx.types.usize, ], - tcx.mk_unit(), + tcx.mk().unit(), ), sym::write_bytes | sym::volatile_set_memory => ( 1, vec![ - tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), + tcx.mk().ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Mut }), tcx.types.u8, tcx.types.usize, ], - tcx.mk_unit(), + tcx.mk().unit(), ), sym::sqrtf32 => (0, vec![tcx.types.f32], tcx.types.f32), sym::sqrtf64 => (0, vec![tcx.types.f64], tcx.types.f64), @@ -304,10 +304,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { sym::roundevenf64 => (0, vec![tcx.types.f64], tcx.types.f64), sym::volatile_load | sym::unaligned_volatile_load => { - (1, vec![tcx.mk_imm_ptr(param(0))], param(0)) + (1, vec![tcx.mk().imm_ptr(param(0))], param(0)) } sym::volatile_store | sym::unaligned_volatile_store => { - (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()) + (1, vec![tcx.mk().mut_ptr(param(0)), param(0)], tcx.mk().unit()) } sym::ctpop @@ -319,27 +319,27 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { | sym::bitreverse => (1, vec![param(0)], param(0)), sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => { - (1, vec![param(0), param(0)], tcx.mk_tup(&[param(0), tcx.types.bool])) + (1, vec![param(0), param(0)], tcx.mk().tup(&[param(0), tcx.types.bool])) } sym::ptr_guaranteed_cmp => { - (1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.u8) + (1, vec![tcx.mk().imm_ptr(param(0)), tcx.mk().imm_ptr(param(0))], tcx.types.u8) } sym::const_allocate => { - (0, vec![tcx.types.usize, tcx.types.usize], tcx.mk_mut_ptr(tcx.types.u8)) + (0, vec![tcx.types.usize, tcx.types.usize], tcx.mk().mut_ptr(tcx.types.u8)) } sym::const_deallocate => ( 0, - vec![tcx.mk_mut_ptr(tcx.types.u8), tcx.types.usize, tcx.types.usize], - tcx.mk_unit(), + vec![tcx.mk().mut_ptr(tcx.types.u8), tcx.types.usize, tcx.types.usize], + tcx.mk().unit(), ), sym::ptr_offset_from => { - (1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.isize) + (1, vec![tcx.mk().imm_ptr(param(0)), tcx.mk().imm_ptr(param(0))], tcx.types.isize) } sym::ptr_offset_from_unsigned => { - (1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.usize) + (1, vec![tcx.mk().imm_ptr(param(0)), tcx.mk().imm_ptr(param(0))], tcx.types.usize) } sym::unchecked_div | sym::unchecked_rem | sym::exact_div => { (1, vec![param(0), param(0)], param(0)) @@ -359,11 +359,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { } sym::float_to_int_unchecked => (2, vec![param(0)], param(1)), - sym::assume => (0, vec![tcx.types.bool], tcx.mk_unit()), + sym::assume => (0, vec![tcx.types.bool], tcx.mk().unit()), sym::likely => (0, vec![tcx.types.bool], tcx.types.bool), sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool), - sym::read_via_copy => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)), + sym::read_via_copy => (1, vec![tcx.mk().imm_ptr(param(0))], param(0)), sym::discriminant_value => { let assoc_items = tcx.associated_item_def_ids( @@ -375,43 +375,43 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }; ( 1, - vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))], - tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])), + vec![tcx.mk().imm_ref(tcx.mk().re_late_bound(ty::INNERMOST, br), param(0))], + tcx.mk().projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])), ) } kw::Try => { - let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8); - let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig( + let mut_u8 = tcx.mk().mut_ptr(tcx.types.u8); + let try_fn_ty = ty::Binder::dummy(tcx.mk().fn_sig( [mut_u8], - tcx.mk_unit(), + tcx.mk().unit(), false, hir::Unsafety::Normal, Abi::Rust, )); - let catch_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig( + let catch_fn_ty = ty::Binder::dummy(tcx.mk().fn_sig( [mut_u8, mut_u8], - tcx.mk_unit(), + tcx.mk().unit(), false, hir::Unsafety::Normal, Abi::Rust, )); ( 0, - vec![tcx.mk_fn_ptr(try_fn_ty), mut_u8, tcx.mk_fn_ptr(catch_fn_ty)], + vec![tcx.mk().fn_ptr(try_fn_ty), mut_u8, tcx.mk().fn_ptr(catch_fn_ty)], tcx.types.i32, ) } sym::va_start | sym::va_end => match mk_va_list_ty(hir::Mutability::Mut) { - Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk_unit()), + Some((va_list_ref_ty, _)) => (0, vec![va_list_ref_ty], tcx.mk().unit()), None => bug!("`va_list` language item needed for C-variadic intrinsics"), }, sym::va_copy => match mk_va_list_ty(hir::Mutability::Not) { Some((va_list_ref_ty, va_list_ty)) => { - let va_list_ptr_ty = tcx.mk_mut_ptr(va_list_ty); - (0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk_unit()) + let va_list_ptr_ty = tcx.mk().mut_ptr(va_list_ty); + (0, vec![va_list_ptr_ty, va_list_ref_ty], tcx.mk().unit()) } None => bug!("`va_list` language item needed for C-variadic intrinsics"), }, @@ -421,12 +421,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { None => bug!("`va_list` language item needed for C-variadic intrinsics"), }, - sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), + sym::nontemporal_store => { + (1, vec![tcx.mk().mut_ptr(param(0)), param(0)], tcx.mk().unit()) + } sym::raw_eq => { let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }; - let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0)); + let param_ty = + tcx.mk().imm_ref(tcx.mk().re_late_bound(ty::INNERMOST, br), param(0)); (1, vec![param_ty; 2], tcx.types.bool) } @@ -435,7 +438,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { sym::const_eval_select => (4, vec![param(0), param(1), param(2)], param(3)), sym::vtable_size | sym::vtable_align => { - (0, vec![tcx.mk_imm_ptr(tcx.mk_unit())], tcx.types.usize) + (0, vec![tcx.mk().imm_ptr(tcx.mk().unit())], tcx.types.usize) } other => { @@ -445,7 +448,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { }; (n_tps, 0, inputs, output, unsafety) }; - let sig = tcx.mk_fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic); + let sig = tcx.mk().fn_sig(inputs, output, false, unsafety, Abi::RustIntrinsic); let sig = ty::Binder::bind_with_vars(sig, bound_vars); equate_intrinsic_type(tcx, it, n_tps, n_lts, sig) } @@ -454,7 +457,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let param = |n| { let name = Symbol::intern(&format!("P{}", n)); - tcx.mk_ty_param(n, name) + tcx.mk().ty_param(n, name) }; let name = it.ident.name; @@ -496,7 +499,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) sym::simd_fpowi => (1, vec![param(0), tcx.types.i32], param(0)), sym::simd_fma => (1, vec![param(0), param(0), param(0)], param(0)), sym::simd_gather => (3, vec![param(0), param(1), param(2)], param(0)), - sym::simd_scatter => (3, vec![param(0), param(1), param(2)], tcx.mk_unit()), + sym::simd_scatter => (3, vec![param(0), param(1), param(2)], tcx.mk().unit()), sym::simd_insert => (2, vec![param(0), tcx.types.u32, param(1)], param(0)), sym::simd_extract => (2, vec![param(0), tcx.types.u32], param(1)), sym::simd_cast @@ -525,7 +528,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) name if name.as_str().starts_with("simd_shuffle") => { match name.as_str()["simd_shuffle".len()..].parse() { Ok(n) => { - let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)]; + let params = vec![param(0), param(0), tcx.mk().array(tcx.types.u32, n)]; (2, params, param(1)) } Err(_) => { @@ -543,7 +546,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) } }; - let sig = tcx.mk_fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic); + let sig = tcx.mk().fn_sig(inputs, output, false, hir::Unsafety::Unsafe, Abi::PlatformIntrinsic); let sig = ty::Binder::dummy(sig); equate_intrinsic_type(tcx, it, n_tps, 0, sig) } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 28f0924d1d683..7b057610506d1 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -492,7 +492,7 @@ fn augment_param_env<'tcx>( return param_env; } - let bounds = tcx.mk_predicates_from_iter( + let bounds = tcx.mk().predicates_from_iter( param_env.caller_bounds().iter().chain(new_predicates.iter().cloned()), ); // FIXME(compiler-errors): Perhaps there is a case where we need to normalize this @@ -553,11 +553,11 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( // our example, the type was `Self`, which will also be // `Self` in the GAT. let ty_param = gat_generics.param_at(*ty_idx, tcx); - let ty_param = tcx.mk_ty_param(ty_param.index, ty_param.name); + let ty_param = tcx.mk().ty_param(ty_param.index, ty_param.name); // Same for the region. In our example, 'a corresponds // to the 'me parameter. let region_param = gat_generics.param_at(*region_a_idx, tcx); - let region_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion { + let region_param = tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: region_param.def_id, index: region_param.index, name: region_param.name, @@ -567,7 +567,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives( ty::OutlivesPredicate(ty_param, region_param), )); - let clause = tcx.mk_predicate(ty::Binder::dummy(clause)); + let clause = tcx.mk().predicate(ty::Binder::dummy(clause)); bounds.insert(clause); } } @@ -594,14 +594,14 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( debug!("required clause: {region_a} must outlive {region_b}"); // Translate into the generic parameters of the GAT. let region_a_param = gat_generics.param_at(*region_a_idx, tcx); - let region_a_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion { + let region_a_param = tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: region_a_param.def_id, index: region_a_param.index, name: region_a_param.name, }); // Same for the region. let region_b_param = gat_generics.param_at(*region_b_idx, tcx); - let region_b_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion { + let region_b_param = tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: region_b_param.def_id, index: region_b_param.index, name: region_b_param.name, @@ -610,7 +610,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable>>( let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives( ty::OutlivesPredicate(region_a_param, region_b_param), )); - let clause = tcx.mk_predicate(ty::Binder::dummy(clause)); + let clause = tcx.mk().predicate(ty::Binder::dummy(clause)); bounds.insert(clause); } } @@ -1340,7 +1340,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id match param.kind { GenericParamDefKind::Lifetime => { // All regions are identity. - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) } GenericParamDefKind::Type { .. } => { @@ -1354,7 +1354,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id } } - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) } GenericParamDefKind::Const { .. } => { // If the param has a default, ... @@ -1367,7 +1367,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id } } - tcx.mk_param_from_def(param) + tcx.mk().param_from_def(param) } } }); @@ -1475,7 +1475,7 @@ fn check_fn_or_method<'tcx>( |idx| hir_decl.inputs.get(idx).map_or(hir_decl.output.span(), |arg: &hir::Ty<'_>| arg.span); sig.inputs_and_output = - tcx.mk_type_list_from_iter(sig.inputs_and_output.iter().enumerate().map(|(idx, ty)| { + tcx.mk().type_list_from_iter(sig.inputs_and_output.iter().enumerate().map(|(idx, ty)| { wfcx.normalize( arg_span(idx), Some(WellFormedLoc::Param { @@ -1742,7 +1742,7 @@ fn receiver_is_implemented<'tcx>( receiver_ty: Ty<'tcx>, ) -> bool { let tcx = wfcx.tcx(); - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(receiver_trait_def_id, [receiver_ty])); + let trait_ref = ty::Binder::dummy(tcx.mk().trait_ref(receiver_trait_def_id, [receiver_ty])); let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref); diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 5e8f69677cf3d..1814ec10f3a91 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -414,15 +414,17 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a); let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }; - check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ref(r_b, ty)) + check_mutbl(mt_a, mt_b, &|ty| tcx.mk().imm_ref(r_b, ty)) } (&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(mt_b)) => { let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; - check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty)) + check_mutbl(mt_a, mt_b, &|ty| tcx.mk().imm_ptr(ty)) } - (&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty)), + (&ty::RawPtr(mt_a), &ty::RawPtr(mt_b)) => { + check_mutbl(mt_a, mt_b, &|ty| tcx.mk().imm_ptr(ty)) + } (&ty::Adt(def_a, substs_a), &ty::Adt(def_b, substs_b)) if def_a.is_struct() && def_b.is_struct() => diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 47c47de8cedba..12c0899b918e4 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -333,7 +333,7 @@ fn emit_orphan_check_error<'tcx>( // That way if we had `Vec`, we will properly attribute the // problem to `Vec` and avoid confusing the user if they were to see // `MyType` in the error. - ty::Adt(def, _) => tcx.mk_adt(*def, ty::List::empty()), + ty::Adt(def, _) => tcx.mk().adt(*def, ty::List::empty()), _ => ty, }; let msg = |ty: &str, postfix: &str| { @@ -595,7 +595,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: } let self_ty_root = match self_ty.kind() { - ty::Adt(def, _) => tcx.mk_adt(*def, InternalSubsts::identity_for_item(tcx, def.did())), + ty::Adt(def, _) => tcx.mk().adt(*def, InternalSubsts::identity_for_item(tcx, def.did())), _ => unimplemented!("unexpected self ty {:?}", self_ty), }; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 604d54cafb532..1f8874d13a881 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -420,7 +420,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { item_segment, trait_ref.substs, ); - self.tcx().mk_projection(item_def_id, item_substs) + self.tcx().mk().projection(item_def_id, item_substs) } else { // There are no late-bound regions; we can just ignore the binder. let mut err = struct_span_err!( @@ -458,7 +458,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { self.tcx.replace_late_bound_regions_uncached( poly_trait_ref, |_| { - self.tcx.mk_re_early_bound(ty::EarlyBoundRegion { + self.tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: item_def_id, index: 0, name: Symbol::intern(<_name), @@ -905,7 +905,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> { } _ => bug!(), }; - tcx.mk_adt_def(def_id.to_def_id(), kind, variants, repr) + tcx.mk().adt_def(def_id.to_def_id(), kind, variants, repr) } fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { @@ -1145,7 +1145,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => { let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity(); let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).subst_identity()); - ty::Binder::dummy(tcx.mk_fn_sig( + ty::Binder::dummy(tcx.mk().fn_sig( inputs, ty, false, @@ -1324,7 +1324,7 @@ fn suggest_impl_trait<'tcx>( let item_ty = ocx.normalize( &ObligationCause::misc(span, def_id), param_env, - tcx.mk_projection(assoc_item_def_id, substs), + tcx.mk().projection(assoc_item_def_id, substs), ); // FIXME(compiler-errors): We may benefit from resolving regions here. if ocx.select_where_possible().is_empty() diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 7dce29cc0bbe3..311526128f72a 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -20,10 +20,9 @@ fn associated_type_bounds<'tcx>( ast_bounds: &'tcx [hir::GenericBound<'tcx>], span: Span, ) -> &'tcx [(ty::Predicate<'tcx>, Span)] { - let item_ty = tcx.mk_projection( - assoc_item_def_id, - InternalSubsts::identity_for_item(tcx, assoc_item_def_id), - ); + let item_ty = tcx + .mk() + .projection(assoc_item_def_id, InternalSubsts::identity_for_item(tcx, assoc_item_def_id)); let icx = ItemCtxt::new(tcx, assoc_item_def_id); let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds); @@ -101,9 +100,9 @@ pub(super) fn explicit_item_bounds( }) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); let item_ty = if *in_trait || rpitit_info.is_some() { - tcx.mk_projection(def_id, substs) + tcx.mk().projection(def_id, substs) } else { - tcx.mk_opaque(def_id, substs) + tcx.mk().opaque(def_id, substs) }; opaque_type_bounds(tcx, bounds_def_id, bounds, item_ty, *span) } @@ -115,7 +114,7 @@ pub(super) fn item_bounds( tcx: TyCtxt<'_>, def_id: DefId, ) -> ty::EarlyBinder<&'_ ty::List>> { - let bounds = tcx.mk_predicates_from_iter( + let bounds = tcx.mk().predicates_from_iter( util::elaborate_predicates( tcx, tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound), diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 2badd66e346f1..eea0aa05d1b63 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -181,7 +181,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let ct_ty = tcx.type_of(param.def_id.to_def_id()).subst_identity(); - let ct = tcx.mk_const(param_const, ct_ty); + let ct = tcx.mk().const_(param_const, ct_ty); let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::Clause::ConstArgHasType(ct, ct_ty), @@ -297,7 +297,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() }; - let dup_region = tcx.mk_re_early_bound(ty::EarlyBoundRegion { + let dup_region = tcx.mk().re_early_bound(ty::EarlyBoundRegion { def_id: dup_def, index: dup_index, name: duplicate.name.ident().name, @@ -634,7 +634,7 @@ pub(super) fn type_param_predicates( let param_owner = tcx.hir().ty_param_owner(def_id); let generics = tcx.generics_of(param_owner); let index = generics.param_def_id_to_index[&def_id.to_def_id()]; - let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id)); + let ty = tcx.mk().ty_param(index, tcx.hir().ty_param_name(def_id)); // Don't look for bounds where the type parameter isn't in scope. let parent = if item_def_id == param_owner.to_def_id() { diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index fe44fabf57df9..a11628b68add1 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -274,7 +274,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> Node::TraitItem(item) => match item.kind { TraitItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_fn_def(def_id.to_def_id(), substs) + tcx.mk().fn_def(def_id.to_def_id(), substs) } TraitItemKind::Const(ty, body_id) => body_id .and_then(|body_id| { @@ -291,7 +291,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> Node::ImplItem(item) => match item.kind { ImplItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_fn_def(def_id.to_def_id(), substs) + tcx.mk().fn_def(def_id.to_def_id(), substs) } ImplItemKind::Const(ty, body_id) => { if is_suggestable_infer_ty(ty) { @@ -346,12 +346,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> }, ItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_fn_def(def_id.to_def_id(), substs) + tcx.mk().fn_def(def_id.to_def_id(), substs) } ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { let def = tcx.adt_def(def_id); let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_adt(def, substs) + tcx.mk().adt(def, substs) } ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => { find_opaque_ty_constraints_for_tait(tcx, def_id) @@ -388,10 +388,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> Node::ForeignItem(foreign_item) => match foreign_item.kind { ForeignItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_fn_def(def_id.to_def_id(), substs) + tcx.mk().fn_def(def_id.to_def_id(), substs) } ForeignItemKind::Static(t, _) => icx.to_ty(t), - ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()), + ForeignItemKind::Type => tcx.mk().foreign(def_id.to_def_id()), }, Node::Ctor(def) | Node::Variant(Variant { data: def, .. }) => match def { @@ -400,7 +400,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder> } VariantData::Tuple(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - tcx.mk_fn_def(def_id.to_def_id(), substs) + tcx.mk().fn_def(def_id.to_def_id(), substs) } }, @@ -847,7 +847,7 @@ fn find_opaque_ty_constraints_for_rpit( // so we can just make the hidden type be `!`. // For backwards compatibility reasons, we fall back to // `()` until we the diverging default is changed. - tcx.mk_diverging_default() + tcx.mk().diverging_default() }) } }) @@ -874,7 +874,7 @@ fn infer_placeholder_type<'a>( fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = match *ty.kind() { ty::FnDef(def_id, substs) => { - self.tcx.mk_fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs)) + self.tcx.mk().fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs)) } _ => ty, }; diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 62abcbbdc9f6e..2ff648d5f8808 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -325,15 +325,15 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { expected_return_type = main_fnsig.output(); } else { // standard () main return type - expected_return_type = ty::Binder::dummy(tcx.mk_unit()); + expected_return_type = ty::Binder::dummy(tcx.mk().unit()); } if error { return; } - let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| { - tcx.mk_fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust) + let se_ty = tcx.mk().fn_ptr(expected_return_type.map_bound(|expected_return_type| { + tcx.mk().fn_sig([], expected_return_type, false, hir::Unsafety::Normal, Abi::Rust) })); require_same_types( @@ -344,7 +344,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { ObligationCauseCode::MainFunctionType, ), se_ty, - tcx.mk_fn_ptr(main_fnsig), + tcx.mk().fn_ptr(main_fnsig), ); } fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { @@ -402,8 +402,8 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { } } - let se_ty = tcx.mk_fn_ptr(ty::Binder::dummy(tcx.mk_fn_sig( - [tcx.types.isize, tcx.mk_imm_ptr(tcx.mk_imm_ptr(tcx.types.u8))], + let se_ty = tcx.mk().fn_ptr(ty::Binder::dummy(tcx.mk().fn_sig( + [tcx.types.isize, tcx.mk().imm_ptr(tcx.mk().imm_ptr(tcx.types.u8))], tcx.types.isize, false, hir::Unsafety::Normal, @@ -418,7 +418,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { ObligationCauseCode::StartFunctionType, ), se_ty, - tcx.mk_fn_ptr(tcx.fn_sig(start_def_id).subst_identity()), + tcx.mk().fn_ptr(tcx.fn_sig(start_def_id).subst_identity()), ); } _ => { diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index e19ef2ff3bf48..fe74925068ef0 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // us to give better error messages (pointing to a usually better // arm for inconsistent arms or to the whole match when a `()` type // is required). - Expectation::ExpectHasType(ety) if ety != self.tcx.mk_unit() => ety, + Expectation::ExpectHasType(ety) if ety != self.tcx.mk().unit() => ety, _ => self.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span: expr.span, diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index ecbe4a97dd967..5e50837bae4ff 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -232,7 +232,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let Some(trait_def_id) = opt_trait_def_id else { continue }; let opt_input_type = opt_arg_exprs.map(|arg_exprs| { - self.tcx.mk_tup_from_iter(arg_exprs.iter().map(|e| { + self.tcx.mk().tup_from_iter(arg_exprs.iter().map(|e| { self.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span: e.span, diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 316c2a7eeeb4b..9cc1bcf047366 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -391,7 +391,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { && fcx .try_coerce( self.expr, - fcx.tcx.mk_ref( + fcx.tcx.mk().ref_( fcx.tcx.lifetimes.re_erased, TypeAndMut { ty: expr_ty, mutbl }, ), @@ -408,7 +408,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { && fcx .try_coerce( self.expr, - fcx.tcx.mk_ref( + fcx.tcx.mk().ref_( expr_reg, TypeAndMut { ty: expr_ty, mutbl: Mutability::Mut }, ), @@ -426,7 +426,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { && fcx .try_coerce( self.expr, - fcx.tcx.mk_ref(reg, TypeAndMut { ty: self.expr_ty, mutbl }), + fcx.tcx.mk().ref_(reg, TypeAndMut { ty: self.expr_ty, mutbl }), self.cast_ty, AllowTwoPhase::No, None, @@ -439,7 +439,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { && fcx .try_coerce( self.expr, - fcx.tcx.mk_ref( + fcx.tcx.mk().ref_( fcx.tcx.lifetimes.re_erased, TypeAndMut { ty: self.expr_ty, mutbl }, ), @@ -765,7 +765,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { let res = fcx.try_coerce( self.expr, self.expr_ty, - fcx.tcx.mk_fn_ptr(f), + fcx.tcx.mk().fn_ptr(f), AllowTwoPhase::No, None, ); @@ -957,7 +957,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // from a region pointer to a vector. // Coerce to a raw pointer so that we generate AddressOf in MIR. - let array_ptr_type = fcx.tcx.mk_ptr(m_expr); + let array_ptr_type = fcx.tcx.mk().ptr(m_expr); fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None) .unwrap_or_else(|_| { bug!( diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs index bf8259ff70fa9..7a428eb8b04ef 100644 --- a/compiler/rustc_hir_typeck/src/check.rs +++ b/compiler/rustc_hir_typeck/src/check.rs @@ -61,11 +61,11 @@ pub(super) fn check_fn<'a, 'tcx>( fcx.require_type_is_sized(yield_ty, span, traits::SizedYieldType); yield_ty } else { - tcx.mk_unit() + tcx.mk().unit() }; // Resume type defaults to `()` if the generator has no argument. - let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| tcx.mk_unit()); + let resume_ty = fn_sig.inputs().get(0).copied().unwrap_or_else(|| tcx.mk().unit()); fcx.resume_yield_tys = Some((resume_ty, yield_ty)); } @@ -262,10 +262,10 @@ fn check_lang_start_fn<'tcx>( // for example `start`'s generic should be a type parameter let generics = tcx.generics_of(def_id); let fn_generic = generics.param_at(0, tcx); - let generic_ty = tcx.mk_ty_param(fn_generic.index, fn_generic.name); + let generic_ty = tcx.mk().ty_param(fn_generic.index, fn_generic.name); let expected_fn_sig = - tcx.mk_fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust); - let expected_ty = tcx.mk_fn_ptr(Binder::dummy(expected_fn_sig)); + tcx.mk().fn_sig([], generic_ty, false, hir::Unsafety::Normal, Abi::Rust); + let expected_ty = tcx.mk().fn_ptr(Binder::dummy(expected_fn_sig)); // we emit the same error to suggest changing the arg no matter what's wrong with the arg let emit_main_fn_arg_err = || { @@ -322,9 +322,9 @@ fn check_lang_start_fn<'tcx>( if !argv_is_okay { let inner_ptr_ty = - tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: tcx.types.u8 }); + tcx.mk().ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: tcx.types.u8 }); let expected_ty = - tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: inner_ptr_ty }); + tcx.mk().ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: inner_ptr_ty }); tcx.sess.emit_err(LangStartIncorrectParam { param_span: decl.inputs[2].span, param_num: 3, diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 773ac0e40c571..7f7ed65630246 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -116,7 +116,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, ); - return self.tcx.mk_generator( + return self.tcx.mk().generator( expr_def_id.to_def_id(), generator_substs.substs, movability, @@ -126,8 +126,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Tuple up the arguments and insert the resulting function type into // the `closures` table. let sig = bound_sig.map_bound(|sig| { - self.tcx.mk_fn_sig( - [self.tcx.mk_tup(sig.inputs())], + self.tcx.mk().fn_sig( + [self.tcx.mk().tup(sig.inputs())], sig.output(), sig.c_variadic, sig.unsafety, @@ -154,12 +154,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::ClosureSubstsParts { parent_substs, closure_kind_ty, - closure_sig_as_fn_ptr_ty: self.tcx.mk_fn_ptr(sig), + closure_sig_as_fn_ptr_ty: self.tcx.mk().fn_ptr(sig), tupled_upvars_ty, }, ); - self.tcx.mk_closure(expr_def_id.to_def_id(), closure_substs.substs) + self.tcx.mk().closure(expr_def_id.to_def_id(), closure_substs.substs) } /// Given the expected type, figures out what it can about this closure we @@ -186,7 +186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (sig, kind) } ty::Infer(ty::TyVar(vid)) => self.deduce_closure_signature_from_predicates( - self.tcx.mk_ty_var(self.root_var(vid)), + self.tcx.mk().ty_var(self.root_var(vid)), self.obligations_for_self_ty(vid).map(|obl| (obl.predicate, obl.cause.span)), ), ty::FnPtr(sig) => { @@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty); debug!(?ret_param_ty); - let sig = projection.rebind(self.tcx.mk_fn_sig( + let sig = projection.rebind(self.tcx.mk().fn_sig( input_tys, ret_param_ty, false, @@ -439,7 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // in this binder we are creating. assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST)); let bound_sig = expected_sig.sig.map_bound(|sig| { - self.tcx.mk_fn_sig( + self.tcx.mk().fn_sig( sig.inputs().iter().cloned(), sig.output(), sig.c_variadic, @@ -584,7 +584,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let inputs = inputs.into_iter().map(|ty| self.resolve_vars_if_possible(ty)); - expected_sigs.liberated_sig = self.tcx.mk_fn_sig( + expected_sigs.liberated_sig = self.tcx.mk().fn_sig( inputs, supplied_output_ty, expected_sigs.liberated_sig.c_variadic, @@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let result = ty::Binder::bind_with_vars( - self.tcx.mk_fn_sig( + self.tcx.mk().fn_sig( supplied_arguments, supplied_return, decl.c_variadic, @@ -812,7 +812,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { astconv.ast_ty_to_ty(&output); } - let result = ty::Binder::dummy(self.tcx.mk_fn_sig( + let result = ty::Binder::dummy(self.tcx.mk().fn_sig( supplied_arguments, err_ty, decl.c_variadic, diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 00b86890b33f4..c656f1d2c9c53 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -425,7 +425,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } r_borrow_var.unwrap() }; - let derefd_ty_a = self.tcx.mk_ref( + let derefd_ty_a = self.tcx.mk().ref_( r, TypeAndMut { ty: referent_ty, @@ -545,7 +545,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), target: self .tcx - .mk_ref(r_borrow, ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a }), + .mk() + .ref_(r_borrow, ty::TypeAndMut { mutbl: mutbl_b, ty: ty_a }), }, )) } @@ -556,7 +557,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Adjustment { kind: Adjust::Deref(None), target: ty_a }, Adjustment { kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)), - target: self.tcx.mk_ptr(ty::TypeAndMut { mutbl: mt_b, ty: ty_a }), + target: self.tcx.mk().ptr(ty::TypeAndMut { mutbl: mt_b, ty: ty_a }), }, )) } @@ -865,7 +866,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.at(&self.cause, self.param_env).normalize(a_sig); obligations.extend(o1); - let a_fn_pointer = self.tcx.mk_fn_ptr(a_sig); + let a_fn_pointer = self.tcx.mk().fn_ptr(a_sig); let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn( a_fn_pointer, a_sig, @@ -927,7 +928,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let closure_sig = substs_a.as_closure().sig(); let unsafety = fn_ty.unsafety(); let pointer_ty = - self.tcx.mk_fn_ptr(self.tcx.signature_unclosure(closure_sig, unsafety)); + self.tcx.mk().fn_ptr(self.tcx.signature_unclosure(closure_sig, unsafety)); debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty); self.unify_and( pointer_ty, @@ -955,7 +956,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { coerce_mutbls(mt_a.mutbl, mutbl_b)?; // Check that the types which they point at are compatible. - let a_unsafe = self.tcx.mk_ptr(ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty }); + let a_unsafe = self.tcx.mk().ptr(ty::TypeAndMut { mutbl: mutbl_b, ty: mt_a.ty }); // Although references and unsafe ptrs have the same // representation, we still register an Adjust::DerefRef so that // regionck knows that the region for `a` must be valid here. @@ -1157,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .map(|ok| self.register_infer_ok_obligations(ok))?; // Reify both sides and return the reified fn pointer type. - let fn_ptr = self.tcx.mk_fn_ptr(sig); + let fn_ptr = self.tcx.mk().fn_ptr(sig); let prev_adjustment = match prev_ty.kind() { ty::Closure(..) => Adjust::Pointer(PointerCast::ClosureFnPointer(a_sig.unsafety())), ty::FnDef(..) => Adjust::Pointer(PointerCast::ReifyFnPointer), @@ -1404,7 +1405,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { fcx, cause, None, - fcx.tcx.mk_unit(), + fcx.tcx.mk().unit(), Some(augment_error), label_unit_as_expected, ) diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 0ec10dc9ea32d..8a19d2858074f 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -272,9 +272,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { lt_op: |_| self.tcx.lifetimes.re_erased, ct_op: |c| c, ty_op: |t| match *t.kind() { - ty::Infer(ty::TyVar(_)) => self.tcx.mk_ty_var(ty::TyVid::from_u32(0)), - ty::Infer(ty::IntVar(_)) => self.tcx.mk_int_var(ty::IntVid { index: 0 }), - ty::Infer(ty::FloatVar(_)) => self.tcx.mk_float_var(ty::FloatVid { index: 0 }), + ty::Infer(ty::TyVar(_)) => self.tcx.mk().ty_var(ty::TyVid::from_u32(0)), + ty::Infer(ty::IntVar(_)) => self.tcx.mk().int_var(ty::IntVid { index: 0 }), + ty::Infer(ty::FloatVar(_)) => self.tcx.mk().float_var(ty::FloatVid { index: 0 }), _ => t, }, }; @@ -1269,10 +1269,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // ``` let ref_ty = match mutability { hir::Mutability::Mut => { - self.tcx.mk_mut_ref(self.tcx.lifetimes.re_static, checked_ty) + self.tcx.mk().mut_ref(self.tcx.lifetimes.re_static, checked_ty) } hir::Mutability::Not => { - self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, checked_ty) + self.tcx.mk().imm_ref(self.tcx.lifetimes.re_static, checked_ty) } }; if self.can_coerce(ref_ty, expected) { diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 7fc4ccb04ee0b..b719aaa3e7de6 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -365,7 +365,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); let referent_ty = self.check_expr_with_expectation(expr, expected_inner); self.require_type_is_sized(referent_ty, expr.span, traits::SizedBoxType); - self.tcx.mk_box(referent_ty) + self.tcx.mk().box_(referent_ty) } fn check_expr_unary( @@ -455,7 +455,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ if tm.ty.references_error() => self.tcx.ty_error_misc(), hir::BorrowKind::Raw => { self.check_named_place_expr(oprnd); - self.tcx.mk_ptr(tm) + self.tcx.mk().ptr(tm) } hir::BorrowKind::Ref => { // Note: at this point, we cannot say what the best lifetime @@ -473,7 +473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // whose address was taken can actually be made to live as long // as it needs to live. let region = self.next_region_var(infer::AddrOfRegion(expr.span)); - self.tcx.mk_ref(region, tm) + self.tcx.mk().ref_(region, tm) } } } @@ -642,7 +642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { // Otherwise, this is a break *without* a value. That's // always legal, and is equivalent to `break ()`. - e_ty = tcx.mk_unit(); + e_ty = tcx.mk().unit(); cause = self.misc(expr.span); } @@ -1051,7 +1051,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The expected type is `bool` but this will result in `()` so we can reasonably // say that the user intended to write `lhs == rhs` instead of `lhs = rhs`. // The likely cause of this is `if foo = bar { .. }`. - let actual_ty = self.tcx.mk_unit(); + let actual_ty = self.tcx.mk().unit(); let mut err = self.demand_suptype_diag(expr.span, expected_ty, actual_ty).unwrap(); let lhs_ty = self.check_expr(&lhs); let rhs_ty = self.check_expr(&rhs); @@ -1158,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Err(guar) = (lhs_ty, rhs_ty).error_reported() { self.tcx.ty_error(guar) } else { - self.tcx.mk_unit() + self.tcx.mk().unit() } } @@ -1213,7 +1213,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // [1] self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break"); } - ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit()) + ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk().unit()) } /// Checks a method call. @@ -1336,7 +1336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let array_len = args.len() as u64; self.suggest_array_len(expr, array_len); - self.tcx.mk_array(element_ty, array_len) + self.tcx.mk().array(element_ty, array_len) } fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { @@ -1429,7 +1429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.check_repeat_element_needs_copy_bound(element, count, element_ty); - tcx.mk_array_with_const_len(t, count) + tcx.mk().array_with_const_len(t, count) } fn check_repeat_element_needs_copy_bound( @@ -1492,7 +1492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => self.check_expr_with_expectation(&e, NoExpectation), }); - let tuple = self.tcx.mk_tup_from_iter(elt_ts_iter); + let tuple = self.tcx.mk().tup_from_iter(elt_ts_iter); if let Err(guar) = tuple.error_reported() { self.tcx.ty_error(guar) } else { @@ -1722,7 +1722,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `MyStruct<'a, _, F2, C>`, as opposed to just `_`... // This is important to allow coercions to happen in // `other_struct` itself. See `coerce-in-base-expr.rs`. - let fresh_base_ty = self.tcx.mk_adt(*adt, fresh_substs); + let fresh_base_ty = self.tcx.mk().adt(*adt, fresh_substs); self.check_expr_has_type_or_error( base_expr, self.resolve_vars_if_possible(fresh_base_ty), @@ -2883,14 +2883,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // information. Hence, we check the source of the yield expression here and check its // value's type against `()` (this check should always hold). None if src.is_await() => { - self.check_expr_coercable_to_type(&value, self.tcx.mk_unit(), None); - self.tcx.mk_unit() + self.check_expr_coercable_to_type(&value, self.tcx.mk().unit(), None); + self.tcx.mk().unit() } _ => { self.tcx.sess.emit_err(YieldExprOutsideOfGenerator { span: expr.span }); // Avoid expressions without types during writeback (#78653). self.check_expr(value); - self.tcx.mk_unit() + self.tcx.mk().unit() } } } @@ -2917,11 +2917,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.structurally_resolved_type(expr.span, ty); match *ty.kind() { ty::FnDef(..) => { - let fnptr_ty = self.tcx.mk_fn_ptr(ty.fn_sig(self.tcx)); + let fnptr_ty = self.tcx.mk().fn_ptr(ty.fn_sig(self.tcx)); self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No); } ty::Ref(_, base_ty, mutbl) => { - let ptr_ty = self.tcx.mk_ptr(ty::TypeAndMut { ty: base_ty, mutbl }); + let ptr_ty = self.tcx.mk().ptr(ty::TypeAndMut { ty: base_ty, mutbl }); self.demand_coerce(expr, ty, ptr_ty, None, AllowTwoPhase::No); } _ => {} @@ -2956,7 +2956,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if asm.options.contains(ast::InlineAsmOptions::NORETURN) { self.tcx.types.never } else { - self.tcx.mk_unit() + self.tcx.mk().unit() } } } diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index b7ae621c6859f..734de8cf2a5d0 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -287,7 +287,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { let mut diverging_fallback = FxHashMap::default(); diverging_fallback.reserve(diverging_vids.len()); for &diverging_vid in &diverging_vids { - let diverging_ty = self.tcx.mk_ty_var(diverging_vid); + let diverging_ty = self.tcx.mk().ty_var(diverging_vid); let root_vid = self.root_var(diverging_vid); let can_reach_non_diverging = coercion_graph .depth_first_search(root_vid) @@ -334,7 +334,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { diverging_fallback.insert(diverging_ty, self.tcx.types.unit); } else { debug!("fallback to ! - all diverging: {:?}", diverging_vid); - diverging_fallback.insert(diverging_ty, self.tcx.mk_diverging_default()); + diverging_fallback.insert(diverging_ty, self.tcx.mk().diverging_default()); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index ac73cd7cc6e17..c013759b0f4e5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -552,7 +552,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx, self.tcx.typeck_root_def_id(expr_def_id.to_def_id()), ); - let witness = self.tcx.mk_generator_witness_mir(expr_def_id.to_def_id(), substs); + let witness = self.tcx.mk().generator_witness_mir(expr_def_id.to_def_id(), substs); // Unify `interior` with `witness` and collect all the resulting obligations. let span = self.tcx.hir().body(body_id).value.span; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index ec14bd3c6f43e..e0afdd557ce4e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -476,7 +476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of // that struct type. let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_or_alias_def_id) { - self.tcx.mk_trait_ref( + self.tcx.mk().trait_ref( obligation.impl_or_alias_def_id, ty::InternalSubsts::identity_for_item(self.tcx, obligation.impl_or_alias_def_id), ) @@ -633,9 +633,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Err(expr); } - let param_to_point_at_in_struct = self.tcx.mk_param_from_def( - struct_generic_parameters.param_at(drill_generic_index, self.tcx), - ); + let param_to_point_at_in_struct = self + .tcx + .mk() + .param_from_def(struct_generic_parameters.param_at(drill_generic_index, self.tcx)); // We make 3 steps: // Suppose we have a type like @@ -756,9 +757,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Err(expr); } - let param_to_point_at_in_struct = self.tcx.mk_param_from_def( - struct_generic_parameters.param_at(drill_generic_index, self.tcx), - ); + let param_to_point_at_in_struct = self + .tcx + .mk() + .param_from_def(struct_generic_parameters.param_at(drill_generic_index, self.tcx)); // We make 3 steps: // Suppose we have a type like diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index ea54b76bdec96..50c7384ab5061 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let err_inputs = match tuple_arguments { DontTupleArguments => err_inputs, - TupleArguments => vec![self.tcx.mk_tup(&err_inputs)], + TupleArguments => vec![self.tcx.mk().tup(&err_inputs)], }; self.check_argument_types( @@ -419,7 +419,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { variadic_error(tcx.sess, arg.span, arg_ty, "c_uint"); } ty::FnDef(..) => { - let ptr_ty = self.tcx.mk_fn_ptr(arg_ty.fn_sig(self.tcx)); + let ptr_ty = self.tcx.mk().fn_ptr(arg_ty.fn_sig(self.tcx)); let ptr_ty = self.resolve_vars_if_possible(ptr_ty); variadic_error(tcx.sess, arg.span, arg_ty, &ptr_ty.to_string()); } @@ -641,7 +641,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len() { // Wrap up the N provided arguments starting at this position in a tuple. - let provided_as_tuple = tcx.mk_tup_from_iter( + let provided_as_tuple = tcx.mk().tup_from_iter( provided_arg_tys.iter().map(|(ty, _)| *ty).skip(mismatch_idx).take(tys.len()), ); @@ -1258,14 +1258,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; match lit.node { - ast::LitKind::Str(..) => tcx.mk_static_str(), - ast::LitKind::ByteStr(ref v, _) => { - tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_array(tcx.types.u8, v.len() as u64)) - } + ast::LitKind::Str(..) => tcx.mk().static_str(), + ast::LitKind::ByteStr(ref v, _) => tcx + .mk() + .imm_ref(tcx.lifetimes.re_static, tcx.mk().array(tcx.types.u8, v.len() as u64)), ast::LitKind::Byte(_) => tcx.types.u8, ast::LitKind::Char(_) => tcx.types.char, - ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(ty::int_ty(t)), - ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(ty::uint_ty(t)), + ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk().mach_int(ty::int_ty(t)), + ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => { + tcx.mk().mach_uint(ty::uint_ty(t)) + } ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => { let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() { ty::Int(_) | ty::Uint(_) => Some(ty), @@ -1277,7 +1279,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { opt_ty.unwrap_or_else(|| self.next_int_var()) } ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => { - tcx.mk_mach_float(ty::float_ty(t)) + tcx.mk().mach_float(ty::float_ty(t)) } ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => { let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() { @@ -1447,7 +1449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::StmtKind::Item(_) => {} hir::StmtKind::Expr(ref expr) => { // Check with expected type of `()`. - self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err| { + self.check_expr_has_type_or_error(&expr, self.tcx.mk().unit(), |err| { if expr.can_have_side_effects() { self.suggest_semicolon_at_end(expr.span, err); } @@ -1470,7 +1472,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) { - let unit = self.tcx.mk_unit(); + let unit = self.tcx.mk().unit(); let ty = self.check_block_with_expected(blk, ExpectHasType(unit)); // if the block produces a `!` value, that can always be @@ -1882,7 +1884,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { // Look for a user-provided impl of a `Fn` trait, and point to it. let new_def_id = self.probe(|_| { - let trait_ref = self.tcx.mk_trait_ref( + let trait_ref = self.tcx.mk().trait_ref( call_kind.to_def_id(self.tcx), [ callee_ty, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 1dea3e6f900d4..b9a318c94f637 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -302,7 +302,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { trait_ref.substs, ); - self.tcx().mk_projection(item_def_id, item_substs) + self.tcx().mk().projection(item_def_id, item_substs) } fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option> { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 690d8a238261a..aa77c69116169 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -451,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if !expected.is_box() || found.is_box() { return false; } - let boxed_found = self.tcx.mk_box(found); + let boxed_found = self.tcx.mk().box_(found); if self.can_coerce(boxed_found, expected) { err.multipart_suggestion( "store this in the heap by calling `Box::new`", @@ -530,9 +530,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if pin_did.is_none() || self.tcx.lang_items().owned_box().is_none() { return false; } - let box_found = self.tcx.mk_box(found); - let pin_box_found = self.tcx.mk_lang_item(box_found, LangItem::Pin).unwrap(); - let pin_found = self.tcx.mk_lang_item(found, LangItem::Pin).unwrap(); + let box_found = self.tcx.mk().box_(found); + let pin_box_found = self.tcx.mk().lang_item(box_found, LangItem::Pin).unwrap(); + let pin_found = self.tcx.mk().lang_item(found, LangItem::Pin).unwrap(); match expected.kind() { ty::Adt(def, _) if Some(def.did()) == pin_did => { if self.can_coerce(pin_box_found, expected) { @@ -1094,7 +1094,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx, self.misc(expr.span), self.param_env, - ty::Binder::dummy(self.tcx.mk_trait_ref( + ty::Binder::dummy(self.tcx.mk().trait_ref( into_def_id, [expr_ty, expected_ty] )), @@ -1432,7 +1432,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..))) // Check that we're in fact trying to clone into the expected type && self.can_coerce(*pointee_ty, expected_ty) - && let trait_ref = ty::Binder::dummy(self.tcx.mk_trait_ref(clone_trait_did, [expected_ty])) + && let trait_ref = ty::Binder::dummy(self.tcx.mk().trait_ref(clone_trait_did, [expected_ty])) // And the expected type doesn't implement `Clone` && !self.predicate_must_hold_considering_regions(&traits::Obligation::new( self.tcx, diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 2e41c2041f888..74a4f421388b6 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -271,7 +271,7 @@ pub fn resolve_interior<'a, 'tcx>( }, _ => mk_bound_region(None), }; - let r = fcx.tcx.mk_re_late_bound(current_depth, br); + let r = fcx.tcx.mk().re_late_bound(current_depth, br); r }); captured_tys.insert(ty).then(|| { @@ -300,7 +300,7 @@ pub fn resolve_interior<'a, 'tcx>( let var = ty::BoundVar::from_usize(bound_vars.len()); bound_vars.push(ty::BoundVariableKind::Region(kind)); counter += 1; - fcx.tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var, kind }) + fcx.tcx.mk().re_late_bound(ty::INNERMOST, ty::BoundRegion { var, kind }) }, types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"), consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"), @@ -311,10 +311,10 @@ pub fn resolve_interior<'a, 'tcx>( }; // Extract type components to build the witness type. - let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty)); + let type_list = fcx.tcx.mk().type_list_from_iter(type_causes.iter().map(|cause| cause.ty)); let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars); let witness = - fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone())); + fcx.tcx.mk().generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone())); drop(typeck_results); // Store the generator types and spans into the typeck results for this generator. @@ -359,7 +359,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { let ty = self.interior_visitor.fcx.typeck_results.borrow().node_type(id); let tcx = self.interior_visitor.fcx.tcx; - let ty = tcx.mk_ref( + let ty = tcx.mk().ref_( // Use `ReErased` as `resolve_interior` is going to replace all the // regions anyway. tcx.lifetimes.re_erased, diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index 4d3969d28aa2d..4a19b1391a684 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -280,7 +280,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let base = if let Some(deref) = overloaded { let ref_ty = self .tcx() - .mk_ref(deref.region, ty::TypeAndMut { ty: target, mutbl: deref.mutbl }); + .mk() + .ref_(deref.region, ty::TypeAndMut { ty: target, mutbl: deref.mutbl }); self.cat_rvalue(expr.hir_id, expr.span, ref_ty) } else { previous()? @@ -489,7 +490,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let ty::Ref(region, _, mutbl) = *base_ty.kind() else { span_bug!(expr.span, "cat_overloaded_place: base is not a reference"); }; - let ref_ty = self.tcx().mk_ref(region, ty::TypeAndMut { ty: place_ty, mutbl }); + let ref_ty = self.tcx().mk().ref_(region, ty::TypeAndMut { ty: place_ty, mutbl }); let base = self.cat_rvalue(expr.hir_id, expr.span, ref_ty); self.cat_deref(expr, base) diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 169f128e0a003..d501d528460c2 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -98,7 +98,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // in scope, and if we find another method which can be used, we'll output an // appropriate hint suggesting to import the trait. let filler_substs = rcvr_substs - .extend_to(self.tcx, pick.item.def_id, |def, _| self.tcx.mk_param_from_def(def)); + .extend_to(self.tcx, pick.item.def_id, |def, _| self.tcx.mk().param_from_def(def)); let illegal_sized_bound = self.predicates_require_illegal_sized_bound( self.tcx.predicates_of(pick.item.def_id).instantiate(self.tcx, filler_substs), ); @@ -128,7 +128,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // a custom error in that case. if illegal_sized_bound.is_none() { self.add_obligations( - self.tcx.mk_fn_ptr(method_sig), + self.tcx.mk().fn_ptr(method_sig), all_substs, method_predicates, pick.item.def_id, @@ -172,7 +172,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // Type we're wrapping in a reference, used later for unsizing let base_ty = target; - target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target }); + target = self.tcx.mk().ref_(region, ty::TypeAndMut { mutbl, ty: target }); // Method call receivers are the primary use case // for two-phase borrows. @@ -185,7 +185,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { if unsize { let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() { - self.tcx.mk_slice(*elem_ty) + self.tcx.mk().slice(*elem_ty) } else { bug!( "AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}", @@ -194,7 +194,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { }; target = self .tcx - .mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty }); + .mk() + .ref_(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty }); adjustments .push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target }); } @@ -203,7 +204,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { target = match target.kind() { &ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => { assert!(mutbl.is_mut()); - self.tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty }) + self.tcx.mk().ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty }) } other => panic!("Cannot adjust receiver type {:?} to const ptr", other), }; diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 0456dd56c340e..3200463b8ee81 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -206,7 +206,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Ref(region, t_type, mutability) = self_ty.kind() { let trait_type = self .tcx - .mk_ref(*region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }); + .mk() + .ref_(*region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }); // We probe again to see if there might be a borrow mutability discrepancy. match self.lookup_probe( segment.ident, @@ -317,7 +318,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.var_for_def(cause.span, param) }); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs); + let trait_ref = self.tcx.mk().trait_ref(trait_def_id, substs); // Construct an obligation let poly_trait_ref = ty::Binder::dummy(trait_ref); @@ -443,7 +444,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )); // Also add an obligation for the method type being well-formed. - let method_ty = tcx.mk_fn_ptr(ty::Binder::dummy(fn_sig)); + let method_ty = tcx.mk().fn_ptr(ty::Binder::dummy(fn_sig)); debug!( "lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}", method_ty, obligation diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 3254a93034236..1e19abf2baa27 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -542,7 +542,7 @@ fn method_autoderef_steps<'tcx>( steps.push(CandidateStep { self_ty: infcx.make_query_response_ignoring_pending_obligations( inference_vars, - infcx.tcx.mk_slice(*elem_ty), + infcx.tcx.mk().slice(*elem_ty), ), autoderefs: dereferences, // this could be from an unsafe deref if we had @@ -949,7 +949,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { ) { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id); let trait_substs = self.fresh_item_substs(trait_def_id); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs); + let trait_ref = self.tcx.mk().trait_ref(trait_def_id, trait_substs); if self.tcx.is_trait_alias(trait_def_id) { // For trait aliases, recursively assume all explicitly named traits are relevant @@ -1196,7 +1196,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // In general, during probing we erase regions. let region = tcx.lifetimes.re_erased; - let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl }); + let autoref_ty = tcx.mk().ref_(region, ty::TypeAndMut { ty: self_ty, mutbl }); self.pick_method(autoref_ty, unstable_candidates).map(|r| { r.map(|mut pick| { pick.autoderefs = step.autoderefs; @@ -1226,7 +1226,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }; let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }; - let const_ptr_ty = self.tcx.mk_ptr(const_self_ty); + let const_ptr_ty = self.tcx.mk().ptr(const_self_ty); self.pick_method(const_ptr_ty, unstable_candidates).map(|r| { r.map(|mut pick| { pick.autoderefs = step.autoderefs; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 50f2b71250c01..363ec5c948a7d 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.autoderef(span, ty).any(|(ty, _)| { info!("check deref {:?} impl FnOnce", ty); self.probe(|_| { - let trait_ref = tcx.mk_trait_ref( + let trait_ref = tcx.mk().trait_ref( fn_once, [ ty, @@ -206,7 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() { if needs_mut { - let trait_type = self.tcx.mk_ref( + let trait_type = self.tcx.mk().ref_( *region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }, ); @@ -595,13 +595,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `::Item = String`. let projection_ty = pred.skip_binder().projection_ty; - let substs_with_infer_self = tcx.mk_substs_from_iter( - iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) + let substs_with_infer_self = tcx.mk().substs_from_iter( + iter::once(tcx.mk().ty_var(ty::TyVid::from_u32(0)).into()) .chain(projection_ty.substs.iter().skip(1)), ); let quiet_projection_ty = - tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self); + tcx.mk().alias_ty(projection_ty.def_id, substs_with_infer_self); let term = pred.skip_binder().term; @@ -1273,7 +1273,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Adt(def, substs) = target_ty.kind() { // If there are any inferred arguments, (`{integer}`), we should replace // them with underscores to allow the compiler to infer them - let infer_substs = self.tcx.mk_substs_from_iter(substs.into_iter().map(|arg| { + let infer_substs = self.tcx.mk().substs_from_iter(substs.into_iter().map(|arg| { if !arg.is_suggestable(self.tcx, true) { has_unsuggestable_args = true; match arg.unpack() { @@ -2342,8 +2342,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // just this list. for (rcvr_ty, post) in &[ (rcvr_ty, ""), - (self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "), - (self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"), + (self.tcx.mk().mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "), + (self.tcx.mk().imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"), ] { match self.lookup_probe_for_diagnostic( item_name, @@ -2378,10 +2378,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } for (rcvr_ty, pre) in &[ - (self.tcx.mk_lang_item(*rcvr_ty, LangItem::OwnedBox), "Box::new"), - (self.tcx.mk_lang_item(*rcvr_ty, LangItem::Pin), "Pin::new"), - (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"), - (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"), + (self.tcx.mk().lang_item(*rcvr_ty, LangItem::OwnedBox), "Box::new"), + (self.tcx.mk().lang_item(*rcvr_ty, LangItem::Pin), "Pin::new"), + (self.tcx.mk().diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"), + (self.tcx.mk().diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"), ] { if let Some(new_rcvr_t) = *rcvr_ty && let Ok(pick) = self.lookup_probe_for_diagnostic( diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 37783bc91bb8c..6bec8f4d8929e 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -40,7 +40,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) { self.enforce_builtin_binop_types(lhs.span, lhs_ty, rhs.span, rhs_ty, op); - self.tcx.mk_unit() + self.tcx.mk().unit() } else { return_ty }; diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 11ff65d0c373a..59caf568db650 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -398,7 +398,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .borrow_mut() .treat_byte_string_as_slice .insert(lt.hir_id.local_id); - pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8)); + pat_ty = tcx.mk().imm_ref(tcx.lifetimes.re_static, tcx.mk().slice(tcx.types.u8)); } } @@ -407,7 +407,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expected = self.resolve_vars_if_possible(expected); pat_ty = match expected.kind() { ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().string() => expected, - ty::Str => tcx.mk_static_str(), + ty::Str => tcx.mk().static_str(), _ => pat_ty, }; } @@ -1295,8 +1295,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span }, ) }); - let element_tys = tcx.mk_type_list_from_iter(element_tys_iter); - let pat_ty = tcx.mk_tup(element_tys); + let element_tys = tcx.mk().type_list_from_iter(element_tys_iter); + let pat_ty = tcx.mk().tup(element_tys); if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) { let reported = err.emit(); // Walk subpatterns with an expected type of `err` in this case to silence @@ -1305,7 +1305,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { self.check_pat(elem, tcx.ty_error(reported), def_bm, ti); } - tcx.mk_tup_from_iter(element_tys_iter) + tcx.mk().tup_from_iter(element_tys_iter) } else { for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { self.check_pat(elem, element_tys[i], def_bm, ti); @@ -1932,7 +1932,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind: TypeVariableOriginKind::TypeInference, span: inner.span, }); - let box_ty = tcx.mk_box(inner_ty); + let box_ty = tcx.mk().box_(inner_ty); self.demand_eqtype_pat(span, expected, box_ty, ti); (box_ty, inner_ty) } @@ -2000,7 +2000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn new_ref_ty(&self, span: Span, mutbl: hir::Mutability, ty: Ty<'tcx>) -> Ty<'tcx> { let region = self.next_region_var(infer::PatternRegion(span)); let mt = ty::TypeAndMut { ty, mutbl }; - self.tcx.mk_ref(region, mt) + self.tcx.mk().ref_(region, mt) } /// Type check a slice pattern. @@ -2089,7 +2089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if let Some(pat_len) = len.checked_sub(min_len) { // The variable-length pattern was there, // so it has an array type with the remaining elements left as its size... - return (Some(self.tcx.mk_array(element_ty, pat_len)), arr_ty); + return (Some(self.tcx.mk().array(element_ty, pat_len)), arr_ty); } else { // ...however, in this case, there were no remaining elements. // That is, the slice pattern requires more than the array type offers. @@ -2098,7 +2098,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if slice.is_none() { // We have a pattern with a fixed length, // which we can use to infer the length of the array. - let updated_arr_ty = self.tcx.mk_array(element_ty, min_len); + let updated_arr_ty = self.tcx.mk().array(element_ty, min_len); self.demand_eqtype(span, updated_arr_ty, arr_ty); return (None, updated_arr_ty); } else { diff --git a/compiler/rustc_hir_typeck/src/place_op.rs b/compiler/rustc_hir_typeck/src/place_op.rs index 2cca45de5e971..fd4a76ec51cac 100644 --- a/compiler/rustc_hir_typeck/src/place_op.rs +++ b/compiler/rustc_hir_typeck/src/place_op.rs @@ -138,7 +138,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if unsize { // We only unsize arrays here. if let ty::Array(element_ty, _) = adjusted_ty.kind() { - self_ty = self.tcx.mk_slice(*element_ty); + self_ty = self.tcx.mk().slice(*element_ty); } else { continue; } @@ -162,7 +162,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { adjustments.push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), - target: self.tcx.mk_ref( + target: self.tcx.mk().ref_( *region, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty: adjusted_ty }, ), @@ -427,7 +427,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)); adjustment.target = self .tcx - .mk_ref(*region, ty::TypeAndMut { ty: source, mutbl: mutbl.into() }); + .mk() + .ref_(*region, ty::TypeAndMut { ty: source, mutbl: mutbl.into() }); } source = adjustment.target; } diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 4a432328c4d1b..785c139cbc6ad 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -301,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Build a tuple (U0..Un) of the final upvar types U0..Un // and unify the upvar tuple type in the closure with it: - let final_tupled_upvars_type = self.tcx.mk_tup(&final_upvar_tys); + let final_tupled_upvars_type = self.tcx.mk().tup(&final_upvar_tys); self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type); let fake_reads = delegate @@ -315,8 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.typeck_results.borrow_mut().closure_size_eval.insert( closure_def_id, ClosureSizeProfileData { - before_feature_tys: self.tcx.mk_tup(&before_feature_tys), - after_feature_tys: self.tcx.mk_tup(&after_feature_tys), + before_feature_tys: self.tcx.mk().tup(&before_feature_tys), + after_feature_tys: self.tcx.mk().tup(&after_feature_tys), }, ); } @@ -1671,7 +1671,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>( match capture_kind { ty::UpvarCapture::ByValue => ty, ty::UpvarCapture::ByRef(kind) => { - tcx.mk_ref(region.unwrap(), ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() }) + tcx.mk().ref_(region.unwrap(), ty::TypeAndMut { ty: ty, mutbl: kind.to_mutbl_lossy() }) } } } diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 7d9bae735e55d..469d32b7d2d9f 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -447,8 +447,8 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> { a: Self, b: Self, ) -> TypeTrace<'tcx> { - let a_ty = tcx.mk_projection(a.def_id, a.substs); - let b_ty = tcx.mk_projection(b.def_id, b.substs); + let a_ty = tcx.mk().projection(a.def_id, a.substs); + let b_ty = tcx.mk().projection(b.def_id, b.substs); TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())), diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 8ac82653c0ee8..9ac5b59cd9a04 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -382,7 +382,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { // any equated inference vars correctly! let root_vid = self.infcx.root_var(vid); if root_vid != vid { - t = self.infcx.tcx.mk_ty_var(root_vid); + t = self.infcx.tcx.mk().ty_var(root_vid); vid = root_vid; } @@ -497,7 +497,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { // any equated inference vars correctly! let root_vid = self.infcx.root_const_var(vid); if root_vid != vid { - ct = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), ct.ty()); + ct = self.infcx.tcx.mk().const_(ty::InferConst::Var(root_vid), ct.ty()); vid = root_vid; } @@ -771,7 +771,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { ) -> ty::Region<'tcx> { let var = self.canonical_var(info, r.into()); let br = ty::BoundRegion { var, kind: ty::BrAnon(var.as_u32(), None) }; - self.interner().mk_re_late_bound(self.binder_index, br) + self.interner().mk().re_late_bound(self.binder_index, br) } /// Given a type variable `ty_var` of the given kind, first check @@ -785,7 +785,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { self.fold_ty(bound_to) } else { let var = self.canonical_var(info, ty_var.into()); - self.interner().mk_bound(self.binder_index, var.into()) + self.interner().mk().bound(self.binder_index, var.into()) } } @@ -804,10 +804,9 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { self.fold_const(bound_to) } else { let var = self.canonical_var(info, const_var.into()); - self.interner().mk_const( - ty::ConstKind::Bound(self.binder_index, var), - self.fold_ty(const_var.ty()), - ) + self.interner() + .mk() + .const_(ty::ConstKind::Bound(self.binder_index, var), self.fold_ty(const_var.ty())) } } } diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index ce230afdab3ce..9aca0e88d364b 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -88,7 +88,7 @@ impl<'tcx> InferCtxt<'tcx> { universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex, ) -> CanonicalVarValues<'tcx> { CanonicalVarValues { - var_values: self.tcx.mk_substs_from_iter( + var_values: self.tcx.mk().substs_from_iter( variables .iter() .map(|info| self.instantiate_canonical_var(span, info, &universe_map)), @@ -128,7 +128,7 @@ impl<'tcx> InferCtxt<'tcx> { CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => { let universe_mapped = universe_map(universe); let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name }; - self.tcx.mk_placeholder(placeholder_mapped).into() + self.tcx.mk().placeholder(placeholder_mapped).into() } CanonicalVarKind::Region(ui) => self @@ -141,7 +141,7 @@ impl<'tcx> InferCtxt<'tcx> { CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => { let universe_mapped = universe_map(universe); let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name }; - self.tcx.mk_re_placeholder(placeholder_mapped).into() + self.tcx.mk().re_placeholder(placeholder_mapped).into() } CanonicalVarKind::Const(ui, ty) => self @@ -155,7 +155,7 @@ impl<'tcx> InferCtxt<'tcx> { CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => { let universe_mapped = universe_map(universe); let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name }; - self.tcx.mk_const(placeholder_mapped, ty).into() + self.tcx.mk().const_(placeholder_mapped, ty).into() } } } diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 90e89a187822d..da2f1375e6f35 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -160,7 +160,7 @@ impl<'tcx> InferCtxt<'tcx> { .opaque_types .iter() .map(|&(k, ref v)| { - (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty) + (self.tcx.mk().opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty) }) .collect() } @@ -168,7 +168,7 @@ impl<'tcx> InferCtxt<'tcx> { fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> { std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types) .into_iter() - .map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty)) + .map(|(k, v)| (self.tcx.mk().opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty)) .collect() } @@ -484,7 +484,7 @@ impl<'tcx> InferCtxt<'tcx> { // given variable in the loop above, use that. Otherwise, use // a fresh inference variable. let result_subst = CanonicalVarValues { - var_values: self.tcx.mk_substs_from_iter( + var_values: self.tcx.mk().substs_from_iter( query_response.variables.iter().enumerate().map(|(index, info)| { if info.is_existential() { match opt_values[BoundVar::new(index)] { @@ -649,13 +649,13 @@ pub fn make_query_region_constraints<'tcx>( // Swap regions because we are going from sub (<=) to outlives // (>=). Constraint::VarSubVar(v1, v2) => { - ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), tcx.mk_re_var(v1)) + ty::OutlivesPredicate(tcx.mk().re_var(v2).into(), tcx.mk().re_var(v1)) } Constraint::VarSubReg(v1, r2) => { - ty::OutlivesPredicate(r2.into(), tcx.mk_re_var(v1)) + ty::OutlivesPredicate(r2.into(), tcx.mk().re_var(v1)) } Constraint::RegSubVar(r1, v2) => { - ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), r1) + ty::OutlivesPredicate(tcx.mk().re_var(v2).into(), r1) } Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1), }; @@ -699,7 +699,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { } fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> { - self.infcx.tcx.mk_re_placeholder(placeholder) + self.infcx.tcx.mk().re_placeholder(placeholder) } fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> { diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index a2332797e8680..493198e4ab7e2 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -327,8 +327,8 @@ impl<'tcx> InferCtxt<'tcx> { .unify_var_value(vid, Some(val)) .map_err(|e| int_unification_error(vid_is_expected, e))?; match val { - IntType(v) => Ok(self.tcx.mk_mach_int(v)), - UintType(v) => Ok(self.tcx.mk_mach_uint(v)), + IntType(v) => Ok(self.tcx.mk().mach_int(v)), + UintType(v) => Ok(self.tcx.mk().mach_uint(v)), } } @@ -343,7 +343,7 @@ impl<'tcx> InferCtxt<'tcx> { .float_unification_table() .unify_var_value(vid, Some(ty::FloatVarValue(val))) .map_err(|e| float_unification_error(vid_is_expected, e))?; - Ok(self.tcx.mk_mach_float(val)) + Ok(self.tcx.mk().mach_float(val)) } } @@ -703,7 +703,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { .borrow_mut() .type_variables() .new_var(self.for_universe, origin); - let u = self.tcx().mk_ty_var(new_var_id); + let u = self.tcx().mk().ty_var(new_var_id); // Record that we replaced `vid` with `new_var_id` as part of a generalization // operation. This is needed to detect cyclic types. To see why, see the @@ -723,7 +723,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { } ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => { let s = self.relate(substs, substs)?; - Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) }) + Ok(if s == substs { t } else { self.infcx.tcx.mk().opaque(def_id, s) }) } _ => relate::super_relate_tys(self, t, t), }?; @@ -803,7 +803,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { origin: var_value.origin, val: ConstVariableValue::Unknown { universe: self.for_universe }, }); - Ok(self.tcx().mk_const(new_var_id, c.ty())) + Ok(self.tcx().mk().const_(new_var_id, c.ty())) } } } @@ -815,7 +815,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { substs, substs, )?; - Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty())) + Ok(self.tcx().mk().const_(ty::UnevaluatedConst { def, substs }, c.ty())) } _ => relate::super_relate_consts(self, c, c), } @@ -917,7 +917,7 @@ impl<'tcx> FallibleTypeFolder> for ConstInferUnifier<'_, 'tcx> { .borrow_mut() .type_variables() .new_var(self.for_universe, origin); - Ok(self.interner().mk_ty_var(new_var_id)) + Ok(self.interner().mk().ty_var(new_var_id)) } } } @@ -995,7 +995,7 @@ impl<'tcx> FallibleTypeFolder> for ConstInferUnifier<'_, 'tcx> { }, }, ); - Ok(self.interner().mk_const(new_var_id, c.ty())) + Ok(self.interner().mk().const_(new_var_id, c.ty())) } } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 8a2b800af0e81..fd21663fe08d0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -286,7 +286,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime { span, - opaque_ty: tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs), + opaque_ty: tcx.mk().opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs), opaque_ty_span: tcx.def_span(opaque_ty_key.def_id), }); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index c1ea0a0d95e96..36e8a94682e51 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -79,7 +79,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sup_placeholder @ Region(Interned(RePlaceholder(_), _)), _, )) => self.try_report_trait_placeholder_mismatch( - Some(self.tcx().mk_re_var(*vid)), + Some(self.tcx().mk().re_var(*vid)), cause, Some(*sub_placeholder), Some(*sup_placeholder), @@ -95,7 +95,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { _, _, )) => self.try_report_trait_placeholder_mismatch( - Some(self.tcx().mk_re_var(*vid)), + Some(self.tcx().mk().re_var(*vid)), cause, Some(*sub_placeholder), None, @@ -111,7 +111,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sup_placeholder @ Region(Interned(RePlaceholder(_), _)), _, )) => self.try_report_trait_placeholder_mismatch( - Some(self.tcx().mk_re_var(*vid)), + Some(self.tcx().mk().re_var(*vid)), cause, None, Some(*sup_placeholder), @@ -127,7 +127,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { sup_placeholder @ Region(Interned(RePlaceholder(_), _)), _, )) => self.try_report_trait_placeholder_mismatch( - Some(self.tcx().mk_re_var(*vid)), + Some(self.tcx().mk().re_var(*vid)), cause, None, Some(*sup_placeholder), @@ -141,7 +141,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { SubregionOrigin::Subtype(box TypeTrace { cause, values }), sup_placeholder @ Region(Interned(RePlaceholder(_), _)), )) => self.try_report_trait_placeholder_mismatch( - Some(self.tcx().mk_re_var(*vid)), + Some(self.tcx().mk().re_var(*vid)), cause, None, Some(*sup_placeholder), @@ -263,9 +263,10 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { let expected_trait_ref = self .cx - .resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, expected_substs)); - let actual_trait_ref = - self.cx.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, actual_substs)); + .resolve_vars_if_possible(self.cx.tcx.mk().trait_ref(trait_def_id, expected_substs)); + let actual_trait_ref = self + .cx + .resolve_vars_if_possible(self.cx.tcx.mk().trait_ref(trait_def_id, actual_substs)); // Search the expected and actual trait references to see (a) // whether the sub/sup placeholders appear in them (sometimes diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 22c1e3871175e..a672c9ed310fc 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -288,7 +288,7 @@ pub fn suggest_new_region_bound( // Get the identity type for this RPIT let did = item_id.owner_id.to_def_id(); - let ty = tcx.mk_opaque(did, ty::InternalSubsts::identity_for_item(tcx, did)); + let ty = tcx.mk().opaque(did, ty::InternalSubsts::identity_for_item(tcx, did)); if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg { GenericBound::Outlives(Lifetime { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index 2875448ee157c..f6c34a992fc4e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -41,8 +41,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { // all of the region highlighting machinery only deals with those. let guar = self.emit_err( var_origin.span(), - self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(expected)), - self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(found)), + self.cx.tcx.mk().fn_ptr(ty::Binder::dummy(expected)), + self.cx.tcx.mk().fn_ptr(ty::Binder::dummy(found)), *trait_item_def_id, ); return Some(guar); diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 7ffe1fd20b49a..e86e4a9d4c880 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -304,7 +304,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let trait_substs = trait_ref .subst_identity() // Replace the explicit self type with `Self` for better suggestion rendering - .with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper)) + .with_self_ty(self.tcx, self.tcx.mk().ty_param(0, kw::SelfUpper)) .substs; let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id.to_def_id()) diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index f09f93abf45d6..50f817c1526ad 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -97,7 +97,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { Entry::Vacant(entry) => { let index = self.const_freshen_count; self.const_freshen_count += 1; - let ct = self.infcx.tcx.mk_const(freshener(index), ty); + let ct = self.infcx.tcx.mk().const_(freshener(index), ty); entry.insert(ct); ct } @@ -199,7 +199,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { match v { ty::TyVar(v) => { let opt_ty = self.infcx.inner.borrow_mut().type_variables().probe(v).known(); - Some(self.freshen_ty(opt_ty, ty::TyVar(v), |n| self.infcx.tcx.mk_fresh_ty(n))) + Some(self.freshen_ty(opt_ty, ty::TyVar(v), |n| self.infcx.tcx.mk().fresh_ty(n))) } ty::IntVar(v) => Some( @@ -211,7 +211,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { .probe_value(v) .map(|v| v.to_type(self.infcx.tcx)), ty::IntVar(v), - |n| self.infcx.tcx.mk_fresh_int_ty(n), + |n| self.infcx.tcx.mk().fresh_int_ty(n), ), ), @@ -224,7 +224,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { .probe_value(v) .map(|v| v.to_type(self.infcx.tcx)), ty::FloatVar(v), - |n| self.infcx.tcx.mk_fresh_float_ty(n), + |n| self.infcx.tcx.mk().fresh_float_ty(n), ), ), diff --git a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs index d1897cf24b4a0..789cdda44838e 100644 --- a/compiler/rustc_infer/src/infer/higher_ranked/mod.rs +++ b/compiler/rustc_infer/src/infer/higher_ranked/mod.rs @@ -82,20 +82,21 @@ impl<'tcx> InferCtxt<'tcx> { let delegate = FnMutDelegate { regions: &mut |br: ty::BoundRegion| { - self.tcx.mk_re_placeholder(ty::PlaceholderRegion { + self.tcx.mk().re_placeholder(ty::PlaceholderRegion { universe: next_universe, name: br.kind, }) }, types: &mut |bound_ty: ty::BoundTy| { - self.tcx.mk_placeholder(ty::PlaceholderType { + self.tcx.mk().placeholder(ty::PlaceholderType { universe: next_universe, name: bound_ty.kind, }) }, consts: &mut |bound_var: ty::BoundVar, ty| { self.tcx - .mk_const(ty::PlaceholderConst { universe: next_universe, name: bound_var }, ty) + .mk() + .const_(ty::PlaceholderConst { universe: next_universe, name: bound_var }, ty) }, }; diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index cf657756ff534..6945ed12351bc 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -337,7 +337,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { // name the placeholder, then the placeholder is // larger; otherwise, the only ancestor is `'static`. Err(placeholder) if empty_ui.can_name(placeholder.universe) => { - self.tcx().mk_re_placeholder(placeholder) + self.tcx().mk().re_placeholder(placeholder) } Err(_) => self.tcx().lifetimes.re_static, }; diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 66fb1db46185d..3040a6fae403f 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -708,19 +708,19 @@ impl<'tcx> InferCtxt<'tcx> { .type_variables() .unsolved_variables() .into_iter() - .map(|t| self.tcx.mk_ty_var(t)) + .map(|t| self.tcx.mk().ty_var(t)) .collect(); vars.extend( (0..inner.int_unification_table().len()) .map(|i| ty::IntVid { index: i as u32 }) .filter(|&vid| inner.int_unification_table().probe_value(vid).is_none()) - .map(|v| self.tcx.mk_int_var(v)), + .map(|v| self.tcx.mk().int_var(v)), ); vars.extend( (0..inner.float_unification_table().len()) .map(|i| ty::FloatVid { index: i as u32 }) .filter(|&vid| inner.float_unification_table().probe_value(vid).is_none()) - .map(|v| self.tcx.mk_float_var(v)), + .map(|v| self.tcx.mk().float_var(v)), ); vars } @@ -990,7 +990,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> { - self.tcx.mk_ty_var(self.next_ty_var_id(origin)) + self.tcx.mk().ty_var(self.next_ty_var_id(origin)) } pub fn next_ty_var_id_in_universe( @@ -1007,11 +1007,11 @@ impl<'tcx> InferCtxt<'tcx> { universe: ty::UniverseIndex, ) -> Ty<'tcx> { let vid = self.next_ty_var_id_in_universe(origin, universe); - self.tcx.mk_ty_var(vid) + self.tcx.mk().ty_var(vid) } pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> { - self.tcx.mk_const(self.next_const_var_id(origin), ty) + self.tcx.mk().const_(self.next_const_var_id(origin), ty) } pub fn next_const_var_in_universe( @@ -1025,7 +1025,7 @@ impl<'tcx> InferCtxt<'tcx> { .borrow_mut() .const_unification_table() .new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } }); - self.tcx.mk_const(vid, ty) + self.tcx.mk().const_(vid, ty) } pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> { @@ -1040,7 +1040,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn next_int_var(&self) -> Ty<'tcx> { - self.tcx.mk_int_var(self.next_int_var_id()) + self.tcx.mk().int_var(self.next_int_var_id()) } fn next_float_var_id(&self) -> FloatVid { @@ -1048,7 +1048,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn next_float_var(&self) -> Ty<'tcx> { - self.tcx.mk_float_var(self.next_float_var_id()) + self.tcx.mk().float_var(self.next_float_var_id()) } /// Creates a fresh region variable with the next available index. @@ -1068,7 +1068,7 @@ impl<'tcx> InferCtxt<'tcx> { ) -> ty::Region<'tcx> { let region_var = self.inner.borrow_mut().unwrap_region_constraints().new_region_var(universe, origin); - self.tcx.mk_re_var(region_var) + self.tcx.mk().re_var(region_var) } /// Return the universe that the region `r` was created in. For @@ -1128,7 +1128,7 @@ impl<'tcx> InferCtxt<'tcx> { }, ); - self.tcx.mk_ty_var(ty_var_id).into() + self.tcx.mk().ty_var(ty_var_id).into() } GenericParamDefKind::Const { .. } => { let origin = ConstVariableOrigin { @@ -1144,7 +1144,8 @@ impl<'tcx> InferCtxt<'tcx> { val: ConstVariableValue::Unknown { universe: self.universe() }, }); self.tcx - .mk_const( + .mk() + .const_( const_var_id, self.tcx .type_of(param.def_id) @@ -1366,7 +1367,7 @@ impl<'tcx> InferCtxt<'tcx> { if let Some(value) = inner.int_unification_table().probe_value(vid) { value.to_type(self.tcx) } else { - self.tcx.mk_int_var(inner.int_unification_table().find(vid)) + self.tcx.mk().int_var(inner.int_unification_table().find(vid)) } } @@ -1377,7 +1378,7 @@ impl<'tcx> InferCtxt<'tcx> { if let Some(value) = inner.float_unification_table().probe_value(vid) { value.to_type(self.tcx) } else { - self.tcx.mk_float_var(inner.float_unification_table().find(vid)) + self.tcx.mk().float_var(inner.float_unification_table().find(vid)) } } @@ -1572,7 +1573,7 @@ impl<'tcx> InferCtxt<'tcx> { span: Option, ) -> Result, ErrorHandled> { match self.const_eval_resolve(param_env, unevaluated, span) { - Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)), + Ok(Some(val)) => Ok(self.tcx.mk().const_(val, ty)), Ok(None) => { let tcx = self.tcx; let def_id = unevaluated.def.did; @@ -2068,7 +2069,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>( fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { if let ty::Infer(_) = t.kind() { - self.tcx.mk_placeholder(ty::PlaceholderType { + self.tcx.mk().placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name: ty::BoundTyKind::Anon({ let idx = self.idx; @@ -2088,7 +2089,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>( if ty.has_non_region_param() || ty.has_non_region_infer() { bug!("const `{c}`'s type should not reference params or types"); } - self.tcx.mk_const( + self.tcx.mk().const_( ty::PlaceholderConst { universe: ty::UniverseIndex::ROOT, name: ty::BoundVar::from_u32({ diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 573cd91a2a2a6..6d7d9bf5af69c 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -962,7 +962,7 @@ where // the universe `_universe`. let new_var_id = variables.new_var(self.universe, origin); - let u = self.tcx().mk_ty_var(new_var_id); + let u = self.tcx().mk().ty_var(new_var_id); debug!("generalize: replacing original vid={:?} with new={:?}", vid, u); Ok(u) } @@ -1046,7 +1046,7 @@ where origin: var_value.origin, val: ConstVariableValue::Unknown { universe: self.universe }, }); - Ok(self.tcx().mk_const(new_var_id, a.ty())) + Ok(self.tcx().mk().const_(new_var_id, a.ty())) } } } diff --git a/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs b/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs index 89ada23c6673a..0b03c2a04fd70 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/leak_check.rs @@ -280,7 +280,7 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> { placeholder1: ty::PlaceholderRegion, placeholder2: ty::PlaceholderRegion, ) -> TypeError<'tcx> { - self.error(placeholder1, self.tcx.mk_re_placeholder(placeholder2)) + self.error(placeholder1, self.tcx.mk().re_placeholder(placeholder2)) } fn error( @@ -413,13 +413,13 @@ impl<'tcx> MiniGraph<'tcx> { for undo_entry in undo_log { match undo_entry { &AddConstraint(Constraint::VarSubVar(a, b)) => { - each_edge(tcx.mk_re_var(a), tcx.mk_re_var(b)); + each_edge(tcx.mk().re_var(a), tcx.mk().re_var(b)); } &AddConstraint(Constraint::RegSubVar(a, b)) => { - each_edge(a, tcx.mk_re_var(b)); + each_edge(a, tcx.mk().re_var(b)); } &AddConstraint(Constraint::VarSubReg(a, b)) => { - each_edge(tcx.mk_re_var(a), b); + each_edge(tcx.mk().re_var(a), b); } &AddConstraint(Constraint::RegSubReg(a, b)) => { each_edge(a, b); diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 7b272dfd2a454..a62d1866735cb 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -610,13 +610,13 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { let resolved = ut .probe_value(root_vid) .get_value_ignoring_universes() - .unwrap_or_else(|| tcx.mk_re_var(root_vid)); + .unwrap_or_else(|| tcx.mk().re_var(root_vid)); // Don't resolve a variable to a region that it cannot name. if self.var_universe(vid).can_name(self.universe(resolved)) { resolved } else { - tcx.mk_re_var(vid) + tcx.mk().re_var(vid) } } @@ -637,7 +637,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { ) -> Region<'tcx> { let vars = TwoRegions { a, b }; if let Some(&c) = self.combine_map(t).get(&vars) { - return tcx.mk_re_var(c); + return tcx.mk().re_var(c); } let a_universe = self.universe(a); let b_universe = self.universe(b); @@ -645,7 +645,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> { let c = self.new_region_var(c_universe, MiscVariable(origin.span())); self.combine_map(t).insert(vars, c); self.undo_log.push(AddCombination(t, vars)); - let new_r = tcx.mk_re_var(c); + let new_r = tcx.mk().re_var(c); for old_r in [a, b] { match t { Glb => self.make_subregion(origin.clone(), new_r, old_r), diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index f75344f20b6d9..a9547ddfb9b7c 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -18,7 +18,7 @@ pub trait TraitEngine<'tcx>: 'tcx { def_id: DefId, cause: ObligationCause<'tcx>, ) { - let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]); + let trait_ref = infcx.tcx.mk().trait_ref(def_id, [ty]); self.register_predicate_obligation( infcx, Obligation { diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index 77c67c14ecc55..d15e966c7d274 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -78,7 +78,7 @@ impl<'tcx> PredicateObligation<'tcx> { pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> { self.param_env = self.param_env.without_const(); if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) = self.predicate.kind().skip_binder() && trait_pred.is_const_if_const() { - self.predicate = tcx.mk_predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred.without_const())))); + self.predicate = tcx.mk().predicate(self.predicate.kind().map_bound(|_| ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred.without_const())))); } self } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index c07ff51657994..5f8b78c41849b 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -255,7 +255,7 @@ impl<'tcx> Elaborator<'tcx> { } Component::Param(p) => { - let ty = tcx.mk_ty_param(p.index, p.name); + let ty = tcx.mk().ty_param(p.index, p.name); Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives( ty::OutlivesPredicate(ty, r_min), ))) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 5b2100b5da9d1..fec5526104ad1 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -677,21 +677,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, ty::List::empty())) + (def, cx.tcx.mk().adt(def, ty::List::empty())) } hir::ItemKind::Union(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, ty::List::empty())) + (def, cx.tcx.mk().adt(def, ty::List::empty())) } hir::ItemKind::Enum(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, ty::List::empty())) + (def, cx.tcx.mk().adt(def, ty::List::empty())) } _ => return, }; diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index f5a711315ea4c..2c5b735245d0a 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -1299,7 +1299,7 @@ impl<'tcx> LateContext<'tcx> { tcx.associated_items(trait_id) .find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) .and_then(|assoc| { - let proj = tcx.mk_projection(assoc.def_id, [self_ty]); + let proj = tcx.mk().projection(assoc.def_id, [self_ty]); tcx.try_normalize_erasing_regions(self.param_env, proj).ok() }) } diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 883a56cb3ce6b..99915d3006082 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { let Some(proj_term) = proj.term.ty() else { continue }; let proj_ty = - cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs); + cx.tcx.mk().projection(proj.projection_ty.def_id, proj.projection_ty.substs); // For every instance of the projection type in the bounds, // replace them with the term we're assigning to the associated // type in our opaque type. @@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { OPAQUE_HIDDEN_INFERRED_BOUND, pred_span, OpaqueHiddenInferredBoundLint { - ty: cx.tcx.mk_opaque( + ty: cx.tcx.mk().opaque( def_id, ty::InternalSubsts::identity_for_item(cx.tcx, def_id), ), diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 7ca50f5a2db70..5addd1843d259 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -713,12 +713,12 @@ fn get_nullable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option tcx.mk_mach_int(ty), - ty::Uint(ty) => tcx.mk_mach_uint(ty), - ty::RawPtr(ty_mut) => tcx.mk_ptr(ty_mut), + ty::Int(ty) => tcx.mk().mach_int(ty), + ty::Uint(ty) => tcx.mk().mach_uint(ty), + ty::RawPtr(ty_mut) => tcx.mk().ptr(ty_mut), // As these types are always non-null, the nullable equivalent of // Option of these types are their raw pointer counterparts. - ty::Ref(_region, ty, mutbl) => tcx.mk_ptr(ty::TypeAndMut { ty, mutbl }), + ty::Ref(_region, ty, mutbl) => tcx.mk().ptr(ty::TypeAndMut { ty, mutbl }), ty::FnPtr(..) => { // There is no nullable equivalent for Rust's function pointers -- you // must use an Option _> to represent it. diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index d6f68b2e14055..2635ea829b1a2 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -507,7 +507,7 @@ impl<'tcx> Collector<'tcx> { .subst_identity() .fn_sig(self.tcx) .inputs() - .map_bound(|slice| self.tcx.mk_type_list(slice)), + .map_bound(|slice| self.tcx.mk().type_list(slice)), ); argument_types diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 0070e46ffdf02..3df72b077eed1 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -922,7 +922,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { std::iter::once(self.get_variant(&kind, item_id, did)).collect() }; - tcx.mk_adt_def(did, adt_kind, variants, repr) + tcx.mk().adt_def(did, adt_kind, variants, repr) } fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics { diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 7f8fc17744dc9..44771e6bb5b35 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -402,22 +402,23 @@ impl<'tcx> CanonicalVarValues<'tcx> { infos: CanonicalVarInfos<'tcx>, ) -> CanonicalVarValues<'tcx> { CanonicalVarValues { - var_values: tcx.mk_substs_from_iter(infos.iter().enumerate().map( + var_values: tcx.mk().substs_from_iter(infos.iter().enumerate().map( |(i, info)| -> ty::GenericArg<'tcx> { match info.kind { CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => { - tcx.mk_bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()).into() + tcx.mk().bound(ty::INNERMOST, ty::BoundVar::from_usize(i).into()).into() } CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => { let br = ty::BoundRegion { var: ty::BoundVar::from_usize(i), kind: ty::BrAnon(i as u32, None), }; - tcx.mk_re_late_bound(ty::INNERMOST, br).into() + tcx.mk().re_late_bound(ty::INNERMOST, br).into() } CanonicalVarKind::Const(_, ty) | CanonicalVarKind::PlaceholderConst(_, ty) => tcx - .mk_const( + .mk() + .const_( ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(i)), ty, ) diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs index d83a587a86ae6..1d1190deddb82 100644 --- a/compiler/rustc_middle/src/infer/unify_key.rs +++ b/compiler/rustc_middle/src/infer/unify_key.rs @@ -90,15 +90,15 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> { impl ToType for ty::IntVarValue { fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { - ty::IntType(i) => tcx.mk_mach_int(i), - ty::UintType(i) => tcx.mk_mach_uint(i), + ty::IntType(i) => tcx.mk().mach_int(i), + ty::UintType(i) => tcx.mk().mach_uint(i), } } } impl ToType for ty::FloatVarValue { fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - tcx.mk_mach_float(self.0) + tcx.mk().mach_float(self.0) } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index b34651c3ea797..283dd6901b055 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1863,7 +1863,7 @@ impl<'tcx> Operand<'tcx> { substs: impl IntoIterator>, span: Span, ) -> Self { - let ty = tcx.mk_fn_def(def_id, substs); + let ty = tcx.mk().fn_def(def_id, substs); Operand::Constant(Box::new(Constant { span, user_ty: None, @@ -2522,7 +2522,7 @@ impl<'tcx> ConstantKind<'tcx> { let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; let name = tcx.item_name(def_id); - let ty_const = tcx.mk_const(ty::ParamConst::new(index, name), ty); + let ty_const = tcx.mk().const_(ty::ParamConst::new(index, name), ty); debug!(?ty_const); return Self::Ty(ty_const); @@ -2543,7 +2543,7 @@ impl<'tcx> ConstantKind<'tcx> { let did = def.did.to_def_id(); let child_substs = InternalSubsts::identity_for_item(tcx, did); let substs = - tcx.mk_substs_from_iter(parent_substs.into_iter().chain(child_substs.into_iter())); + tcx.mk().substs_from_iter(parent_substs.into_iter().chain(child_substs.into_iter())); debug!(?substs); let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index d85d68870d7d8..e460b52cfbc51 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -415,7 +415,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon(vid.as_u32(), None), }; - tcx.mk_re_late_bound(depth, br) + tcx.mk().re_late_bound(depth, br) } _ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"), }); diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 0aa2c500f51fb..c1bff787cbcbb 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -95,11 +95,11 @@ impl<'tcx> PlaceTy<'tcx> { ProjectionElem::Subslice { from, to, from_end } => { PlaceTy::from_ty(match self.ty.kind() { ty::Slice(..) => self.ty, - ty::Array(inner, _) if !from_end => tcx.mk_array(*inner, (to - from) as u64), + ty::Array(inner, _) if !from_end => tcx.mk().array(*inner, (to - from) as u64), ty::Array(inner, size) if from_end => { let size = size.eval_target_usize(tcx, param_env); let len = size - (from as u64) - (to as u64); - tcx.mk_array(*inner, len) + tcx.mk().array(*inner, len) } _ => bug!("cannot subslice non-array type: `{:?}`", self), }) @@ -162,26 +162,26 @@ impl<'tcx> Rvalue<'tcx> { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), Rvalue::Repeat(ref operand, count) => { - tcx.mk_array_with_const_len(operand.ty(local_decls, tcx), count) + tcx.mk().array_with_const_len(operand.ty(local_decls, tcx), count) } Rvalue::ThreadLocalRef(did) => { let static_ty = tcx.type_of(did).subst_identity(); if tcx.is_mutable_static(did) { - tcx.mk_mut_ptr(static_ty) + tcx.mk().mut_ptr(static_ty) } else if tcx.is_foreign_item(did) { - tcx.mk_imm_ptr(static_ty) + tcx.mk().imm_ptr(static_ty) } else { // FIXME: These things don't *really* have 'static lifetime. - tcx.mk_imm_ref(tcx.lifetimes.re_static, static_ty) + tcx.mk().imm_ref(tcx.lifetimes.re_static, static_ty) } } Rvalue::Ref(reg, bk, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; - tcx.mk_ref(reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() }) + tcx.mk().ref_(reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() }) } Rvalue::AddressOf(mutability, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; - tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability }) + tcx.mk().ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability }) } Rvalue::Len(..) => tcx.types.usize, Rvalue::Cast(.., ty) => ty, @@ -194,23 +194,23 @@ impl<'tcx> Rvalue<'tcx> { let lhs_ty = lhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx); let ty = op.ty(tcx, lhs_ty, rhs_ty); - tcx.mk_tup(&[ty, tcx.types.bool]) + tcx.mk().tup(&[ty, tcx.types.bool]) } Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx), Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx), Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => tcx.types.usize, Rvalue::Aggregate(ref ak, ref ops) => match **ak { - AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), + AggregateKind::Array(ty) => tcx.mk().array(ty, ops.len() as u64), AggregateKind::Tuple => { - tcx.mk_tup_from_iter(ops.iter().map(|op| op.ty(local_decls, tcx))) + tcx.mk().tup_from_iter(ops.iter().map(|op| op.ty(local_decls, tcx))) } AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs), - AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs), + AggregateKind::Closure(did, substs) => tcx.mk().closure(did, substs), AggregateKind::Generator(did, substs, movability) => { - tcx.mk_generator(did, substs, movability) + tcx.mk().generator(did, substs, movability) } }, - Rvalue::ShallowInitBox(_, ty) => tcx.mk_box(ty), + Rvalue::ShallowInitBox(_, ty) => tcx.mk().box_(ty), Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty, } } diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 8ce06404de081..94b343f0fe9cf 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -131,7 +131,7 @@ impl<'tcx> OverloadedDeref<'tcx> { .find(|m| m.kind == ty::AssocKind::Fn) .unwrap() .def_id; - tcx.mk_fn_def(method_def_id, [source]) + tcx.mk().fn_def(method_def_id, [source]) } } diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 3ce80e06ad9ef..032f89871527d 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -207,7 +207,7 @@ impl<'tcx, D: TyDecoder>> Decodable for Ty<'tcx> { }) } else { let tcx = decoder.interner(); - tcx.mk_ty_from_kind(rustc_type_ir::TyKind::decode(decoder)) + tcx.mk().ty_from_kind(rustc_type_ir::TyKind::decode(decoder)) } } } @@ -236,7 +236,7 @@ impl<'tcx, D: TyDecoder>> Decodable impl<'tcx, D: TyDecoder>> Decodable for ty::Predicate<'tcx> { fn decode(decoder: &mut D) -> ty::Predicate<'tcx> { let predicate_kind = Decodable::decode(decoder); - decoder.interner().mk_predicate(predicate_kind) + decoder.interner().mk().predicate(predicate_kind) } } @@ -244,7 +244,7 @@ impl<'tcx, D: TyDecoder>> Decodable for SubstsRef<'tcx> { fn decode(decoder: &mut D) -> Self { let len = decoder.read_usize(); let tcx = decoder.interner(); - tcx.mk_substs_from_iter( + tcx.mk().substs_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -254,7 +254,7 @@ impl<'tcx, D: TyDecoder>> Decodable for mir::Place<'tcx> { fn decode(decoder: &mut D) -> Self { let local: mir::Local = Decodable::decode(decoder); let len = decoder.read_usize(); - let projection = decoder.interner().mk_place_elems_from_iter( + let projection = decoder.interner().mk().place_elems_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ); mir::Place { local, projection } @@ -263,14 +263,14 @@ impl<'tcx, D: TyDecoder>> Decodable for mir::Place<'tcx> { impl<'tcx, D: TyDecoder>> Decodable for ty::Region<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().mk_region_from_kind(Decodable::decode(decoder)) + decoder.interner().mk().region_from_kind(Decodable::decode(decoder)) } } impl<'tcx, D: TyDecoder>> Decodable for CanonicalVarInfos<'tcx> { fn decode(decoder: &mut D) -> Self { let len = decoder.read_usize(); - decoder.interner().mk_canonical_var_infos_from_iter( + decoder.interner().mk().canonical_var_infos_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -312,7 +312,8 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List, _>(|_| Decodable::decode(decoder))) + .mk() + .type_list_from_iter((0..len).map::, _>(|_| Decodable::decode(decoder))) } } @@ -321,7 +322,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_poly_existential_predicates_from_iter( + decoder.interner().mk().poly_existential_predicates_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -330,7 +331,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder>> Decodable for ty::Const<'tcx> { fn decode(decoder: &mut D) -> Self { let consts: ty::ConstData<'tcx> = Decodable::decode(decoder); - decoder.interner().mk_const(consts.kind, consts.ty) + decoder.interner().mk().const_(consts.kind, consts.ty) } } @@ -377,7 +378,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_bound_variable_kinds_from_iter( + decoder.interner().mk().bound_variable_kinds_from_iter( (0..len).map::(|_| Decodable::decode(decoder)), ) } @@ -386,7 +387,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_const_list_from_iter( + decoder.interner().mk().const_list_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -395,7 +396,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_predicates_from_iter( + decoder.interner().mk().predicates_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 42101f6b93152..f06fd617924ca 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -80,7 +80,7 @@ impl<'tcx> Const<'tcx> { match Self::try_eval_lit_or_param(tcx, ty, expr) { Some(v) => v, - None => tcx.mk_const( + None => tcx.mk().const_( ty::UnevaluatedConst { def: def.to_global(), substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()), @@ -146,9 +146,9 @@ impl<'tcx> Const<'tcx> { let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; let name = tcx.item_name(def_id); - Some(tcx.mk_const(ty::ParamConst::new(index, name), param_ty)) + Some(tcx.mk().const_(ty::ParamConst::new(index, name), param_ty)) } - Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => Some(tcx.mk_const( + Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => Some(tcx.mk().const_( ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)), param_ty, )), @@ -177,7 +177,7 @@ impl<'tcx> Const<'tcx> { .layout_of(ty) .unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e)) .size; - tcx.mk_const( + tcx.mk().const_( ty::ValTree::from_scalar_int(ScalarInt::try_from_uint(bits, size).unwrap()), ty.value, ) @@ -186,7 +186,7 @@ impl<'tcx> Const<'tcx> { #[inline] /// Creates an interned zst constant. pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self { - tcx.mk_const(ty::ValTree::zst(), ty) + tcx.mk().const_(ty::ValTree::zst(), ty) } #[inline] @@ -237,7 +237,7 @@ impl<'tcx> Const<'tcx> { pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) { match val { - Ok(val) => tcx.mk_const(val, self.ty()), + Ok(val) => tcx.mk().const_(val, self.ty()), Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar), } } else { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index a4eb49fb82d47..64c40b6e11b16 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -727,7 +727,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` #[track_caller] pub fn ty_error(self, reported: ErrorGuaranteed) -> Ty<'tcx> { - self.mk_ty_from_kind(Error(reported)) + self.mk().ty_from_kind(Error(reported)) } /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used. @@ -741,7 +741,7 @@ impl<'tcx> TyCtxt<'tcx> { #[track_caller] pub fn ty_error_with_message>(self, span: S, msg: &str) -> Ty<'tcx> { let reported = self.sess.delay_span_bug(span, msg); - self.mk_ty_from_kind(Error(reported)) + self.mk().ty_from_kind(Error(reported)) } /// Constructs a `RegionKind::ReError` lifetime. @@ -777,7 +777,7 @@ impl<'tcx> TyCtxt<'tcx> { ty: Ty<'tcx>, reported: ErrorGuaranteed, ) -> Const<'tcx> { - self.mk_const(ty::ConstKind::Error(reported), ty) + self.mk().const_(ty::ConstKind::Error(reported), ty) } /// Like [TyCtxt::ty_error] but for constants. @@ -799,7 +799,7 @@ impl<'tcx> TyCtxt<'tcx> { msg: &str, ) -> Const<'tcx> { let reported = self.sess.delay_span_bug(span, msg); - self.mk_const(ty::ConstKind::Error(reported), ty) + self.mk().const_(ty::ConstKind::Error(reported), ty) } pub fn consider_optimizing String>(self, msg: T) -> bool { @@ -1201,7 +1201,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns `&'static core::panic::Location<'static>`. pub fn caller_location_ty(self) -> Ty<'tcx> { - self.mk_imm_ref( + self.mk().imm_ref( self.lifetimes.re_static, self.type_of(self.require_lang_item(LangItem::PanicLocation, None)) .subst(self, self.mk_substs(&[self.lifetimes.re_static.into()])), @@ -1614,7 +1614,7 @@ impl<'tcx> TyCtxt<'tcx> { /// unsafe. pub fn safe_to_unsafe_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> { assert_eq!(sig.unsafety(), hir::Unsafety::Normal); - self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig })) + self.mk().fn_ptr(sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig })) } /// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name` @@ -1686,7 +1686,7 @@ impl<'tcx> TyCtxt<'tcx> { ty::Tuple(params) => *params, _ => bug!(), }; - self.mk_fn_sig(params, s.output(), s.c_variadic, unsafety, abi::Abi::Rust) + self.mk().fn_sig(params, s.output(), s.c_variadic, unsafety, abi::Abi::Rust) }) } @@ -1932,7 +1932,7 @@ impl<'tcx> TyCtxt<'tcx> { substs.collect::>(), ); } - self.mk_substs_from_iter(substs) + self.mk().substs_from_iter(substs) } #[inline] diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index ae0bb4949c743..3f09ef4524fbc 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -548,7 +548,7 @@ impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { Infer(InferTy::TyVar(_)) if self.infer_suggestable => t, FnDef(def_id, substs) => { - self.tcx.mk_fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs)) + self.tcx.mk().fn_ptr(self.tcx.fn_sig(def_id).subst(self.tcx, substs)) } // FIXME(compiler-errors): We could replace these with infer, I guess. diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index d66f436f947a3..be41858af8c84 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -225,7 +225,7 @@ where // debruijn index. Then we adjust it to the // correct depth. assert_eq!(debruijn1, ty::INNERMOST); - self.tcx.mk_re_late_bound(debruijn, br) + self.tcx.mk().re_late_bound(debruijn, br) } else { region } @@ -340,7 +340,7 @@ impl<'tcx> TyCtxt<'tcx> { T: TypeFoldable>, { self.replace_late_bound_regions_uncached(value, |br| { - self.mk_re_free(all_outlive_scope, br.kind) + self.mk().re_free(all_outlive_scope, br.kind) }) } @@ -353,16 +353,17 @@ impl<'tcx> TyCtxt<'tcx> { value, FnMutDelegate { regions: &mut |r: ty::BoundRegion| { - self.mk_re_late_bound( + self.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: shift_bv(r.var), kind: r.kind }, ) }, types: &mut |t: ty::BoundTy| { - self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind }) + self.mk() + .bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind }) }, consts: &mut |c, ty: Ty<'tcx>| { - self.mk_const(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty) + self.mk().const_(ty::ConstKind::Bound(ty::INNERMOST, shift_bv(c)), ty) }, }, ) @@ -397,7 +398,7 @@ impl<'tcx> TyCtxt<'tcx> { }) .expect_region(); let br = ty::BoundRegion { var, kind }; - self.tcx.mk_re_late_bound(ty::INNERMOST, br) + self.tcx.mk().re_late_bound(ty::INNERMOST, br) } fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> { let entry = self.map.entry(bt.var); @@ -408,21 +409,21 @@ impl<'tcx> TyCtxt<'tcx> { ty::BoundVariableKind::Ty(ty::BoundTyKind::Anon(index as u32)) }) .expect_ty(); - self.tcx.mk_bound(ty::INNERMOST, BoundTy { var, kind }) + self.tcx.mk().bound(ty::INNERMOST, BoundTy { var, kind }) } fn replace_const(&mut self, bv: ty::BoundVar, ty: Ty<'tcx>) -> ty::Const<'tcx> { let entry = self.map.entry(bv); let index = entry.index(); let var = ty::BoundVar::from_usize(index); let () = entry.or_insert_with(|| ty::BoundVariableKind::Const).expect_const(); - self.tcx.mk_const(ty::ConstKind::Bound(ty::INNERMOST, var), ty) + self.tcx.mk().const_(ty::ConstKind::Bound(ty::INNERMOST, var), ty) } } let mut map = Default::default(); let delegate = Anonymize { tcx: self, map: &mut map }; let inner = self.replace_escaping_bound_vars_uncached(value.skip_binder(), delegate); - let bound_vars = self.mk_bound_variable_kinds_from_iter(map.into_values()); + let bound_vars = self.mk().bound_variable_kinds_from_iter(map.into_values()); Binder::bind_with_vars(inner, bound_vars) } } @@ -467,7 +468,7 @@ impl<'tcx> TypeFolder> for Shifter<'tcx> { match *r { ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => { let debruijn = debruijn.shifted_in(self.amount); - self.tcx.mk_re_late_bound(debruijn, br) + self.tcx.mk().re_late_bound(debruijn, br) } _ => r, } @@ -477,7 +478,7 @@ impl<'tcx> TypeFolder> for Shifter<'tcx> { match *ty.kind() { ty::Bound(debruijn, bound_ty) if debruijn >= self.current_index => { let debruijn = debruijn.shifted_in(self.amount); - self.tcx.mk_bound(debruijn, bound_ty) + self.tcx.mk().bound(debruijn, bound_ty) } _ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self), @@ -490,7 +491,7 @@ impl<'tcx> TypeFolder> for Shifter<'tcx> { && debruijn >= self.current_index { let debruijn = debruijn.shifted_in(self.amount); - self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty()) + self.tcx.mk().const_(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty()) } else { ct.super_fold_with(self) } @@ -508,7 +509,7 @@ pub fn shift_region<'tcx>( ) -> ty::Region<'tcx> { match *region { ty::ReLateBound(debruijn, br) if amount > 0 => { - tcx.mk_re_late_bound(debruijn.shifted_in(amount), br) + tcx.mk().re_late_bound(debruijn.shifted_in(amount), br) } _ => region, } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index baef4ffeda732..fc1afa5010eb8 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -100,7 +100,7 @@ impl GenericParamDef { preceding_substs: &[ty::GenericArg<'tcx>], ) -> ty::GenericArg<'tcx> { match &self.kind { - ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(), + ty::GenericParamDefKind::Lifetime => tcx.mk().re_error_misc().into(), ty::GenericParamDefKind::Type { .. } => tcx.ty_error_misc().into(), ty::GenericParamDefKind::Const { .. } => { tcx.const_error(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into() diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index f4028a5a9f63a..7396a2ce6c777 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -561,13 +561,13 @@ impl<'tcx> Instance<'tcx> { tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER); let def = ty::InstanceDef::ClosureOnceShim { call_once, track_caller }; - let self_ty = tcx.mk_closure(closure_did, substs); + let self_ty = tcx.mk().closure(closure_did, substs); let sig = substs.as_closure().sig(); let sig = tcx.try_normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig).ok()?; assert_eq!(sig.inputs().len(), 1); - let substs = tcx.mk_substs_trait(self_ty, [sig.inputs()[0].into()]); + let substs = tcx.mk().substs_trait(self_ty, [sig.inputs()[0].into()]); debug!(?self_ty, ?sig); Some(Instance { def, substs }) @@ -691,7 +691,7 @@ fn polymorphize<'tcx>( if substs == polymorphized_substs { ty } else { - self.tcx.mk_closure(def_id, polymorphized_substs) + self.tcx.mk().closure(def_id, polymorphized_substs) } } ty::Generator(def_id, substs, movability) => { @@ -703,7 +703,7 @@ fn polymorphize<'tcx>( if substs == polymorphized_substs { ty } else { - self.tcx.mk_generator(def_id, polymorphized_substs, movability) + self.tcx.mk().generator(def_id, polymorphized_substs, movability) } } _ => ty.super_fold_with(self), @@ -736,7 +736,7 @@ fn polymorphize<'tcx>( // ..and is within range and unused.. unused.is_unused(param.index) => // ..then use the identity for this parameter. - tcx.mk_param_from_def(param), + tcx.mk().param_from_def(param), // Otherwise, use the parameter as before. _ => substs[param.index as usize], diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 42fb5d031bbc9..ea9b2d2e90c9d 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -131,7 +131,7 @@ impl PrimitiveExt for Primitive { F32 => tcx.types.f32, F64 => tcx.types.f64, // FIXME(erikdesjardins): handle non-default addrspace ptr sizes - Pointer(_) => tcx.mk_mut_ptr(tcx.mk_unit()), + Pointer(_) => tcx.mk().mut_ptr(tcx.mk().unit()), } } @@ -697,11 +697,11 @@ where // (which may have no non-DST form), and will work as long // as the `Abi` or `FieldsShape` is checked by users. if i == 0 { - let nil = tcx.mk_unit(); + let nil = tcx.mk().unit(); let unit_ptr_ty = if this.ty.is_unsafe_ptr() { - tcx.mk_mut_ptr(nil) + tcx.mk().mut_ptr(nil) } else { - tcx.mk_mut_ref(tcx.lifetimes.re_static, nil) + tcx.mk().mut_ref(tcx.lifetimes.re_static, nil) }; // NOTE(eddyb) using an empty `ParamEnv`, and `unwrap`-ing @@ -714,7 +714,8 @@ where } let mk_dyn_vtable = || { - tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_array(tcx.types.usize, 3)) + tcx.mk() + .imm_ref(tcx.lifetimes.re_static, tcx.mk().array(tcx.types.usize, 3)) /* FIXME: use actual fn pointers Warning: naively computing the number of entries in the vtable by counting the methods on the trait + methods on @@ -737,7 +738,7 @@ where { let metadata = tcx.normalize_erasing_regions( cx.param_env(), - tcx.mk_projection(metadata_def_id, [pointee]), + tcx.mk().projection(metadata_def_id, [pointee]), ); // Map `Metadata = DynMetadata` back to a vtable, since it @@ -811,13 +812,13 @@ where ty::Dynamic(_, _, ty::DynStar) => { if i == 0 { - TyMaybeWithLayout::Ty(tcx.mk_mut_ptr(tcx.types.unit)) + TyMaybeWithLayout::Ty(tcx.mk().mut_ptr(tcx.types.unit)) } else if i == 1 { // FIXME(dyn-star) same FIXME as above applies here too TyMaybeWithLayout::Ty( - tcx.mk_imm_ref( + tcx.mk().imm_ref( tcx.lifetimes.re_static, - tcx.mk_array(tcx.types.usize, 3), + tcx.mk().array(tcx.types.usize, 3), ), ) } else { @@ -868,10 +869,8 @@ where }) } ty::FnPtr(fn_sig) if offset.bytes() == 0 => { - tcx.layout_of(param_env.and(tcx.mk_fn_ptr(fn_sig))).ok().map(|layout| PointeeInfo { - size: layout.size, - align: layout.align.abi, - safe: None, + tcx.layout_of(param_env.and(tcx.mk().fn_ptr(fn_sig))).ok().map(|layout| { + PointeeInfo { size: layout.size, align: layout.align.abi, safe: None } }) } ty::Ref(_, ty, mt) if offset.bytes() == 0 => { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 04d7de531c26b..506d7939e092d 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -502,14 +502,14 @@ impl<'tcx> Predicate<'tcx> { }) .transpose()?; - Some(tcx.mk_predicate(kind)) + Some(tcx.mk().predicate(kind)) } pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> Self { if let PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref, constness, polarity })) = self.kind().skip_binder() && constness != BoundConstness::NotConst { - self = tcx.mk_predicate(self.kind().rebind(PredicateKind::Clause(Clause::Trait(TraitPredicate { + self = tcx.mk().predicate(self.kind().rebind(PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref, constness: BoundConstness::NotConst, polarity, @@ -752,7 +752,7 @@ impl<'tcx> Predicate<'tcx> { let new = EarlyBinder(shifted_pred).subst(tcx, trait_ref.skip_binder().substs); // 3) ['x] + ['b] -> ['x, 'b] let bound_vars = - tcx.mk_bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars)); + tcx.mk().bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars)); tcx.reuse_or_mk_predicate(self, ty::Binder::bind_with_vars(new, bound_vars)) } } @@ -990,7 +990,7 @@ impl<'tcx> Term<'tcx> { _ => None, }, TermKind::Const(ct) => match ct.kind() { - ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def.did, uv.substs)), + ConstKind::Unevaluated(uv) => Some(tcx.mk().alias_ty(uv.def.did, uv.substs)), _ => None, }, } @@ -1131,14 +1131,14 @@ impl<'tcx, T> ToPredicate<'tcx, T> for T { impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - tcx.mk_predicate(self) + tcx.mk().predicate(self) } } impl<'tcx> ToPredicate<'tcx> for Clause<'tcx> { #[inline(always)] fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self))) + tcx.mk().predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self))) } } diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 751f3066c9cc6..75891677b6d37 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -79,7 +79,7 @@ impl<'tcx> ReverseMapper<'tcx> { // during codegen. let generics = self.tcx.generics_of(def_id); - self.tcx.mk_substs_from_iter(substs.iter().enumerate().map(|(index, kind)| { + self.tcx.mk().substs_from_iter(substs.iter().enumerate().map(|(index, kind)| { if index < generics.parent_count { // Accommodate missing regions in the parent kinds... self.fold_kind_no_missing_regions_error(kind) @@ -141,7 +141,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { ) .emit(); - self.interner().mk_re_error(e) + self.interner().mk().re_error(e) } } } @@ -150,17 +150,17 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { match *ty.kind() { ty::Closure(def_id, substs) => { let substs = self.fold_closure_substs(def_id, substs); - self.tcx.mk_closure(def_id, substs) + self.tcx.mk().closure(def_id, substs) } ty::Generator(def_id, substs, movability) => { let substs = self.fold_closure_substs(def_id, substs); - self.tcx.mk_generator(def_id, substs, movability) + self.tcx.mk().generator(def_id, substs, movability) } ty::GeneratorWitnessMIR(def_id, substs) => { let substs = self.fold_closure_substs(def_id, substs); - self.tcx.mk_generator_witness_mir(def_id, substs) + self.tcx.mk().generator_witness_mir(def_id, substs) } ty::Param(param) => { diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index d947d96041ef7..5548fc38691af 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -169,8 +169,10 @@ 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 = cx + .tcx() + .mk() + .trait_ref(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) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index b3139d23d36e3..f2e06d91e1102 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -182,7 +182,7 @@ impl<'tcx> RegionHighlightMode<'tcx> { /// Convenience wrapper for `highlighting_region`. pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) { - self.highlighting_region(self.tcx.mk_re_var(vid), number) + self.highlighting_region(self.tcx.mk().re_var(vid), number) } /// Returns `Some(n)` with the number to use for the given region, if any. @@ -1212,7 +1212,7 @@ pub trait PrettyPrinter<'tcx>: // in order to place the projections inside the `<...>`. if !resugared { // Use a type that can't appear in defaults of type parameters. - let dummy_cx = cx.tcx().mk_fresh_ty(0); + let dummy_cx = cx.tcx().mk().fresh_ty(0); let principal = principal.with_self_ty(cx.tcx(), dummy_cx); let args = cx @@ -1585,7 +1585,7 @@ pub trait PrettyPrinter<'tcx>: } // Aggregates, printed as array/tuple/struct/variant construction syntax. (ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => { - let contents = self.tcx().destructure_const(self.tcx().mk_const(valtree, ty)); + let contents = self.tcx().destructure_const(self.tcx().mk().const_(valtree, ty)); let fields = contents.fields.iter().copied(); match *ty.kind() { ty::Array(..) => { @@ -2274,7 +2274,7 @@ impl<'a, 'tcx> ty::TypeFolder> for RegionFolder<'a, 'tcx> { }; if let ty::ReLateBound(debruijn1, br) = *region { assert_eq!(debruijn1, ty::INNERMOST); - self.tcx.mk_re_late_bound(self.current_index, br) + self.tcx.mk().re_late_bound(self.current_index, br) } else { region } @@ -2386,7 +2386,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { if let Some(lt_idx) = lifetime_idx { if lt_idx > binder_level_idx { let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name); - return tcx.mk_re_late_bound( + return tcx.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: br.var, kind }, ); @@ -2401,7 +2401,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { if let Some(lt_idx) = lifetime_idx { if lt_idx > binder_level_idx { let kind = ty::BrNamed(def_id, name); - return tcx.mk_re_late_bound( + return tcx.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: br.var, kind }, ); @@ -2414,7 +2414,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { if let Some(lt_idx) = lifetime_idx { if lt_idx > binder_level_idx { let kind = br.kind; - return tcx.mk_re_late_bound( + return tcx.mk().re_late_bound( ty::INNERMOST, ty::BoundRegion { var: br.var, kind }, ); @@ -2429,7 +2429,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { start_or_continue(&mut self, "for<", ", "); do_continue(&mut self, name); } - tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind }) + tcx.mk().re_late_bound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind }) }; let mut folder = RegionFolder { tcx, @@ -2699,7 +2699,7 @@ define_print_and_forward_display! { ty::ExistentialTraitRef<'tcx> { // Use a type that can't appear in defaults of type parameters. - let dummy_self = cx.tcx().mk_fresh_ty(0); + let dummy_self = cx.tcx().mk().fresh_ty(0); let trait_ref = self.with_self_ty(cx.tcx(), dummy_self); p!(print(trait_ref.print_only_trait_path())) } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 3fc5f5bed8fcd..a39ed2a01e40a 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -144,7 +144,7 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>( a_subst: SubstsRef<'tcx>, b_subst: SubstsRef<'tcx>, ) -> RelateResult<'tcx, SubstsRef<'tcx>> { - relation.tcx().mk_substs_from_iter(iter::zip(a_subst, b_subst).map(|(a, b)| { + relation.tcx().mk().substs_from_iter(iter::zip(a_subst, b_subst).map(|(a, b)| { relation.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b) })) } @@ -171,7 +171,7 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>( relation.relate_with_variance(variance, variance_info, a, b) }); - tcx.mk_substs_from_iter(params) + tcx.mk().substs_from_iter(params) } impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { @@ -222,7 +222,7 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { r => r, }); Ok(ty::FnSig { - inputs_and_output: tcx.mk_type_list_from_iter(inputs_and_output)?, + inputs_and_output: tcx.mk().type_list_from_iter(inputs_and_output)?, c_variadic: a.c_variadic, unsafety, abi, @@ -278,7 +278,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> { Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relation.relate(a.substs, b.substs)?; - Ok(relation.tcx().mk_alias_ty(a.def_id, substs)) + Ok(relation.tcx().mk().alias_ty(a.def_id, substs)) } } } @@ -320,7 +320,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(relation.tcx().mk().trait_ref(a.def_id, substs)) } } } @@ -352,8 +352,9 @@ impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> { assert_eq!(a.0.len(), b.0.len()); let tcx = relation.tcx(); - let types = - tcx.mk_type_list_from_iter(iter::zip(a.0, b.0).map(|(a, b)| relation.relate(a, b)))?; + let types = tcx + .mk() + .type_list_from_iter(iter::zip(a.0, b.0).map(|(a, b)| relation.relate(a, b)))?; Ok(GeneratorWitness(types)) } } @@ -433,10 +434,10 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( (&ty::Adt(a_def, a_substs), &ty::Adt(b_def, b_substs)) if a_def == b_def => { let substs = relation.relate_item_substs(a_def.did(), a_substs, b_substs)?; - Ok(tcx.mk_adt(a_def, substs)) + Ok(tcx.mk().adt(a_def, substs)) } - (&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk_foreign(a_id)), + (&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(tcx.mk().foreign(a_id)), (&ty::Dynamic(a_obj, a_region, a_repr), &ty::Dynamic(b_obj, b_region, b_repr)) if a_repr == b_repr => @@ -444,7 +445,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| { relation.relate(a_region, b_region) })?; - Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound, a_repr)) + Ok(tcx.mk().dynamic(relation.relate(a_obj, b_obj)?, region_bound, a_repr)) } (&ty::Generator(a_id, a_substs, movability), &ty::Generator(b_id, b_substs, _)) @@ -454,7 +455,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( // the (anonymous) type of the same generator expression. So // all of their regions should be equated. let substs = relation.relate(a_substs, b_substs)?; - Ok(tcx.mk_generator(a_id, substs, movability)) + Ok(tcx.mk().generator(a_id, substs, movability)) } (&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => { @@ -464,7 +465,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( let b_types = b_types.map_bound(GeneratorWitness); // Then remove the GeneratorWitness for the result let types = relation.relate(a_types, b_types)?.map_bound(|witness| witness.0); - Ok(tcx.mk_generator_witness(types)) + Ok(tcx.mk().generator_witness(types)) } (&ty::GeneratorWitnessMIR(a_id, a_substs), &ty::GeneratorWitnessMIR(b_id, b_substs)) @@ -474,7 +475,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( // the (anonymous) type of the same generator expression. So // all of their regions should be equated. let substs = relation.relate(a_substs, b_substs)?; - Ok(tcx.mk_generator_witness_mir(a_id, substs)) + Ok(tcx.mk().generator_witness_mir(a_id, substs)) } (&ty::Closure(a_id, a_substs), &ty::Closure(b_id, b_substs)) if a_id == b_id => { @@ -482,12 +483,12 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( // the (anonymous) type of the same closure expression. So // all of their regions should be equated. let substs = relation.relate(a_substs, b_substs)?; - Ok(tcx.mk_closure(a_id, &substs)) + Ok(tcx.mk().closure(a_id, &substs)) } (&ty::RawPtr(a_mt), &ty::RawPtr(b_mt)) => { let mt = relate_type_and_mut(relation, a_mt, b_mt, a)?; - Ok(tcx.mk_ptr(mt)) + Ok(tcx.mk().ptr(mt)) } (&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => { @@ -495,13 +496,13 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl }; let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl }; let mt = relate_type_and_mut(relation, a_mt, b_mt, a)?; - Ok(tcx.mk_ref(r, mt)) + Ok(tcx.mk().ref_(r, mt)) } (&ty::Array(a_t, sz_a), &ty::Array(b_t, sz_b)) => { let t = relation.relate(a_t, b_t)?; match relation.relate(sz_a, sz_b) { - Ok(sz) => Ok(tcx.mk_array_with_const_len(t, sz)), + Ok(sz) => Ok(tcx.mk().array_with_const_len(t, sz)), Err(err) => { // Check whether the lengths are both concrete/known values, // but are unequal, for better diagnostics. @@ -524,12 +525,14 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( (&ty::Slice(a_t), &ty::Slice(b_t)) => { let t = relation.relate(a_t, b_t)?; - Ok(tcx.mk_slice(t)) + Ok(tcx.mk().slice(t)) } (&ty::Tuple(as_), &ty::Tuple(bs)) => { if as_.len() == bs.len() { - Ok(tcx.mk_tup_from_iter(iter::zip(as_, bs).map(|(a, b)| relation.relate(a, b)))?) + Ok(tcx + .mk() + .tup_from_iter(iter::zip(as_, bs).map(|(a, b)| relation.relate(a, b)))?) } else if !(as_.is_empty() || bs.is_empty()) { Err(TypeError::TupleSize(expected_found(relation, as_.len(), bs.len()))) } else { @@ -541,18 +544,18 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( if a_def_id == b_def_id => { let substs = relation.relate_item_substs(a_def_id, a_substs, b_substs)?; - Ok(tcx.mk_fn_def(a_def_id, substs)) + Ok(tcx.mk().fn_def(a_def_id, substs)) } (&ty::FnPtr(a_fty), &ty::FnPtr(b_fty)) => { let fty = relation.relate(a_fty, b_fty)?; - Ok(tcx.mk_fn_ptr(fty)) + Ok(tcx.mk().fn_ptr(fty)) } // these two are already handled downstream in case of lazy normalization (&ty::Alias(ty::Projection, a_data), &ty::Alias(ty::Projection, b_data)) => { let projection_ty = relation.relate(a_data, b_data)?; - Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs)) + Ok(tcx.mk().projection(projection_ty.def_id, projection_ty.substs)) } ( @@ -574,7 +577,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( b_substs, false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle )?; - Ok(tcx.mk_opaque(a_def_id, substs)) + Ok(tcx.mk().opaque(a_def_id, substs)) } } @@ -638,7 +641,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( au.substs, bu.substs, )?; - return Ok(tcx.mk_const(ty::UnevaluatedConst { def: au.def, substs }, a.ty())); + return Ok(tcx.mk().const_(ty::UnevaluatedConst { def: au.def, substs }, a.ty())); } // Before calling relate on exprs, it is necessary to ensure that the nested consts // have identical types. @@ -680,7 +683,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( _ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))), }; let kind = ty::ConstKind::Expr(expr); - return Ok(tcx.mk_const(kind, a.ty())); + return Ok(tcx.mk().const_(kind, a.ty())); } _ => false, }; @@ -721,7 +724,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List> { _ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))), } }); - tcx.mk_poly_existential_predicates_from_iter(v) + tcx.mk().poly_existential_predicates_from_iter(v) } } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index ef643531bb288..7db8d58cd92df 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -431,7 +431,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_poly_existential_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().poly_existential_predicates(v)) } } @@ -514,7 +514,7 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { | ty::Foreign(..) => return Ok(self), }; - Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty_from_kind(kind) }) + Ok(if *self.kind() == kind { self } else { folder.interner().mk().ty_from_kind(kind) }) } } @@ -637,7 +637,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().predicates(v)) } } @@ -664,7 +664,7 @@ impl<'tcx> TypeSuperFoldable> for ty::Const<'tcx> { let ty = self.ty().try_fold_with(folder)?; let kind = self.kind().try_fold_with(folder)?; if ty != self.ty() || kind != self.kind() { - Ok(folder.interner().mk_const(kind, ty)) + Ok(folder.interner().mk().const_(kind, ty)) } else { Ok(self) } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 52d114bae3007..a0e7b0df76b35 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -259,7 +259,7 @@ impl<'tcx> ClosureSubsts<'tcx> { parts: ClosureSubstsParts<'tcx, Ty<'tcx>>, ) -> ClosureSubsts<'tcx> { ClosureSubsts { - substs: tcx.mk_substs_from_iter( + substs: tcx.mk().substs_from_iter( parts.parent_substs.iter().copied().chain( [parts.closure_kind_ty, parts.closure_sig_as_fn_ptr_ty, parts.tupled_upvars_ty] .iter() @@ -386,7 +386,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { parts: GeneratorSubstsParts<'tcx, Ty<'tcx>>, ) -> GeneratorSubsts<'tcx> { GeneratorSubsts { - substs: tcx.mk_substs_from_iter( + substs: tcx.mk().substs_from_iter( parts.parent_substs.iter().copied().chain( [ parts.resume_ty, @@ -664,7 +664,7 @@ impl<'tcx> InlineConstSubsts<'tcx> { parts: InlineConstSubstsParts<'tcx, Ty<'tcx>>, ) -> InlineConstSubsts<'tcx> { InlineConstSubsts { - substs: tcx.mk_substs_from_iter( + substs: tcx.mk().substs_from_iter( parts.parent_substs.iter().copied().chain(std::iter::once(parts.ty.into())), ), } @@ -740,13 +740,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]) + tcx.mk().trait_ref(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) + tcx.mk().trait_ref(did, err_substs) }; self.rebind(trait_ref).without_const().to_predicate(tcx) } @@ -839,16 +839,16 @@ pub struct TraitRef<'tcx> { impl<'tcx> TraitRef<'tcx> { pub fn with_self_ty(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)), - ) + 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` 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( + tcx.mk().trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)), + ) } #[inline] @@ -862,7 +862,7 @@ 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()])) + tcx.mk().trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()])) } } @@ -920,7 +920,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())) + tcx.mk().trait_ref(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter())) } } @@ -1189,7 +1189,7 @@ impl<'tcx> FallibleTypeFolder> for SkipBindersAt<'tcx> { if index == self.index { Err(()) } else { - Ok(self.interner().mk_bound(index.shifted_out(1), bv)) + Ok(self.interner().mk().bound(index.shifted_out(1), bv)) } } else { ty.try_super_fold_with(self) @@ -1203,7 +1203,7 @@ impl<'tcx> FallibleTypeFolder> for SkipBindersAt<'tcx> { if index == self.index { Err(()) } else { - Ok(self.interner().mk_re_late_bound(index.shifted_out(1), bv)) + Ok(self.interner().mk().re_late_bound(index.shifted_out(1), bv)) } } else { r.try_super_fold_with(self) @@ -1217,7 +1217,7 @@ impl<'tcx> FallibleTypeFolder> for SkipBindersAt<'tcx> { if index == self.index { Err(()) } else { - Ok(self.interner().mk_const( + Ok(self.interner().mk().const_( ty::ConstKind::Bound(index.shifted_out(1), bv), ct.ty().try_fold_with(self)?, )) @@ -1278,7 +1278,7 @@ impl<'tcx> AliasTy<'tcx> { } pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - tcx.mk_alias(self.kind(tcx), self) + tcx.mk().alias(self.kind(tcx), self) } } @@ -1305,7 +1305,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)), + tcx.mk().trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)), &self.substs[trait_generics.count()..], ) } @@ -1319,7 +1319,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))) + tcx.mk().trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) } pub fn self_ty(self) -> Ty<'tcx> { @@ -1327,7 +1327,8 @@ impl<'tcx> AliasTy<'tcx> { } pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { - tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1))) + tcx.mk() + .alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1))) } } @@ -1425,7 +1426,7 @@ impl<'tcx> ParamTy { #[inline] pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - tcx.mk_ty_param(self.index, self.name) + tcx.mk().ty_param(self.index, self.name) } pub fn span_from_generics(&self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span { @@ -1574,7 +1575,8 @@ impl<'tcx> ExistentialProjection<'tcx> { ty::ProjectionPredicate { projection_ty: tcx - .mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)), + .mk() + .alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)), term: self.term, } } @@ -2218,7 +2220,7 @@ impl<'tcx> Ty<'tcx> { let assoc_items = tcx.associated_item_def_ids( tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), ); - tcx.mk_projection(assoc_items[0], tcx.mk_substs(&[self.into()])) + tcx.mk().projection(assoc_items[0], tcx.mk_substs(&[self.into()])) } ty::Bool diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index b090bd9d807c5..1bbbc6786e82a 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -303,7 +303,7 @@ impl<'tcx> InternalSubsts<'tcx> { /// Creates an `InternalSubsts` that maps each generic parameter to itself. pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { - Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param)) + Self::for_item(tcx, def_id, |param, _| tcx.mk().param_from_def(param)) } /// Creates an `InternalSubsts` for generic parameter definitions, @@ -468,11 +468,11 @@ impl<'tcx> InternalSubsts<'tcx> { target_substs: SubstsRef<'tcx>, ) -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); - tcx.mk_substs_from_iter(target_substs.iter().chain(self.iter().skip(defs.params.len()))) + tcx.mk().substs_from_iter(target_substs.iter().chain(self.iter().skip(defs.params.len()))) } pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> { - tcx.mk_substs_from_iter(self.iter().take(generics.count())) + tcx.mk().substs_from_iter(self.iter().take(generics.count())) } } @@ -538,10 +538,10 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().mk_type_list(&[param0, param1])) + Ok(folder.interner().mk().type_list(&[param0, param1])) } } - _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_type_list(v)), + _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk().type_list(v)), } } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index b0f6127baa5d4..5f3c972404343 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -573,12 +573,12 @@ impl<'tcx> TyCtxt<'tcx> { closure_substs: SubstsRef<'tcx>, env_region: ty::Region<'tcx>, ) -> Option> { - let closure_ty = self.mk_closure(closure_def_id, closure_substs); + let closure_ty = self.mk().closure(closure_def_id, closure_substs); let closure_kind_ty = closure_substs.as_closure().kind_ty(); let closure_kind = closure_kind_ty.to_opt_closure_kind()?; let env_ty = match closure_kind { - ty::ClosureKind::Fn => self.mk_imm_ref(env_region, closure_ty), - ty::ClosureKind::FnMut => self.mk_mut_ref(env_region, closure_ty), + ty::ClosureKind::Fn => self.mk().imm_ref(env_region, closure_ty), + ty::ClosureKind::FnMut => self.mk().mut_ref(env_region, closure_ty), ty::ClosureKind::FnOnce => closure_ty, }; Some(env_ty) @@ -617,11 +617,11 @@ impl<'tcx> TyCtxt<'tcx> { // Make sure that accesses to unsafe statics end up using raw pointers. // For thread-locals, this needs to be kept in sync with `Rvalue::ty`. if self.is_mutable_static(def_id) { - self.mk_mut_ptr(static_ty) + self.mk().mut_ptr(static_ty) } else if self.is_foreign_item(def_id) { - self.mk_imm_ptr(static_ty) + self.mk().imm_ptr(static_ty) } else { - self.mk_imm_ref(self.lifetimes.re_erased, static_ty) + self.mk().imm_ref(self.lifetimes.re_erased, static_ty) } } @@ -867,7 +867,7 @@ impl<'tcx> OpaqueTypeExpander<'tcx> { let hidden_ty = bty.subst(self.tcx, substs); self.fold_ty(hidden_ty); } - let expanded_ty = self.tcx.mk_generator_witness_mir(def_id, substs); + let expanded_ty = self.tcx.mk().generator_witness_mir(def_id, substs); self.expanded_cache.insert((def_id, substs), expanded_ty); expanded_ty } diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 55aa4fcff2cdb..2ae4a2bda4de4 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -48,7 +48,7 @@ impl<'tcx> Value, DepKind> for ty::Binder<'_, ty::FnSig<'_>> { unreachable!() }; - let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig( + let fn_sig = ty::Binder::dummy(tcx.mk().fn_sig( std::iter::repeat(err).take(arity), err, false, diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index cfacb5ea32777..1e675d00b7625 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -84,7 +84,7 @@ pub fn as_constant_inner<'tcx>( Constant { user_ty, span, literal } } ExprKind::ConstParam { param, def_id: _ } => { - let const_param = tcx.mk_const(ty::ConstKind::Param(param), expr.ty); + let const_param = tcx.mk().const_(ty::ConstKind::Param(param), expr.ty); let literal = ConstantKind::Ty(const_param); Constant { user_ty: None, span, literal } diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 33200b80a572d..63bbb7503f760 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -689,7 +689,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) .ty; let fake_borrow_ty = - tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); + tcx.mk().imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); let fake_borrow_temp = self.local_decls.push(LocalDecl::new(fake_borrow_ty, expr_span)); let projection = tcx.mk_place_elems(&base_place.projection[..idx]); diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index a4e48c1545d6c..c04285a5909fb 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -145,7 +145,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { [], expr_span, ); - let storage = this.temp(tcx.mk_mut_ptr(tcx.types.u8), expr_span); + let storage = this.temp(tcx.mk().mut_ptr(tcx.types.u8), expr_span); let success = this.cfg.start_new_block(); this.cfg.terminate( block, @@ -183,7 +183,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // initialize the box contents: unpack!( block = this.expr_into_dest( - this.tcx.mk_place_deref(Place::from(result)), + this.tcx.mk().place_deref(Place::from(result)), block, value ) @@ -520,7 +520,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let source_info = self.source_info(span); let bool_ty = self.tcx.types.bool; if self.check_overflow && op.is_checkable() && ty.is_integral() { - let result_tup = self.tcx.mk_tup(&[ty, bool_ty]); + let result_tup = self.tcx.mk().tup(&[ty, bool_ty]); let result_value = self.temp(result_tup, span); self.cfg.push_assign( @@ -533,8 +533,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let of_fld = Field::new(1); let tcx = self.tcx; - let val = tcx.mk_place_field(result_value, val_fld, ty); - let of = tcx.mk_place_field(result_value, of_fld, bool_ty); + let val = tcx.mk().place_field(result_value, val_fld, ty); + let of = tcx.mk().place_field(result_value, of_fld, bool_ty); let err = AssertKind::Overflow(op, lhs, rhs); diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 3fb8a6db2d27a..ff0a8d78d662c 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1751,7 +1751,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { projection: tcx.mk_place_elems(matched_place_ref.projection), }; let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty; - let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); + let fake_borrow_ty = tcx.mk().imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); let mut fake_borrow_temp = LocalDecl::new(fake_borrow_ty, temp_span); fake_borrow_temp.internal = self.local_decls[matched_place.local].internal; fake_borrow_temp.local_info = Some(Box::new(LocalInfo::FakeBorrow)); @@ -2249,7 +2249,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // This variable isn't mutated but has a name, so has to be // immutable to avoid the unused mut lint. mutability: Mutability::Not, - ty: tcx.mk_imm_ref(tcx.lifetimes.re_erased, var_ty), + ty: tcx.mk().imm_ref(tcx.lifetimes.re_erased, var_ty), user_ty: None, source_info, internal: false, diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 2de89f67dfdc7..a90782888a1b6 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -244,8 +244,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { bug!("matching on `String` went through without enabling string_deref_patterns"); } let re_erased = tcx.lifetimes.re_erased; - let ref_string = self.temp(tcx.mk_imm_ref(re_erased, ty), test.span); - let ref_str_ty = tcx.mk_imm_ref(re_erased, tcx.types.str_); + let ref_string = self.temp(tcx.mk().imm_ref(re_erased, ty), test.span); + let ref_str_ty = tcx.mk().imm_ref(re_erased, tcx.types.str_); let ref_str = self.temp(ref_str_ty, test.span); let deref = tcx.require_lang_item(LangItem::Deref, None); let method = trait_method(tcx, deref, sym::deref, [ty]); @@ -414,7 +414,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => { let tcx = self.tcx; // make both a slice - ty = tcx.mk_imm_ref(*region, tcx.mk_slice(*elem_ty)); + ty = tcx.mk().imm_ref(*region, tcx.mk().slice(*elem_ty)); if opt_ref_ty.is_some() { let temp = self.temp(ty, source_info.span); self.cfg.push_assign( @@ -842,7 +842,7 @@ fn trait_method<'tcx>( .find(|item| item.kind == ty::AssocKind::Fn) .expect("trait method not found"); - let method_ty = tcx.mk_fn_def(item.def_id, substs); + let method_ty = tcx.mk().fn_def(item.def_id, substs); ConstantKind::zero_sized(method_ty) } diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 70d5fc2d9588a..5a722635cbd27 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -934,7 +934,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match self.unit_temp { Some(tmp) => tmp, None => { - let ty = self.tcx.mk_unit(); + let ty = self.tcx.mk().unit(); let fn_span = self.fn_span; let tmp = self.temp(ty, fn_span); self.unit_temp = Some(tmp); diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 4bc2c0ca791e6..5c8be27d66b73 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -720,7 +720,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Add a dummy `Assign` statement to the CFG, with the span for the source code's `continue` // statement. fn add_dummy_assignment(&mut self, span: Span, block: BasicBlock, source_info: SourceInfo) { - let local_decl = LocalDecl::new(self.tcx.mk_unit(), span).internal(); + let local_decl = LocalDecl::new(self.tcx.mk().unit(), span).internal(); let temp_place = Place::from(self.local_decls.push(local_decl)); self.cfg.push_assign_unit(block, source_info, temp_place, self.tcx); } diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 57ae6a3652df5..929c4f39efed1 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -61,5 +61,5 @@ pub(crate) fn lit_to_const<'tcx>( _ => return Err(LitToConstError::TypeError), }; - Ok(tcx.mk_const(valtree, ty)) + Ok(tcx.mk().const_(valtree, ty)) } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 9086412c09a1c..0ad9e01f137df 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -144,7 +144,8 @@ impl<'tcx> Cx<'tcx> { temp_lifetime, ty: self .tcx - .mk_ref(deref.region, ty::TypeAndMut { ty: expr.ty, mutbl: deref.mutbl }), + .mk() + .ref_(deref.region, ty::TypeAndMut { ty: expr.ty, mutbl: deref.mutbl }), span, kind: ExprKind::Borrow { borrow_kind: deref.mutbl.to_borrow_kind(), @@ -307,7 +308,7 @@ impl<'tcx> Cx<'tcx> { let arg_tys = args.iter().map(|e| self.typeck_results().expr_ty_adjusted(e)); let tupled_args = Expr { - ty: tcx.mk_tup_from_iter(arg_tys), + ty: tcx.mk().tup_from_iter(arg_tys), temp_lifetime, span: expr.span, kind: ExprKind::Tuple { fields: self.mirror_exprs(args) }, @@ -846,7 +847,7 @@ impl<'tcx> Cx<'tcx> { let user_ty = self.user_substs_applied_to_res(expr.hir_id, Res::Def(kind, def_id)); debug!("method_callee: user_ty={:?}", user_ty); ( - self.tcx().mk_fn_def(def_id, self.typeck_results().node_substs(expr.hir_id)), + self.tcx().mk().fn_def(def_id, self.typeck_results().node_substs(expr.hir_id)), user_ty, ) } @@ -999,7 +1000,7 @@ impl<'tcx> Cx<'tcx> { let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else { span_bug!(span, "overloaded_place: receiver is not a reference"); }; - let ref_ty = self.tcx.mk_ref(region, ty::TypeAndMut { ty: place_ty, mutbl }); + let ref_ty = self.tcx.mk().ref_(region, ty::TypeAndMut { ty: place_ty, mutbl }); // construct the complete expression `foo()` for the overloaded call, // which will yield the &T type diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 070544446e348..38723e52e0d3c 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -40,7 +40,7 @@ pub(crate) fn thir_body( // It will always be `()` in this case. if tcx.def_kind(owner_def.did) == DefKind::Generator && body.params.is_empty() { cx.thir.params.push(Param { - ty: tcx.mk_unit(), + ty: tcx.mk().unit(), pat: None, ty_span: None, self_kind: None, @@ -143,7 +143,7 @@ impl<'tcx> Cx<'tcx> { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BrEnv, }; - let env_region = self.tcx.mk_re_late_bound(ty::INNERMOST, br); + let env_region = self.tcx.mk().re_late_bound(ty::INNERMOST, br); let closure_env_ty = self.tcx.closure_env_ty(closure_def_id, closure_substs, env_region).unwrap(); let liberated_closure_env_ty = self.tcx.erase_late_bound_regions( diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index ff88d00135173..7c53792b9d57c 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -394,7 +394,7 @@ impl<'tcx> ConstToPat<'tcx> { suffix: Box::new([]), }, span, - ty: tcx.mk_slice(elem_ty), + ty: tcx.mk().slice(elem_ty), }), }; self.behind_reference.set(old); diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index bd12087629c99..11f11bda74a07 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -276,7 +276,7 @@ where assert_eq!(self.elaborator.param_env().reveal(), Reveal::All); let field_ty = tcx.normalize_erasing_regions(self.elaborator.param_env(), f.ty(tcx, substs)); - (tcx.mk_place_field(base_place, field, field_ty), subpath) + (tcx.mk().place_field(base_place, field, field_ty), subpath) }) .collect() } @@ -397,7 +397,7 @@ where .enumerate() .map(|(i, &ty)| { ( - self.tcx().mk_place_field(self.place, Field::new(i), ty), + self.tcx().mk().place_field(self.place, Field::new(i), ty), self.elaborator.field_subpath(self.path, Field::new(i)), ) }) @@ -414,12 +414,12 @@ where let unique_ty = adt.non_enum_variant().fields[0].ty(self.tcx(), substs); let nonnull_ty = unique_ty.ty_adt_def().unwrap().non_enum_variant().fields[0].ty(self.tcx(), substs); - let ptr_ty = self.tcx().mk_imm_ptr(substs[0].expect_ty()); + let ptr_ty = self.tcx().mk().imm_ptr(substs[0].expect_ty()); - let unique_place = self.tcx().mk_place_field(self.place, Field::new(0), unique_ty); - let nonnull_place = self.tcx().mk_place_field(unique_place, Field::new(0), nonnull_ty); - let ptr_place = self.tcx().mk_place_field(nonnull_place, Field::new(0), ptr_ty); - let interior = self.tcx().mk_place_deref(ptr_place); + let unique_place = self.tcx().mk().place_field(self.place, Field::new(0), unique_ty); + let nonnull_place = self.tcx().mk().place_field(unique_place, Field::new(0), nonnull_ty); + let ptr_place = self.tcx().mk().place_field(nonnull_place, Field::new(0), ptr_ty); + let interior = self.tcx().mk().place_deref(ptr_place); let interior_path = self.elaborator.deref_subpath(self.path); @@ -498,7 +498,7 @@ where let subpath = self.elaborator.downcast_subpath(self.path, variant_index); if let Some(variant_path) = subpath { - let base_place = tcx.mk_place_elem( + let base_place = tcx.mk().place_elem( self.place, ProjectionElem::Downcast(Some(variant.name), variant_index), ); @@ -615,10 +615,11 @@ where let drop_fn = tcx.associated_item_def_ids(drop_trait)[0]; let ty = self.place_ty(self.place); - let ref_ty = - tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut }); + let ref_ty = tcx + .mk() + .ref_(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut }); let ref_place = self.new_temp(ref_ty); - let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); + let unit_temp = Place::from(self.new_temp(tcx.mk().unit())); let result = BasicBlockData { statements: vec![self.assign( @@ -680,7 +681,7 @@ where let move_ = |place: Place<'tcx>| Operand::Move(place); let tcx = self.tcx(); - let ptr_ty = tcx.mk_ptr(ty::TypeAndMut { ty: ety, mutbl: hir::Mutability::Mut }); + let ptr_ty = tcx.mk().ptr(ty::TypeAndMut { ty: ety, mutbl: hir::Mutability::Mut }); let ptr = Place::from(self.new_temp(ptr_ty)); let can_go = Place::from(self.new_temp(tcx.types.bool)); @@ -692,7 +693,7 @@ where ) } else { ( - Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place, cur)), + Rvalue::AddressOf(Mutability::Mut, tcx.mk().place_index(self.place, cur)), Rvalue::BinaryOp(BinOp::Add, Box::new((move_(cur.into()), one))), ) }; @@ -727,7 +728,7 @@ where self.elaborator.patch().patch_terminator( drop_block, TerminatorKind::Drop { - place: tcx.mk_place_deref(ptr), + place: tcx.mk().place_deref(ptr), target: loop_block, unwind: unwind.into_option(), }, @@ -751,7 +752,7 @@ where let fields: Vec<(Place<'tcx>, Option)> = (0..size) .map(|i| { ( - tcx.mk_place_elem( + tcx.mk().place_elem( self.place, ProjectionElem::ConstantIndex { offset: i, @@ -806,7 +807,7 @@ where ) -> BasicBlock { debug!("drop_loop_pair({:?}, {:?})", ety, ptr_based); let tcx = self.tcx(); - let iter_ty = if ptr_based { tcx.mk_mut_ptr(ety) } else { tcx.types.usize }; + let iter_ty = if ptr_based { tcx.mk().mut_ptr(ety) } else { tcx.types.usize }; let cur = self.new_temp(iter_ty); let length_or_end = if ptr_based { Place::from(self.new_temp(iter_ty)) } else { length }; @@ -819,7 +820,7 @@ where let cur = Place::from(cur); let drop_block_stmts = if ptr_based { - let tmp_ty = tcx.mk_mut_ptr(self.place_ty(self.place)); + let tmp_ty = tcx.mk().mut_ptr(self.place_ty(self.place)); let tmp = Place::from(self.new_temp(tmp_ty)); // tmp = &raw mut P; // cur = tmp as *mut T; @@ -960,7 +961,7 @@ where unwind: Unwind, ) -> BasicBlock { let tcx = self.tcx(); - let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); + let unit_temp = Place::from(self.new_temp(tcx.mk().unit())); let free_func = tcx.require_lang_item(LangItem::BoxFree, Some(self.source_info.span)); let args = adt .variant(VariantIdx::new(0)) @@ -970,7 +971,7 @@ where .map(|(i, f)| { let field = Field::new(i); let field_ty = f.ty(tcx, substs); - Operand::Move(tcx.mk_place_field(self.place, field, field_ty)) + Operand::Move(tcx.mk().place_field(self.place, field, field_ty)) }) .collect(); diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index d9ceac1154f4a..b13b45a514f37 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -304,7 +304,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { // Box starts out uninitialized - need to create a separate // move-path for the interior so it will be separate from // the exterior. - self.create_move_path(self.builder.tcx.mk_place_deref(*place)); + self.create_move_path(self.builder.tcx.mk().place_deref(*place)); self.gather_init(place.as_ref(), InitKind::Shallow); } else { self.gather_init(place.as_ref(), InitKind::Deep); @@ -494,8 +494,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { for offset in from..to { let elem = ProjectionElem::ConstantIndex { offset, min_length: len, from_end: false }; - let path = - self.add_move_path(base_path, elem, |tcx| tcx.mk_place_elem(base_place, elem)); + let path = self + .add_move_path(base_path, elem, |tcx| tcx.mk().place_elem(base_place, elem)); self.record_move(place, path); } } else { diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 954bb5aff8de6..5bef82dbd8876 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -20,7 +20,7 @@ pub fn build_ptr_tys<'tcx>( let substs = tcx.mk_substs(&[pointee.into()]); let unique_ty = tcx.type_of(unique_did).subst(tcx, substs); let nonnull_ty = tcx.type_of(nonnull_did).subst(tcx, substs); - let ptr_ty = tcx.mk_imm_ptr(pointee); + let ptr_ty = tcx.mk().imm_ptr(pointee); (unique_ty, nonnull_ty, ptr_ty) } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index b7f1cdfc7f219..0e256e641d569 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -295,7 +295,7 @@ impl<'tcx> TransformVisitor<'tcx> { // Create a Place referencing a generator struct field fn make_field(&self, variant_index: VariantIdx, idx: usize, ty: Ty<'tcx>) -> Place<'tcx> { let self_place = Place::from(SELF_ARG); - let base = self.tcx.mk_place_downcast_unnamed(self_place, variant_index); + let base = self.tcx.mk().place_downcast_unnamed(self_place, variant_index); let mut projection = base.projection.to_vec(); projection.push(ProjectionElem::Field(Field::new(idx), ty)); @@ -411,8 +411,9 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let gen_ty = body.local_decls.raw[1].ty; - let ref_gen_ty = - tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut }); + let ref_gen_ty = tcx + .mk() + .ref_(tcx.lifetimes.re_erased, ty::TypeAndMut { ty: gen_ty, mutbl: Mutability::Mut }); // Replace the by value generator argument body.local_decls.raw[1].ty = ref_gen_ty; @@ -427,7 +428,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span)); let pin_adt_ref = tcx.adt_def(pin_did); let substs = tcx.mk_substs(&[ref_gen_ty.into()]); - let pin_ref_gen_ty = tcx.mk_adt(pin_adt_ref, substs); + let pin_ref_gen_ty = tcx.mk().adt(pin_adt_ref, substs); // Replace the by ref generator argument body.local_decls.raw[1].ty = pin_ref_gen_ty; @@ -479,7 +480,7 @@ fn replace_local<'tcx>( /// still using the `ResumeTy` indirection for the time being, and that indirection /// is removed here. After this transform, the generator body only knows about `&mut Context<'_>`. fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let context_mut_ref = tcx.mk_task_context(); + let context_mut_ref = tcx.mk().task_context(); // replace the type of the `resume` argument replace_resume_ty_local(tcx, body, Local::new(2), context_mut_ref); @@ -1097,13 +1098,13 @@ fn create_generator_drop_shim<'tcx>( } // Replace the return variable - body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(tcx.mk_unit(), source_info); + body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(tcx.mk().unit(), source_info); make_generator_state_argument_indirect(tcx, &mut body); // Change the generator argument from &mut to *mut body.local_decls[SELF_ARG] = LocalDecl::with_source_info( - tcx.mk_ptr(ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }), + tcx.mk().ptr(ty::TypeAndMut { ty: gen_ty, mutbl: hir::Mutability::Mut }), source_info, ); @@ -1457,7 +1458,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { let state_substs = tcx.mk_substs(&[yield_ty.into(), body.return_ty().into()]); (state_adt_ref, state_substs) }; - let ret_ty = tcx.mk_adt(state_adt_ref, state_substs); + let ret_ty = tcx.mk().adt(state_adt_ref, state_substs); // We rename RETURN_PLACE which has type mir.return_ty to new_ret_local // RETURN_PLACE then is a fresh unused local with type ret_ty. @@ -1474,7 +1475,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // state. After the yield the slot in the generator state would then be uninitialized. let resume_local = Local::new(2); let resume_ty = - if is_async_kind { tcx.mk_task_context() } else { body.local_decls[resume_local].ty }; + if is_async_kind { tcx.mk().task_context() } else { body.local_decls[resume_local].ty }; let new_resume_local = replace_local(resume_local, resume_ty, body, tcx); // When first entering the generator, move the resume argument into its new local. diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 9cba8870f2377..298845bc9492d 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -535,7 +535,7 @@ impl<'tcx> Inliner<'tcx> { source_info: callsite.source_info, kind: StatementKind::Assign(Box::new((temp, dest))), }); - self.tcx.mk_place_deref(temp) + self.tcx.mk().place_deref(temp) } else { destination }; @@ -706,7 +706,7 @@ impl<'tcx> Inliner<'tcx> { // The `tmp0`, `tmp1`, and `tmp2` in our example above. let tuple_tmp_args = tuple_tys.iter().enumerate().map(|(i, ty)| { // This is e.g., `tuple_tmp.0` in our example above. - let tuple_field = Operand::Move(tcx.mk_place_field(tuple, Field::new(i), ty)); + let tuple_field = Operand::Move(tcx.mk().place_field(tuple, Field::new(i), ty)); // Spill to a local to make e.g., `tmp0`. self.create_temp_if_necessary(tuple_field, callsite, caller_body) diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index 9447a2ff04095..a4db9c2e1d4e9 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -141,7 +141,7 @@ impl EnumSizeOpt { self.candidate(tcx, param_env, ty, &mut alloc_cache)?; let alloc = tcx.global_alloc(alloc_id).unwrap_memory(); - let tmp_ty = tcx.mk_array(tcx.types.usize, num_variants as u64); + let tmp_ty = tcx.mk().array(tcx.types.usize, num_variants as u64); let size_array_local = local_decls.push(LocalDecl::new(tmp_ty, span)); let store_live = Statement { @@ -209,7 +209,7 @@ impl EnumSizeOpt { }; let dst = - Place::from(local_decls.push(LocalDecl::new(tcx.mk_mut_ptr(ty), span))); + Place::from(local_decls.push(LocalDecl::new(tcx.mk().mut_ptr(ty), span))); let dst_ptr = Statement { source_info, @@ -219,7 +219,7 @@ impl EnumSizeOpt { ))), }; - let dst_cast_ty = tcx.mk_mut_ptr(tcx.types.u8); + let dst_cast_ty = tcx.mk().mut_ptr(tcx.types.u8); let dst_cast_place = Place::from(local_decls.push(LocalDecl::new(dst_cast_ty, span))); @@ -232,7 +232,7 @@ impl EnumSizeOpt { }; let src = - Place::from(local_decls.push(LocalDecl::new(tcx.mk_imm_ptr(ty), span))); + Place::from(local_decls.push(LocalDecl::new(tcx.mk().imm_ptr(ty), span))); let src_ptr = Statement { source_info, @@ -242,7 +242,7 @@ impl EnumSizeOpt { ))), }; - let src_cast_ty = tcx.mk_imm_ptr(tcx.types.u8); + let src_cast_ty = tcx.mk().imm_ptr(tcx.types.u8); let src_cast_place = Place::from(local_decls.push(LocalDecl::new(src_cast_ty, span))); diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index 5d7382305ae14..650367fc89ac8 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -155,7 +155,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { }; let derefed_place = if let Some(place) = arg.place() && let Some(local) = place.as_local() { - tcx.mk_place_deref(local.into()) + tcx.mk().place_deref(local.into()) } else { span_bug!(terminator.source_info.span, "Only passing a local is supported"); }; @@ -180,7 +180,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { } sym::discriminant_value => { if let (Some(target), Some(arg)) = (*target, args[0].place()) { - let arg = tcx.mk_place_deref(arg); + let arg = tcx.mk().place_deref(arg); block.statements.push(Statement { source_info: terminator.source_info, kind: StatementKind::Assign(Box::new(( diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index c6e7468aab429..98d1ee9b80ff2 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -75,7 +75,7 @@ fn lower_slice_len_call<'tcx>( // ``` // make new RValue for Len - let deref_arg = tcx.mk_place_deref(arg); + let deref_arg = tcx.mk().place_deref(arg); let r_value = Rvalue::Len(deref_arg); let len_statement_kind = StatementKind::Assign(Box::new((*destination, r_value))); diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index ebe63d6cb7e33..906500913b6e1 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -187,7 +187,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) let reborrow = Rvalue::Ref( tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, - tcx.mk_place_deref(dropee_ptr), + tcx.mk().place_deref(dropee_ptr), ); let ref_ty = reborrow.ty(body.local_decls(), tcx); dropee_ptr = body.local_decls.push(LocalDecl::new(ref_ty, span)).into(); @@ -207,7 +207,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) let param_env = tcx.param_env_reveal_all_normalized(def_id); let mut elaborator = DropShimElaborator { body: &body, patch: MirPatch::new(&body), tcx, param_env }; - let dropee = tcx.mk_place_deref(dropee_ptr); + let dropee = tcx.mk().place_deref(dropee_ptr); let resume_block = elaborator.patch.resume_block(); elaborate_drops::elaborate_drop( &mut elaborator, @@ -331,7 +331,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env); let dest = Place::return_place(); - let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0))); + let src = tcx.mk().place_deref(Place::from(Local::new(1 + 0))); match self_ty.kind() { _ if is_copy => builder.copy_shim(), @@ -415,7 +415,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { } fn copy_shim(&mut self) { - let rcvr = self.tcx.mk_place_deref(Place::from(Local::new(1 + 0))); + let rcvr = self.tcx.mk().place_deref(Place::from(Local::new(1 + 0))); let ret_statement = self.make_statement(StatementKind::Assign(Box::new(( Place::return_place(), Rvalue::Use(Operand::Copy(rcvr)), @@ -443,7 +443,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { let tcx = self.tcx; // `func == Clone::clone(&ty) -> ty` - let func_ty = tcx.mk_fn_def(self.def_id, [ty]); + let func_ty = tcx.mk().fn_def(self.def_id, [ty]); let func = Operand::Constant(Box::new(Constant { span: self.span, user_ty: None, @@ -452,7 +452,8 @@ impl<'tcx> CloneShimBuilder<'tcx> { let ref_loc = self.make_place( Mutability::Not, - tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }), + tcx.mk() + .ref_(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }), ); // `let ref_loc: &ty = &src;` @@ -501,9 +502,9 @@ impl<'tcx> CloneShimBuilder<'tcx> { // will unwind to it if cloning fails. let field = Field::new(i); - let src_field = self.tcx.mk_place_field(src, field, ity); + let src_field = self.tcx.mk().place_field(src, field, ity); - let dest_field = self.tcx.mk_place_field(dest, field, ity); + let dest_field = self.tcx.mk().place_field(dest, field, ity); let next_unwind = self.block_index_offset(1); let next_block = self.block_index_offset(2); @@ -548,8 +549,8 @@ impl<'tcx> CloneShimBuilder<'tcx> { let mut cases = Vec::with_capacity(substs.state_tys(gen_def_id, self.tcx).count()); for (index, state_tys) in substs.state_tys(gen_def_id, self.tcx).enumerate() { let variant_index = VariantIdx::new(index); - let dest = self.tcx.mk_place_downcast_unnamed(dest, variant_index); - let src = self.tcx.mk_place_downcast_unnamed(src, variant_index); + let dest = self.tcx.mk().place_downcast_unnamed(dest, variant_index); + let src = self.tcx.mk().place_downcast_unnamed(src, variant_index); let clone_block = self.block_index_offset(1); let start_block = self.block( vec![self.make_statement(StatementKind::SetDiscriminant { @@ -597,7 +598,7 @@ fn build_call_shim<'tcx>( let untuple_args = sig.inputs(); // Create substitutions for the `Self` and `Args` generic parameters of the shim body. - let arg_tup = tcx.mk_tup(untuple_args); + let arg_tup = tcx.mk().tup(untuple_args); (Some([ty.into(), arg_tup.into()]), Some(untuple_args)) } else { @@ -629,10 +630,10 @@ fn build_call_shim<'tcx>( let self_arg = &mut inputs_and_output[0]; *self_arg = match rcvr_adjustment.unwrap() { Adjustment::Identity => fnty, - Adjustment::Deref => tcx.mk_imm_ptr(fnty), - Adjustment::RefMut => tcx.mk_mut_ptr(fnty), + Adjustment::Deref => tcx.mk().imm_ptr(fnty), + Adjustment::RefMut => tcx.mk().mut_ptr(fnty), }; - sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); + sig.inputs_and_output = tcx.mk().type_list(&inputs_and_output); } // FIXME(eddyb) avoid having this snippet both here and in @@ -642,8 +643,8 @@ fn build_call_shim<'tcx>( let mut inputs_and_output = sig.inputs_and_output.to_vec(); let self_arg = &mut inputs_and_output[0]; debug_assert!(tcx.generics_of(def_id).has_self && *self_arg == tcx.types.self_param); - *self_arg = tcx.mk_mut_ptr(*self_arg); - sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); + *self_arg = tcx.mk().mut_ptr(*self_arg); + sig.inputs_and_output = tcx.mk().type_list(&inputs_and_output); } let span = tcx.def_span(def_id); @@ -661,12 +662,12 @@ fn build_call_shim<'tcx>( let rcvr = rcvr_adjustment.map(|rcvr_adjustment| match rcvr_adjustment { Adjustment::Identity => Operand::Move(rcvr_place()), - Adjustment::Deref => Operand::Move(tcx.mk_place_deref(rcvr_place())), + Adjustment::Deref => Operand::Move(tcx.mk().place_deref(rcvr_place())), Adjustment::RefMut => { // let rcvr = &mut rcvr; let ref_rcvr = local_decls.push( LocalDecl::new( - tcx.mk_ref( + tcx.mk().ref_( tcx.lifetimes.re_erased, ty::TypeAndMut { ty: sig.inputs()[0], mutbl: hir::Mutability::Mut }, ), @@ -723,7 +724,7 @@ fn build_call_shim<'tcx>( if let Some(untuple_args) = untuple_args { let tuple_arg = Local::new(1 + (sig.inputs().len() - 1)); args.extend(untuple_args.iter().enumerate().map(|(i, ity)| { - Operand::Move(tcx.mk_place_field(Place::from(tuple_arg), Field::new(i), *ity)) + Operand::Move(tcx.mk().place_field(Place::from(tuple_arg), Field::new(i), *ity)) })); } diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index ca2221520c825..93f7ec3764296 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -325,7 +325,7 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> { // Put the deaggregated statements *after* the original one. let location = location.successor_within_block(); for (field, ty, new_local) in final_locals { - let rplace = self.tcx.mk_place_field(place, field, ty); + let rplace = self.tcx.mk().place_field(place, field, ty); let rvalue = Rvalue::Use(Operand::Move(rplace)); self.patch.add_statement( location, @@ -352,7 +352,7 @@ impl<'tcx, 'll> MutVisitor<'tcx> for ReplacementVisitor<'tcx, 'll> { }; if let Some(final_locals) = self.replacements.place_fragments(lhs) { for (field, ty, new_local) in final_locals { - let rplace = self.tcx.mk_place_field(rplace, field, ty); + let rplace = self.tcx.mk().place_field(rplace, field, ty); debug!(?rplace); let rplace = self .replacements diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index ef7c68c1a335a..07ea751c7112f 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -135,7 +135,7 @@ where let def_id = tcx.impl_trait_in_trait_parent(projection.def_id); let trait_generics = tcx.generics_of(def_id); ( - tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)), + tcx.mk().trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)), &projection.substs[trait_generics.count()..], ) }; diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 1a679f32ca59b..2a9a810efad04 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -594,7 +594,7 @@ fn encode_ty<'tcx>( s.push_str("u3refI"); s.push_str(&encode_ty(tcx, *ty0, dict, options)); s.push('E'); - compress(dict, DictKey::Ty(tcx.mk_imm_ref(*region, *ty0), TyQ::None), &mut s); + compress(dict, DictKey::Ty(tcx.mk().imm_ref(*region, *ty0), TyQ::None), &mut s); if ty.is_mutable_ptr() { s = format!("{}{}", "U3mut", &s); compress(dict, DictKey::Ty(ty, TyQ::Mut), &mut s); @@ -675,24 +675,24 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio _ if ty.is_unit() => {} ty::Tuple(tys) => { - ty = tcx.mk_tup_from_iter(tys.iter().map(|ty| transform_ty(tcx, ty, options))); + ty = tcx.mk().tup_from_iter(tys.iter().map(|ty| transform_ty(tcx, ty, options))); } ty::Array(ty0, len) => { let len = len.kind().try_to_scalar().unwrap().to_u64().unwrap(); - ty = tcx.mk_array(transform_ty(tcx, *ty0, options), len); + ty = tcx.mk().array(transform_ty(tcx, *ty0, options), len); } ty::Slice(ty0) => { - ty = tcx.mk_slice(transform_ty(tcx, *ty0, options)); + ty = tcx.mk().slice(transform_ty(tcx, *ty0, options)); } ty::Adt(adt_def, substs) => { if is_c_void_ty(tcx, ty) { - ty = tcx.mk_unit(); + ty = tcx.mk().unit(); } else if options.contains(TransformTyOptions::GENERALIZE_REPR_C) && adt_def.repr().c() { - ty = tcx.mk_adt(*adt_def, ty::List::empty()); + ty = tcx.mk().adt(*adt_def, ty::List::empty()); } else if adt_def.repr().transparent() && adt_def.is_struct() { let variant = adt_def.non_enum_variant(); let param_env = tcx.param_env(variant.def_id); @@ -718,37 +718,37 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio } } else { // Transform repr(transparent) types without non-ZST field into () - ty = tcx.mk_unit(); + ty = tcx.mk().unit(); } } else { - ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options)); + ty = tcx.mk().adt(*adt_def, transform_substs(tcx, substs, options)); } } ty::FnDef(def_id, substs) => { - ty = tcx.mk_fn_def(*def_id, transform_substs(tcx, substs, options)); + ty = tcx.mk().fn_def(*def_id, transform_substs(tcx, substs, options)); } ty::Closure(def_id, substs) => { - ty = tcx.mk_closure(*def_id, transform_substs(tcx, substs, options)); + ty = tcx.mk().closure(*def_id, transform_substs(tcx, substs, options)); } ty::Generator(def_id, substs, movability) => { - ty = tcx.mk_generator(*def_id, transform_substs(tcx, substs, options), *movability); + ty = tcx.mk().generator(*def_id, transform_substs(tcx, substs, options), *movability); } ty::Ref(region, ty0, ..) => { if options.contains(TransformTyOptions::GENERALIZE_POINTERS) { if ty.is_mutable_ptr() { - ty = tcx.mk_mut_ref(tcx.lifetimes.re_static, tcx.mk_unit()); + ty = tcx.mk().mut_ref(tcx.lifetimes.re_static, tcx.mk().unit()); } else { - ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_unit()); + ty = tcx.mk().imm_ref(tcx.lifetimes.re_static, tcx.mk().unit()); } } else { if ty.is_mutable_ptr() { - ty = tcx.mk_mut_ref(*region, transform_ty(tcx, *ty0, options)); + ty = tcx.mk().mut_ref(*region, transform_ty(tcx, *ty0, options)); } else { - ty = tcx.mk_imm_ref(*region, transform_ty(tcx, *ty0, options)); + ty = tcx.mk().imm_ref(*region, transform_ty(tcx, *ty0, options)); } } } @@ -756,22 +756,22 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio ty::RawPtr(tm) => { if options.contains(TransformTyOptions::GENERALIZE_POINTERS) { if ty.is_mutable_ptr() { - ty = tcx.mk_mut_ptr(tcx.mk_unit()); + ty = tcx.mk().mut_ptr(tcx.mk().unit()); } else { - ty = tcx.mk_imm_ptr(tcx.mk_unit()); + ty = tcx.mk().imm_ptr(tcx.mk().unit()); } } else { if ty.is_mutable_ptr() { - ty = tcx.mk_mut_ptr(transform_ty(tcx, tm.ty, options)); + ty = tcx.mk().mut_ptr(transform_ty(tcx, tm.ty, options)); } else { - ty = tcx.mk_imm_ptr(transform_ty(tcx, tm.ty, options)); + ty = tcx.mk().imm_ptr(transform_ty(tcx, tm.ty, options)); } } } ty::FnPtr(fn_sig) => { if options.contains(TransformTyOptions::GENERALIZE_POINTERS) { - ty = tcx.mk_imm_ptr(tcx.mk_unit()); + ty = tcx.mk().imm_ptr(tcx.mk().unit()); } else { let parameters: Vec> = fn_sig .skip_binder() @@ -780,8 +780,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio .map(|ty| transform_ty(tcx, *ty, options)) .collect(); let output = transform_ty(tcx, fn_sig.skip_binder().output(), options); - ty = tcx.mk_fn_ptr(ty::Binder::bind_with_vars( - tcx.mk_fn_sig( + ty = tcx.mk().fn_ptr(ty::Binder::bind_with_vars( + tcx.mk().fn_sig( parameters, output, fn_sig.c_variadic(), @@ -817,7 +817,7 @@ fn transform_substs<'tcx>( let substs = substs.iter().map(|subst| { if let GenericArgKind::Type(ty) = subst.unpack() { if is_c_void_ty(tcx, ty) { - tcx.mk_unit().into() + tcx.mk().unit().into() } else { transform_ty(tcx, ty, options).into() } @@ -825,7 +825,7 @@ fn transform_substs<'tcx>( subst } }); - tcx.mk_substs_from_iter(substs) + tcx.mk().substs_from_iter(substs) } /// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 2f20d42139c8d..8e89d6cd6aa9f 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -541,7 +541,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { match predicate.as_ref().skip_binder() { ty::ExistentialPredicate::Trait(trait_ref) => { // Use a type that can't appear in defaults of type parameters. - let dummy_self = cx.tcx.mk_fresh_ty(0); + let dummy_self = cx.tcx.mk().fresh_ty(0); let trait_ref = trait_ref.with_self_ty(cx.tcx, dummy_self); cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?; } @@ -657,7 +657,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { .builtin_deref(true) .expect("tried to dereference on non-ptr type") .ty; - let dereferenced_const = self.tcx.mk_const(ct.kind(), pointee_ty); + let dereferenced_const = self.tcx.mk().const_(ct.kind(), pointee_ty); self = dereferenced_const.print(self)?; } } diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 9b47c7299bb7b..cda0a08a0fb74 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -85,7 +85,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { params: impl IntoIterator>>, param_env: ty::ParamEnv<'tcx>, ) -> traits::EvaluationResult { - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, params); + let trait_ref = self.tcx.mk().trait_ref(trait_def_id, params); let obligation = traits::Obligation { cause: traits::ObligationCause::dummy(), diff --git a/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs b/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs index 7ee4f33230630..659d4faff7a61 100644 --- a/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs +++ b/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs @@ -258,7 +258,7 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { var }); let br = ty::BoundRegion { var, kind: BrAnon(var.as_u32(), None) }; - self.interner().mk_re_late_bound(self.binder_index, br) + self.interner().mk().re_late_bound(self.binder_index, br) } fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> { @@ -269,7 +269,7 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { // any equated inference vars correctly! let root_vid = self.infcx.root_var(vid); if root_vid != vid { - t = self.infcx.tcx.mk_ty_var(root_vid); + t = self.infcx.tcx.mk().ty_var(root_vid); vid = root_vid; } @@ -346,7 +346,7 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { }), ); let bt = ty::BoundTy { var, kind: BoundTyKind::Anon(var.index() as u32) }; - self.interner().mk_bound(self.binder_index, bt) + self.interner().mk().bound(self.binder_index, bt) } fn fold_const(&mut self, mut c: ty::Const<'tcx>) -> ty::Const<'tcx> { @@ -357,7 +357,7 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { // any equated inference vars correctly! let root_vid = self.infcx.root_const_var(vid); if root_vid != vid { - c = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), c.ty()); + c = self.infcx.tcx.mk().const_(ty::InferConst::Var(root_vid), c.ty()); vid = root_vid; } @@ -406,6 +406,6 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { var }), ); - self.interner().mk_const(ty::ConstKind::Bound(self.binder_index, var), c.ty()) + self.interner().mk().const_(ty::ConstKind::Bound(self.binder_index, var), c.ty()) } } diff --git a/compiler/rustc_trait_selection/src/solve/canonical/mod.rs b/compiler/rustc_trait_selection/src/solve/canonical/mod.rs index 8c3be8da16b57..600581d5d0fb3 100644 --- a/compiler/rustc_trait_selection/src/solve/canonical/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/canonical/mod.rs @@ -160,8 +160,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { } } - let var_values = self.tcx().mk_substs_from_iter(response.variables.iter().enumerate().map( - |(index, info)| { + let var_values = self.tcx().mk().substs_from_iter( + response.variables.iter().enumerate().map(|(index, info)| { if info.universe() != ty::UniverseIndex::ROOT { // A variable from inside a binder of the query. While ideally these shouldn't // exist at all (see the FIXME at the start of this method), we have to deal with @@ -187,8 +187,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { // universal bound variable back the placeholder of the input. original_values[info.expect_anon_placeholder() as usize] } - }, - )); + }), + ); CanonicalVarValues { var_values } } diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index dbb8e722c8f6f..419b7d3396866 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -258,7 +258,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { let did = ty::WithOptConstParam::unknown(assoc_def.item.def_id); let kind = ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(did, identity_substs)); - ty.map_bound(|ty| tcx.mk_const(kind, ty).into()) + ty.map_bound(|ty| tcx.mk().const_(kind, ty).into()) } else { ty.map_bound(|ty| ty.into()) }; @@ -322,7 +322,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { let pred = tupled_inputs_and_output .map_bound(|(inputs, output)| ty::ProjectionPredicate { projection_ty: tcx - .mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]), + .mk() + .alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]), term: output.into(), }) .to_predicate(tcx); @@ -451,7 +452,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ecx, goal, ty::Binder::dummy(ty::ProjectionPredicate { - projection_ty: ecx.tcx().mk_alias_ty(goal.predicate.def_id(), [self_ty]), + projection_ty: ecx.tcx().mk().alias_ty(goal.predicate.def_id(), [self_ty]), term, }) .to_predicate(tcx), @@ -493,7 +494,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ty::Binder::dummy(ty::ProjectionPredicate { projection_ty: ecx .tcx() - .mk_alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]), + .mk() + .alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]), term, }) .to_predicate(tcx), diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index 7878539817cfb..81a679251522b 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -234,7 +234,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { let pred = tupled_inputs_and_output .map_bound(|(inputs, _)| { - tcx.mk_trait_ref(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]) + tcx.mk().trait_ref(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]) }) .to_predicate(tcx); // A built-in `Fn` impl only holds if the output is sized. @@ -300,7 +300,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ecx, goal, ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [self_ty, generator.resume_ty()]), + tcx.mk().trait_ref(goal.predicate.def_id(), [self_ty, generator.resume_ty()]), ) .to_predicate(tcx), // Technically, we need to check that the generator types are Sized, @@ -350,7 +350,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // The type must be Sized to be unsized. goal.with( tcx, - ty::Binder::dummy(tcx.mk_trait_ref(sized_def_id, [a_ty])), + ty::Binder::dummy(tcx.mk().trait_ref(sized_def_id, [a_ty])), ), // The type must outlive the lifetime of the `dyn` we're unsizing into. goal.with(tcx, ty::Binder::dummy(ty::OutlivesPredicate(a_ty, region))), @@ -390,10 +390,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // this substitution must be equal to B. This is so we don't unsize // unrelated type parameters. let new_a_substs = - tcx.mk_substs_from_iter(a_substs.iter().enumerate().map(|(i, a)| { + tcx.mk().substs_from_iter(a_substs.iter().enumerate().map(|(i, a)| { if unsizing_params.contains(i as u32) { b_substs[i] } else { a } })); - let unsized_a_ty = tcx.mk_adt(a_def, new_a_substs); + let unsized_a_ty = tcx.mk().adt(a_def, new_a_substs); // Finally, we require that `TailA: Unsize` for the tail field // types. @@ -401,7 +401,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { nested_goals.push(goal.with( tcx, ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [a_tail_ty, b_tail_ty]), + tcx.mk().trait_ref(goal.predicate.def_id(), [a_tail_ty, b_tail_ty]), ), )); @@ -416,14 +416,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // Substitute just the tail field of B., and require that they're equal. let unsized_a_ty = - tcx.mk_tup_from_iter(a_rest_tys.iter().chain([b_last_ty]).copied()); + tcx.mk().tup_from_iter(a_rest_tys.iter().chain([b_last_ty]).copied()); let mut nested_goals = ecx.eq(goal.param_env, unsized_a_ty, b_ty)?; // Similar to ADTs, require that the rest of the fields are equal. nested_goals.push(goal.with( tcx, ty::Binder::dummy( - tcx.mk_trait_ref(goal.predicate.def_id(), [*a_last_ty, *b_last_ty]), + tcx.mk().trait_ref(goal.predicate.def_id(), [*a_last_ty, *b_last_ty]), ), )); @@ -473,8 +473,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let new_a_data = tcx.mk_poly_existential_predicates_from_iter(new_a_data); - let new_a_ty = tcx.mk_dynamic(new_a_data, b_region, ty::Dyn); + let new_a_data = tcx.mk().poly_existential_predicates_from_iter(new_a_data); + let new_a_ty = tcx.mk().dynamic(new_a_data, b_region, ty::Dyn); // We also require that A's lifetime outlives B's lifetime. let mut nested_obligations = ecx.eq(goal.param_env, new_a_ty, b_ty)?; diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs index d7d93377cf164..4fa4fd07af24f 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs @@ -27,7 +27,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>( | ty::Char => Ok(vec![]), // Treat this like `struct str([u8]);` - ty::Str => Ok(vec![tcx.mk_slice(tcx.types.u8)]), + ty::Str => Ok(vec![tcx.mk().slice(tcx.types.u8)]), ty::Dynamic(..) | ty::Param(..) @@ -192,9 +192,9 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>( ty::FnDef(def_id, substs) => Ok(Some( tcx.fn_sig(def_id) .subst(tcx, substs) - .map_bound(|sig| (tcx.mk_tup(sig.inputs()), sig.output())), + .map_bound(|sig| (tcx.mk().tup(sig.inputs()), sig.output())), )), - ty::FnPtr(sig) => Ok(Some(sig.map_bound(|sig| (tcx.mk_tup(sig.inputs()), sig.output())))), + ty::FnPtr(sig) => Ok(Some(sig.map_bound(|sig| (tcx.mk().tup(sig.inputs()), sig.output())))), ty::Closure(_, substs) => { let closure_substs = substs.as_closure(); match closure_substs.kind_ty().to_opt_closure_kind() { diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 1fb8659bb27d3..25585b030b924 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -86,7 +86,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { ) -> AutoTraitResult { let tcx = self.tcx; - let trait_ref = tcx.mk_trait_ref(trait_did, [ty]); + let trait_ref = tcx.mk().trait_ref(trait_did, [ty]); let infcx = tcx.infer_ctxt().build(); let mut selcx = SelectionContext::new(&infcx); @@ -261,7 +261,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { let mut already_visited = FxHashSet::default(); let mut predicates = VecDeque::new(); predicates.push_back(ty::Binder::dummy(ty::TraitPredicate { - trait_ref: infcx.tcx.mk_trait_ref(trait_did, [ty]), + trait_ref: infcx.tcx.mk().trait_ref(trait_did, [ty]), constness: ty::BoundConstness::NotConst, // Auto traits are positive @@ -350,14 +350,14 @@ impl<'tcx> AutoTraitFinder<'tcx> { ) .map(|o| o.predicate); new_env = ty::ParamEnv::new( - tcx.mk_predicates_from_iter(normalized_preds), + tcx.mk().predicates_from_iter(normalized_preds), param_env.reveal(), param_env.constness(), ); } let final_user_env = ty::ParamEnv::new( - tcx.mk_predicates_from_iter(user_computed_preds.into_iter()), + tcx.mk().predicates_from_iter(user_computed_preds.into_iter()), user_env.reveal(), user_env.constness(), ); @@ -794,7 +794,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { unevaluated, Some(obligation.cause.span), ) { - Ok(Some(valtree)) => Ok(selcx.tcx().mk_const(valtree, c.ty())), + Ok(Some(valtree)) => Ok(selcx.tcx().mk().const_(valtree, c.ty())), Ok(None) => { let tcx = self.tcx; let def_id = unevaluated.def.did; diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 62d5e50dbc548..ab156896f2dea 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { def_id: DefId, ) { let tcx = self.infcx.tcx; - let trait_ref = tcx.mk_trait_ref(def_id, [ty]); + let trait_ref = tcx.mk().trait_ref(def_id, [ty]); self.register_obligation(Obligation { cause, recursion_depth: 0, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 41ffaeeac1c11..fa4852834699c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -358,7 +358,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { span: DUMMY_SP, kind: TypeVariableOriginKind::MiscVariable, }); - let trait_ref = self.tcx.mk_trait_ref(trait_def_id, [ty.skip_binder(), var]); + let trait_ref = self.tcx.mk().trait_ref(trait_def_id, [ty.skip_binder(), var]); let obligation = Obligation::new( self.tcx, ObligationCause::dummy(), @@ -1092,7 +1092,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { && self.fallback_has_occurred { let predicate = trait_predicate.map_bound(|trait_pred| { - trait_pred.with_self_ty(self.tcx, self.tcx.mk_unit()) + trait_pred.with_self_ty(self.tcx, self.tcx.mk().unit()) }); let unit_obligation = obligation.with(tcx, predicate); if self.predicate_may_hold(&unit_obligation) { @@ -1721,11 +1721,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let unnormalized_term = match data.term.unpack() { ty::TermKind::Ty(_) => self .tcx - .mk_projection(data.projection_ty.def_id, data.projection_ty.substs) + .mk() + .projection(data.projection_ty.def_id, data.projection_ty.substs) .into(), ty::TermKind::Const(ct) => self .tcx - .mk_const( + .mk() + .const_( ty::UnevaluatedConst { def: ty::WithOptConstParam::unknown(data.projection_ty.def_id), substs: data.projection_ty.substs, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 5541c0850753d..0494cd75bfe50 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -766,7 +766,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if let Some(steps) = autoderef.into_iter().enumerate().find_map(|(steps, (ty, obligations))| { // Re-add the `&` - let ty = self.tcx.mk_ref(region, TypeAndMut { ty, mutbl }); + let ty = self.tcx.mk().ref_(region, TypeAndMut { ty, mutbl }); // Remapping bound vars here let real_trait_pred_and_ty = @@ -1275,13 +1275,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let trait_pred_and_imm_ref = old_pred.map_bound(|trait_pred| { ( trait_pred, - self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, trait_pred.self_ty()), + self.tcx.mk().imm_ref(self.tcx.lifetimes.re_static, trait_pred.self_ty()), ) }); let trait_pred_and_mut_ref = old_pred.map_bound(|trait_pred| { ( trait_pred, - self.tcx.mk_mut_ref(self.tcx.lifetimes.re_static, trait_pred.self_ty()), + self.tcx.mk().mut_ref(self.tcx.lifetimes.re_static, trait_pred.self_ty()), ) }); @@ -1423,7 +1423,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { object_ty: Ty<'tcx>, ) { let ty::Dynamic(predicates, _, ty::Dyn) = object_ty.kind() else { return; }; - let self_ref_ty = self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, self_ty); + let self_ref_ty = self.tcx.mk().imm_ref(self.tcx.lifetimes.re_erased, self_ty); for predicate in predicates.iter() { if !self.predicate_must_hold_modulo_regions( @@ -1651,8 +1651,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if let ty::Ref(region, t_type, mutability) = *trait_pred.skip_binder().self_ty().kind() { let suggested_ty = match mutability { - hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type), - hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type), + hir::Mutability::Mut => self.tcx.mk().imm_ref(region, t_type), + hir::Mutability::Not => self.tcx.mk().mut_ref(region, t_type), }; // Remapping bound vars here @@ -2022,7 +2022,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let inputs = trait_ref.skip_binder().substs.type_at(1); let sig = match inputs.kind() { ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id()) => { - infcx.tcx.mk_fn_sig( + infcx.tcx.mk().fn_sig( *inputs, infcx.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, @@ -2033,7 +2033,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { abi::Abi::Rust, ) } - _ => infcx.tcx.mk_fn_sig( + _ => infcx.tcx.mk().fn_sig( [inputs], infcx.next_ty_var(TypeVariableOrigin { span: DUMMY_SP, @@ -2045,7 +2045,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ), }; - infcx.tcx.mk_fn_ptr(trait_ref.rebind(sig)) + infcx.tcx.mk().fn_ptr(trait_ref.rebind(sig)) } let argument_kind = match expected.skip_binder().self_ty().kind() { @@ -3383,7 +3383,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0]; // `::Output` let projection_ty = trait_pred.map_bound(|trait_pred| { - self.tcx.mk_projection( + self.tcx.mk().projection( item_def_id, // Future::Output has no substs [trait_pred.self_ty()], @@ -3471,7 +3471,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { _ => None, }; let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate { - trait_ref: self.tcx.mk_trait_ref( + trait_ref: self.tcx.mk().trait_ref( trait_pred.def_id(), [field_ty].into_iter().chain(trait_substs), ), @@ -3579,7 +3579,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { { type_diffs = vec![ Sorts(ty::error::ExpectedFound { - expected: self.tcx.mk_alias(ty::Projection, where_pred.skip_binder().projection_ty), + expected: self.tcx.mk().alias(ty::Projection, where_pred.skip_binder().projection_ty), found, }), ]; @@ -3800,7 +3800,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // This corresponds to `::Item = _`. let projection = ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::Projection( ty::ProjectionPredicate { - projection_ty: self.tcx.mk_alias_ty(proj.def_id, substs), + projection_ty: self.tcx.mk().alias_ty(proj.def_id, substs), term: ty_var.into(), }, ))); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index bfeda88a6d40c..c4f42ee6b6827 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -133,7 +133,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>( def_id: DefId, span: Span, ) -> bool { - let trait_ref = ty::Binder::dummy(infcx.tcx.mk_trait_ref(def_id, [ty])); + let trait_ref = ty::Binder::dummy(infcx.tcx.mk().trait_ref(def_id, [ty])); pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const(), span) } @@ -283,7 +283,7 @@ pub fn normalize_param_env_or_error<'tcx>( debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); let elaborated_env = ty::ParamEnv::new( - tcx.mk_predicates(&predicates), + tcx.mk().predicates(&predicates), unnormalized_env.reveal(), unnormalized_env.constness(), ); @@ -337,7 +337,7 @@ pub fn normalize_param_env_or_error<'tcx>( // predicates here anyway. Keeping them here anyway because it seems safer. let outlives_env = non_outlives_predicates.iter().chain(&outlives_predicates).cloned(); let outlives_env = ty::ParamEnv::new( - tcx.mk_predicates_from_iter(outlives_env), + tcx.mk().predicates_from_iter(outlives_env), unnormalized_env.reveal(), unnormalized_env.constness(), ); @@ -357,7 +357,7 @@ pub fn normalize_param_env_or_error<'tcx>( predicates.extend(outlives_predicates); debug!("normalize_param_env_or_error: final predicates={:?}", predicates); ty::ParamEnv::new( - tcx.mk_predicates(&predicates), + tcx.mk().predicates(&predicates), unnormalized_env.reveal(), unnormalized_env.constness(), ) @@ -420,7 +420,7 @@ pub fn fully_solve_bound<'tcx>( bound: DefId, ) -> Vec> { let tcx = infcx.tcx; - let trait_ref = tcx.mk_trait_ref(bound, [ty]); + let trait_ref = tcx.mk().trait_ref(bound, [ty]); let obligation = Obligation::new(tcx, cause, param_env, ty::Binder::dummy(trait_ref)); fully_solve_obligation(infcx, obligation) diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index a5def4151bfda..cf870d09f3123 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -517,7 +517,7 @@ fn virtual_call_violation_for_method<'tcx>( // e.g., `Rc<()>` let unit_receiver_ty = - receiver_for_self_ty(tcx, receiver_ty, tcx.mk_unit(), method.def_id); + receiver_for_self_ty(tcx, receiver_ty, tcx.mk().unit(), method.def_id); match abi_of_ty(unit_receiver_ty) { Some(Abi::Scalar(..)) => (), @@ -621,7 +621,7 @@ fn receiver_for_self_ty<'tcx>( ) -> Ty<'tcx> { debug!("receiver_for_self_ty({:?}, {:?}, {:?})", receiver_ty, self_ty, method_def_id); let substs = InternalSubsts::for_item(tcx, method_def_id, |param, _| { - if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) } + if param.index == 0 { self_ty.into() } else { tcx.mk().param_from_def(param) } }); let result = EarlyBinder(receiver_ty).subst(tcx, substs); @@ -666,12 +666,12 @@ fn object_ty_for_trait<'tcx>( elaborated_predicates.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); elaborated_predicates.dedup(); - let existential_predicates = tcx.mk_poly_existential_predicates_from_iter( + let existential_predicates = tcx.mk().poly_existential_predicates_from_iter( iter::once(trait_predicate).chain(elaborated_predicates), ); debug!(?existential_predicates); - tcx.mk_dynamic(existential_predicates, lifetime, ty::Dyn) + tcx.mk().dynamic(existential_predicates, lifetime, ty::Dyn) } /// Checks the method's receiver (the `self` argument) can be dispatched on when `Self` is a @@ -739,7 +739,7 @@ fn receiver_is_dispatchable<'tcx>( // FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can // replace this with `dyn Trait` let unsized_self_ty: Ty<'tcx> = - tcx.mk_ty_param(u32::MAX, Symbol::intern("RustaceansAreAwesome")); + tcx.mk().ty_param(u32::MAX, Symbol::intern("RustaceansAreAwesome")); // `Receiver[Self => U]` let unsized_receiver_ty = @@ -752,7 +752,7 @@ fn receiver_is_dispatchable<'tcx>( // Self: Unsize let unsize_predicate = ty::Binder::dummy( - tcx.mk_trait_ref(unsize_did, [tcx.types.self_param, unsized_self_ty]), + tcx.mk().trait_ref(unsize_did, [tcx.types.self_param, unsized_self_ty]), ) .without_const() .to_predicate(tcx); @@ -761,17 +761,21 @@ fn receiver_is_dispatchable<'tcx>( let trait_predicate = { let trait_def_id = method.trait_container(tcx).unwrap(); let substs = InternalSubsts::for_item(tcx, trait_def_id, |param, _| { - if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) } + if param.index == 0 { + unsized_self_ty.into() + } else { + tcx.mk().param_from_def(param) + } }); - ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx) + ty::Binder::dummy(tcx.mk().trait_ref(trait_def_id, substs)).to_predicate(tcx) }; let caller_bounds = param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]); ty::ParamEnv::new( - tcx.mk_predicates_from_iter(caller_bounds), + tcx.mk().predicates_from_iter(caller_bounds), param_env.reveal(), param_env.constness(), ) @@ -780,7 +784,7 @@ fn receiver_is_dispatchable<'tcx>( // Receiver: DispatchFromDyn U]> let obligation = { let predicate = ty::Binder::dummy( - tcx.mk_trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]), + tcx.mk().trait_ref(dispatch_from_dyn_did, [receiver_ty, unsized_receiver_ty]), ); Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 01075d7c55aee..9f8a975a2e99e 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -771,7 +771,7 @@ impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { let universe = self.universe_for(debruijn); let p = ty::PlaceholderRegion { universe, name: br.kind }; self.mapped_regions.insert(p, br); - self.infcx.tcx.mk_re_placeholder(p) + self.infcx.tcx.mk().re_placeholder(p) } _ => r, } @@ -789,7 +789,7 @@ impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { let universe = self.universe_for(debruijn); let p = ty::PlaceholderType { universe, name: bound_ty.kind }; self.mapped_types.insert(p, bound_ty); - self.infcx.tcx.mk_placeholder(p) + self.infcx.tcx.mk().placeholder(p) } _ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self), _ => t, @@ -808,7 +808,7 @@ impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { let universe = self.universe_for(debruijn); let p = ty::PlaceholderConst { universe, name: bound_const }; self.mapped_consts.insert(p, bound_const); - self.infcx.tcx.mk_const(p, ct.ty()) + self.infcx.tcx.mk().const_(p, ct.ty()) } _ => ct.super_fold_with(self), } @@ -892,7 +892,7 @@ impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { let db = ty::DebruijnIndex::from_usize( self.universe_indices.len() - index + self.current_index.as_usize() - 1, ); - self.interner().mk_re_late_bound(db, *replace_var) + self.interner().mk().re_late_bound(db, *replace_var) } None => r1, } @@ -919,7 +919,7 @@ impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { let db = ty::DebruijnIndex::from_usize( self.universe_indices.len() - index + self.current_index.as_usize() - 1, ); - self.interner().mk_bound(db, *replace_var) + self.interner().mk().bound(db, *replace_var) } None => ty, } @@ -943,7 +943,7 @@ impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { let db = ty::DebruijnIndex::from_usize( self.universe_indices.len() - index + self.current_index.as_usize() - 1, ); - self.interner().mk_const(ty::ConstKind::Bound(db, *replace_var), ct.ty()) + self.interner().mk().const_(ty::ConstKind::Bound(db, *replace_var), ct.ty()) } None => ct, } @@ -1274,7 +1274,8 @@ fn project<'cx, 'tcx>( // need to investigate whether or not this is fine. selcx .tcx() - .mk_projection(obligation.predicate.def_id, obligation.predicate.substs) + .mk() + .projection(obligation.predicate.def_id, obligation.predicate.substs) .into(), )), // Error occurred while trying to processing impls. @@ -1301,7 +1302,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>( let trait_substs = obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id)); // FIXME(named-returns): Binders - let trait_predicate = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, trait_substs)); + let trait_predicate = ty::Binder::dummy(tcx.mk().trait_ref(trait_def_id, trait_substs)); let _ = selcx.infcx.commit_if_ok(|_| { match selcx.select(&obligation.with(tcx, trait_predicate)) { @@ -1849,7 +1850,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( }; ty::ProjectionPredicate { - projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs), + projection_ty: tcx.mk().alias_ty(obligation.predicate.def_id, trait_ref.substs), term: ty.into(), } }); @@ -1888,7 +1889,7 @@ fn confirm_future_candidate<'cx, 'tcx>( debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output); ty::ProjectionPredicate { - projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs), + projection_ty: tcx.mk().alias_ty(obligation.predicate.def_id, trait_ref.substs), term: return_ty.into(), } }); @@ -1942,7 +1943,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( }; let predicate = - ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, substs), term }; + ty::ProjectionPredicate { projection_ty: tcx.mk().alias_ty(item_def_id, substs), term }; confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false) .with_addl_obligations(obligations) @@ -2011,7 +2012,7 @@ fn confirm_callable_candidate<'cx, 'tcx>( flag, ) .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate { - projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.substs), + projection_ty: tcx.mk().alias_ty(fn_once_output_def_id, trait_ref.substs), term: ret_type.into(), }); @@ -2128,7 +2129,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( crate::traits::InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id); let did = ty::WithOptConstParam::unknown(assoc_ty.item.def_id); let kind = ty::ConstKind::Unevaluated(ty::UnevaluatedConst::new(did, identity_substs)); - ty.map_bound(|ty| tcx.mk_const(kind, ty).into()) + ty.map_bound(|ty| tcx.mk().const_(kind, ty).into()) } else { ty.map_bound(|ty| ty.into()) }; @@ -2207,7 +2208,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( // Use the default `impl Trait` for the trait, e.g., for a default trait body if leaf_def.item.container == ty::AssocItemContainer::TraitContainer { return Progress { - term: tcx.mk_opaque(obligation.predicate.def_id, obligation.predicate.substs).into(), + term: tcx.mk().opaque(obligation.predicate.def_id, obligation.predicate.substs).into(), obligations, }; } diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3182af989f05a..b35188db3da57 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -534,7 +534,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // - let trait_ref = tcx.mk_trait_ref(tcx.lang_items().deref_trait()?, [ty]); + let trait_ref = tcx.mk().trait_ref(tcx.lang_items().deref_trait()?, [ty]); let obligation = traits::Obligation::new(tcx, cause.clone(), param_env, ty::Binder::dummy(trait_ref)); @@ -546,7 +546,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let ty = traits::normalize_projection_type( self, param_env, - tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.substs), + tcx.mk().alias_ty(tcx.lang_items().deref_target()?, trait_ref.substs), cause.clone(), 0, // We're *intentionally* throwing these away, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index ee41d840bae92..116a29f789c4d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -527,48 +527,51 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let kind = ty::BoundTyKind::Param(param.def_id, param.name); let bound_var = ty::BoundVariableKind::Ty(kind); bound_vars.push(bound_var); - tcx.mk_bound( - ty::INNERMOST, - ty::BoundTy { - var: ty::BoundVar::from_usize(bound_vars.len() - 1), - kind, - }, - ) - .into() + tcx.mk() + .bound( + ty::INNERMOST, + ty::BoundTy { + var: ty::BoundVar::from_usize(bound_vars.len() - 1), + kind, + }, + ) + .into() } GenericParamDefKind::Lifetime => { let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); let bound_var = ty::BoundVariableKind::Region(kind); bound_vars.push(bound_var); - tcx.mk_re_late_bound( - ty::INNERMOST, - ty::BoundRegion { - var: ty::BoundVar::from_usize(bound_vars.len() - 1), - kind, - }, - ) - .into() + tcx.mk() + .re_late_bound( + ty::INNERMOST, + ty::BoundRegion { + var: ty::BoundVar::from_usize(bound_vars.len() - 1), + kind, + }, + ) + .into() } GenericParamDefKind::Const { .. } => { let bound_var = ty::BoundVariableKind::Const; bound_vars.push(bound_var); - tcx.mk_const( - ty::ConstKind::Bound( - ty::INNERMOST, - ty::BoundVar::from_usize(bound_vars.len() - 1), - ), - tcx.type_of(param.def_id) - .no_bound_vars() - .expect("const parameter types cannot be generic"), - ) - .into() + tcx.mk() + .const_( + ty::ConstKind::Bound( + ty::INNERMOST, + ty::BoundVar::from_usize(bound_vars.len() - 1), + ), + tcx.type_of(param.def_id) + .no_bound_vars() + .expect("const parameter types cannot be generic"), + ) + .into() } }); let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); let assoc_ty_substs = tcx.mk_substs(&substs); let bound = bound.map_bound(|b| b.kind().skip_binder()).subst(tcx, assoc_ty_substs); - tcx.mk_predicate(ty::Binder::bind_with_vars(bound, bound_vars)) + tcx.mk().predicate(ty::Binder::bind_with_vars(bound, bound_vars)) }; let normalized_bound = normalize_with_depth_to( self, @@ -888,8 +891,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let existential_predicates = tcx.mk_poly_existential_predicates_from_iter(iter); - let source_trait = tcx.mk_dynamic(existential_predicates, r_b, repr_a); + let existential_predicates = tcx.mk().poly_existential_predicates_from_iter(iter); + let source_trait = tcx.mk().dynamic(existential_predicates, r_b, repr_a); // Require that the traits involved in this upcast are **equal**; // only the **lifetime bound** is changed. @@ -987,8 +990,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let existential_predicates = tcx.mk_poly_existential_predicates_from_iter(iter); - let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a); + let existential_predicates = tcx.mk().poly_existential_predicates_from_iter(iter); + let source_trait = tcx.mk().dynamic(existential_predicates, r_b, dyn_a); // Require that the traits involved in this upcast are **equal**; // only the **lifetime bound** is changed. @@ -1107,10 +1110,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check that the source struct with the target's // unsizing parameters is equal to the target. - let substs = tcx.mk_substs_from_iter(substs_a.iter().enumerate().map(|(i, k)| { - if unsizing_params.contains(i as u32) { substs_b[i] } else { k } - })); - let new_struct = tcx.mk_adt(def, substs); + let substs = + tcx.mk().substs_from_iter(substs_a.iter().enumerate().map(|(i, k)| { + if unsizing_params.contains(i as u32) { substs_b[i] } else { k } + })); + let new_struct = tcx.mk().adt(def, substs); let InferOk { obligations, .. } = self .infcx .at(&obligation.cause, obligation.param_env) @@ -1140,7 +1144,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check that the source tuple with the target's // last element is equal to the target. let new_tuple = - tcx.mk_tup_from_iter(a_mid.iter().copied().chain(iter::once(b_last))); + tcx.mk().tup_from_iter(a_mid.iter().copied().chain(iter::once(b_last))); let InferOk { obligations, .. } = self .infcx .at(&obligation.cause, obligation.param_env) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 38cdaddc1e707..e034019ed52ce 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2256,7 +2256,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } } // (*) binder moved here - let all_vars = self.tcx().mk_bound_variable_kinds_from_iter( + let all_vars = self.tcx().mk().bound_variable_kinds_from_iter( obligation.predicate.bound_vars().iter().chain(binder.bound_vars().iter()), ); Where(ty::Binder::bind_with_vars(witness_tys.to_vec(), all_vars)) @@ -2333,7 +2333,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ty::Char => ty::Binder::dummy(Vec::new()), // Treat this like `struct str([u8]);` - ty::Str => ty::Binder::dummy(vec![self.tcx().mk_slice(self.tcx().types.u8)]), + ty::Str => ty::Binder::dummy(vec![self.tcx().mk().slice(self.tcx().types.u8)]), ty::Placeholder(..) | ty::Dynamic(..) @@ -3051,7 +3051,7 @@ fn bind_generator_hidden_types_above<'tcx>( kind: ty::BrAnon(counter, None), }; counter += 1; - r = tcx.mk_re_late_bound(current_depth, br); + r = tcx.mk().re_late_bound(current_depth, br); } r }) @@ -3063,7 +3063,7 @@ fn bind_generator_hidden_types_above<'tcx>( if considering_regions { debug_assert!(!hidden_types.has_erased_regions()); } - let bound_vars = tcx.mk_bound_variable_kinds_from_iter(bound_vars.iter().chain( + let bound_vars = tcx.mk().bound_variable_kinds_from_iter(bound_vars.iter().chain( (num_bound_variables..counter).map(|i| ty::BoundVariableKind::Region(ty::BrAnon(i, None))), )); ty::Binder::bind_with_vars(hidden_types, bound_vars) diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index fcfb60b26030f..a77fc04bb1b26 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -482,7 +482,7 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti trait_pred }); - p = tcx.mk_predicate( + p = tcx.mk().predicate( new_trait_pred.map_bound(|p| ty::PredicateKind::Clause(ty::Clause::Trait(p))), ) } diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index bcf63d5a6f628..5e7cbc7ef0635 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -241,7 +241,7 @@ pub fn predicate_for_trait_def<'tcx>( recursion_depth: usize, params: impl IntoIterator>>, ) -> PredicateObligation<'tcx> { - let trait_ref = tcx.mk_trait_ref(trait_def_id, params); + let trait_ref = tcx.mk().trait_ref(trait_def_id, params); predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth) } @@ -292,9 +292,9 @@ pub fn closure_trait_ref_and_return_type<'tcx>( assert!(!self_ty.has_escaping_bound_vars()); let arguments_tuple = match tuple_arguments { TupleArgumentsFlag::No => sig.skip_binder().inputs()[0], - TupleArgumentsFlag::Yes => tcx.mk_tup(sig.skip_binder().inputs()), + TupleArgumentsFlag::Yes => tcx.mk().tup(sig.skip_binder().inputs()), }; - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]); + let trait_ref = tcx.mk().trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]); sig.map_bound(|sig| (trait_ref, sig.output())) } @@ -305,7 +305,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>( sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> { assert!(!self_ty.has_escaping_bound_vars()); - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]); + let trait_ref = tcx.mk().trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]); sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty)) } @@ -316,7 +316,7 @@ pub fn future_trait_ref_and_outputs<'tcx>( sig: ty::PolyGenSig<'tcx>, ) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> { assert!(!self_ty.has_escaping_bound_vars()); - let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty]); + let trait_ref = tcx.mk().trait_ref(fn_trait_def_id, [self_ty]); sig.map_bound(|sig| (trait_ref, sig.return_ty)) } diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index a4e9928f8b2cf..71cc2ce920026 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -359,7 +359,7 @@ pub(crate) fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>( // this has been typecked-before, so diagnostics is not really needed. let unsize_trait_did = tcx.require_lang_item(LangItem::Unsize, None); - let trait_ref = tcx.mk_trait_ref(unsize_trait_did, [source, target]); + let trait_ref = tcx.mk().trait_ref(unsize_trait_did, [source, target]); match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), ty::Binder::dummy(trait_ref))) { Ok(ImplSource::TraitUpcasting(implsrc_traitcasting)) => { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index d498af359c584..b14489cd571ad 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -883,7 +883,7 @@ pub fn object_region_bounds<'tcx>( // Since we don't actually *know* the self type for an object, // this "open(err)" serves as a kind of dummy standin -- basically // a placeholder type. - let open_ty = tcx.mk_fresh_ty(0); + let open_ty = tcx.mk().fresh_ty(0); let predicates = existential_predicates.iter().filter_map(|predicate| { if let ty::ExistentialPredicate::Projection(_) = predicate.skip_binder() { diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index f8c8f744e6d53..d15569d3c03bb 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -718,7 +718,8 @@ impl<'tcx> chalk_ir::UnificationDatabase> for RustIrDatabase< fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { InternalSubsts::for_item(tcx, def_id, |param, substs| match param.kind { ty::GenericParamDefKind::Type { .. } => tcx - .mk_bound( + .mk() + .bound( ty::INNERMOST, ty::BoundTy { var: ty::BoundVar::from(param.index), @@ -732,11 +733,12 @@ fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { var: ty::BoundVar::from_usize(substs.len()), kind: ty::BrAnon(substs.len() as u32, None), }; - tcx.mk_re_late_bound(ty::INNERMOST, br).into() + tcx.mk().re_late_bound(ty::INNERMOST, br).into() } ty::GenericParamDefKind::Const { .. } => tcx - .mk_const( + .mk() + .const_( ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from(param.index)), tcx.type_of(param.def_id).subst_identity(), ) @@ -789,7 +791,8 @@ impl<'tcx> ty::TypeFolder> for ReplaceOpaqueTyFolder<'tcx> { if def_id == self.opaque_ty_id.0 && substs == self.identity_substs { return self .tcx - .mk_bound(self.binder_index, ty::BoundTy::from(ty::BoundVar::from_u32(0))); + .mk() + .bound(self.binder_index, ty::BoundTy::from(ty::BoundVar::from_u32(0))); } } ty diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 60e22d1001c81..10c99336b9fd1 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -64,7 +64,8 @@ impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution) -> SubstsRef<'tcx> { interner .tcx - .mk_substs_from_iter(self.iter(interner).map(|subst| subst.lower_into(interner))) + .mk() + .substs_from_iter(self.iter(interner).map(|subst| subst.lower_into(interner))) } } @@ -450,28 +451,28 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { TyKind::Str => ty::Str, TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias( ty::Opaque, - interner.tcx.mk_alias_ty(opaque_ty.0, substitution.lower_into(interner)), + interner.tcx.mk().alias_ty(opaque_ty.0, substitution.lower_into(interner)), ), TyKind::AssociatedType(assoc_ty, substitution) => ty::Alias( ty::Projection, - interner.tcx.mk_alias_ty(assoc_ty.0, substitution.lower_into(interner)), + interner.tcx.mk().alias_ty(assoc_ty.0, substitution.lower_into(interner)), ), TyKind::Foreign(def_id) => ty::Foreign(def_id.0), TyKind::Error => return interner.tcx.ty_error_misc(), TyKind::Alias(alias_ty) => match alias_ty { chalk_ir::AliasTy::Projection(projection) => ty::Alias( ty::Projection, - interner.tcx.mk_alias_ty( + interner.tcx.mk().alias_ty( projection.associated_ty_id.0, projection.substitution.lower_into(interner), ), ), chalk_ir::AliasTy::Opaque(opaque) => ty::Alias( ty::Opaque, - interner.tcx.mk_alias_ty( - opaque.opaque_ty_id.0, - opaque.substitution.lower_into(interner), - ), + interner + .tcx + .mk() + .alias_ty(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner)), ), }, TyKind::Function(_quantified_ty) => unimplemented!(), @@ -489,7 +490,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { TyKind::InferenceVar(_, _) => unimplemented!(), TyKind::Dyn(_) => unimplemented!(), }; - interner.tcx.mk_ty_from_kind(kind) + interner.tcx.mk().ty_from_kind(kind) } } @@ -526,7 +527,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime) -> Region<'tcx> { let tcx = interner.tcx; match self.data(interner) { - chalk_ir::LifetimeData::BoundVar(var) => tcx.mk_re_late_bound( + chalk_ir::LifetimeData::BoundVar(var) => tcx.mk().re_late_bound( ty::DebruijnIndex::from_u32(var.debruijn.depth()), ty::BoundRegion { var: ty::BoundVar::from_usize(var.index), @@ -534,7 +535,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime unimplemented!(), - chalk_ir::LifetimeData::Placeholder(p) => tcx.mk_re_placeholder(ty::Placeholder { + chalk_ir::LifetimeData::Placeholder(p) => tcx.mk().re_placeholder(ty::Placeholder { universe: ty::UniverseIndex::from_usize(p.ui.counter), name: ty::BoundRegionKind::BrAnon(p.idx as u32, None), }), @@ -574,7 +575,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const unimplemented!(), chalk_ir::ConstValue::Concrete(c) => ty::ConstKind::Value(c.interned), }; - interner.tcx.mk_const(kind, ty) + interner.tcx.mk().const_(kind, ty) } } @@ -682,7 +683,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders LowerInto<'tcx, chalk_ir::Binders LowerInto<'tcx, chalk_ir::Binders LowerInto<'tcx, chalk_ir::Binders TypeFolder> for NamedBoundVarSubstitutor<'a, 'tcx> { ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) { Some(idx) => { let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) }; - return self.tcx.mk_re_late_bound(index, new_br); + return self.tcx.mk().re_late_bound(index, new_br); } None => panic!("Missing `BrNamed`."), }, @@ -1089,7 +1093,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { match *t.kind() { ty::Param(param) => match self.list.iter().position(|r| r == ¶m) { - Some(idx) => self.tcx.mk_placeholder(ty::PlaceholderType { + Some(idx) => self.tcx.mk().placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::from_usize(0), name: ty::BoundTyKind::Anon(idx as u32), }), @@ -1097,7 +1101,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { self.list.push(param); let idx = self.list.len() - 1 + self.next_ty_placeholder; self.params.insert(idx as u32, param); - self.tcx.mk_placeholder(ty::PlaceholderType { + self.tcx.mk().placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::from_usize(0), name: ty::BoundTyKind::Anon(idx as u32), }) @@ -1118,7 +1122,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { var: ty::BoundVar::from_u32(*idx), kind: ty::BrAnon(*idx, None), }; - self.tcx.mk_re_late_bound(self.binder_index, br) + self.tcx.mk().re_late_bound(self.binder_index, br) } None => { let idx = self.named_regions.len() as u32; @@ -1127,7 +1131,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { kind: ty::BrAnon(idx, None), }; self.named_regions.insert(_re.def_id, idx); - self.tcx.mk_re_late_bound(self.binder_index, br) + self.tcx.mk().re_late_bound(self.binder_index, br) } }, @@ -1159,7 +1163,7 @@ impl<'tcx> TypeFolder> for ReverseParamsSubstitutor<'tcx> { match *t.kind() { ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name }) => { match self.params.get(&name.expect_anon()) { - Some(&ty::ParamTy { index, name }) => self.tcx.mk_ty_param(index, name), + Some(&ty::ParamTy { index, name }) => self.tcx.mk().ty_param(index, name), None => t, } } diff --git a/compiler/rustc_traits/src/chalk/mod.rs b/compiler/rustc_traits/src/chalk/mod.rs index a5ebc26a8bc96..db7b2ada3d9cb 100644 --- a/compiler/rustc_traits/src/chalk/mod.rs +++ b/compiler/rustc_traits/src/chalk/mod.rs @@ -96,7 +96,7 @@ pub(crate) fn evaluate_goal<'tcx>( use rustc_middle::infer::canonical::CanonicalVarInfo; let mut reverse_param_substitutor = ReverseParamsSubstitutor::new(tcx, params); - let var_values = tcx.mk_substs_from_iter( + let var_values = tcx.mk().substs_from_iter( subst .as_slice(interner) .iter() @@ -123,7 +123,7 @@ pub(crate) fn evaluate_goal<'tcx>( let max_universe = binders.iter(interner).map(|v| v.skip_kind().counter).max().unwrap_or(0); let sol = Canonical { max_universe: ty::UniverseIndex::from_usize(max_universe), - variables: tcx.mk_canonical_var_infos_from_iter(variables), + variables: tcx.mk().canonical_var_infos_from_iter(variables), value: QueryResponse { var_values: CanonicalVarValues { var_values }, region_constraints: QueryRegionConstraints::default(), diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 35c9f95eb03b1..4eade63742fa2 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -53,8 +53,8 @@ fn fn_sig_for_fn_abi<'tcx>( // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`. sig = sig.map_bound(|mut sig| { let mut inputs_and_output = sig.inputs_and_output.to_vec(); - inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]); - sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); + inputs_and_output[0] = tcx.mk().mut_ptr(inputs_and_output[0]); + sig.inputs_and_output = tcx.mk().type_list(&inputs_and_output); sig }); } @@ -63,19 +63,19 @@ fn fn_sig_for_fn_abi<'tcx>( ty::Closure(def_id, substs) => { let sig = substs.as_closure().sig(); - let bound_vars = tcx.mk_bound_variable_kinds_from_iter( + let bound_vars = tcx.mk().bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), ); let br = ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BoundRegionKind::BrEnv, }; - let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br); + let env_region = tcx.mk().re_late_bound(ty::INNERMOST, br); let env_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap(); let sig = sig.skip_binder(); ty::Binder::bind_with_vars( - tcx.mk_fn_sig( + tcx.mk().fn_sig( iter::once(env_ty).chain(sig.inputs().iter().cloned()), sig.output(), sig.c_variadic, @@ -88,19 +88,19 @@ fn fn_sig_for_fn_abi<'tcx>( ty::Generator(did, substs, _) => { let sig = substs.as_generator().poly_sig(); - let bound_vars = tcx.mk_bound_variable_kinds_from_iter( + let bound_vars = tcx.mk().bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), ); let br = ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BoundRegionKind::BrEnv, }; - let env_ty = tcx.mk_mut_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), ty); + let env_ty = tcx.mk().mut_ref(tcx.mk().re_late_bound(ty::INNERMOST, br), ty); let pin_did = tcx.require_lang_item(LangItem::Pin, None); let pin_adt_ref = tcx.adt_def(pin_did); let pin_substs = tcx.mk_substs(&[env_ty.into()]); - let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs); + let env_ty = tcx.mk().adt(pin_adt_ref, pin_substs); let sig = sig.skip_binder(); // The `FnSig` and the `ret_ty` here is for a generators main @@ -112,7 +112,7 @@ fn fn_sig_for_fn_abi<'tcx>( let poll_did = tcx.require_lang_item(LangItem::Poll, None); let poll_adt_ref = tcx.adt_def(poll_did); let poll_substs = tcx.mk_substs(&[sig.return_ty.into()]); - let ret_ty = tcx.mk_adt(poll_adt_ref, poll_substs); + let ret_ty = tcx.mk().adt(poll_adt_ref, poll_substs); // We have to replace the `ResumeTy` that is used for type and borrow checking // with `&mut Context<'_>` which is used in codegen. @@ -126,7 +126,7 @@ fn fn_sig_for_fn_abi<'tcx>( panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); }; } - let context_mut_ref = tcx.mk_task_context(); + let context_mut_ref = tcx.mk().task_context(); (context_mut_ref, ret_ty) } else { @@ -134,13 +134,13 @@ fn fn_sig_for_fn_abi<'tcx>( let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); let state_adt_ref = tcx.adt_def(state_did); let state_substs = tcx.mk_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); - let ret_ty = tcx.mk_adt(state_adt_ref, state_substs); + let ret_ty = tcx.mk().adt(state_adt_ref, state_substs); (sig.resume_ty, ret_ty) }; ty::Binder::bind_with_vars( - tcx.mk_fn_sig( + tcx.mk().fn_sig( [env_ty, resume_ty], ret_ty, false, @@ -525,7 +525,7 @@ fn make_thin_self_ptr<'tcx>( let fat_pointer_ty = if layout.is_unsized() { // unsized `self` is passed as a pointer to `self` // FIXME (mikeyhew) change this to use &own if it is ever added to the language - tcx.mk_mut_ptr(layout.ty) + tcx.mk().mut_ptr(layout.ty) } else { match layout.abi { Abi::ScalarPair(..) | Abi::Scalar(..) => (), @@ -559,7 +559,7 @@ fn make_thin_self_ptr<'tcx>( // we now have a type like `*mut RcBox` // change its layout to that of `*mut ()`, a thin pointer, but keep the same type // this is understood as a special case elsewhere in the compiler - let unit_ptr_ty = tcx.mk_mut_ptr(tcx.mk_unit()); + let unit_ptr_ty = tcx.mk().mut_ptr(tcx.mk().unit()); TyAndLayout { ty: fat_pointer_ty, diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index a28161245384c..8335d4b1da08c 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -284,7 +284,7 @@ fn associated_item_for_impl_trait_in_trait( trait_assoc_ty.impl_defaultness(tcx.impl_defaultness(fn_def_id)); // Copy type_of of the opaque. - trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque( + trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk().opaque( opaque_ty_def_id.to_def_id(), InternalSubsts::identity_for_item(tcx, opaque_ty_def_id.to_def_id()), ))); diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index f2635271609b8..98b5b299e69e5 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -33,7 +33,7 @@ pub(crate) fn destructure_const<'tcx>( ty::Array(inner_ty, _) | ty::Slice(inner_ty) => { // construct the consts for the elements of the array/slice let field_consts = - branches.iter().map(|b| tcx.mk_const(*b, *inner_ty)).collect::>(); + branches.iter().map(|b| tcx.mk().const_(*b, *inner_ty)).collect::>(); debug!(?field_consts); (field_consts, None) @@ -51,7 +51,7 @@ pub(crate) fn destructure_const<'tcx>( for (field, field_valtree) in iter::zip(fields, branches) { let field_ty = field.ty(tcx, substs); - let field_const = tcx.mk_const(*field_valtree, field_ty); + let field_const = tcx.mk().const_(*field_valtree, field_ty); field_consts.push(field_const); } debug!(?field_consts); @@ -60,7 +60,7 @@ pub(crate) fn destructure_const<'tcx>( } ty::Tuple(elem_tys) => { let fields = iter::zip(*elem_tys, branches) - .map(|(elem_ty, elem_valtree)| tcx.mk_const(*elem_valtree, elem_ty)) + .map(|(elem_ty, elem_valtree)| tcx.mk().const_(*elem_valtree, elem_ty)) .collect::>(); (fields, None) @@ -125,17 +125,17 @@ fn recurse_build<'tcx>( } &ExprKind::NonHirLiteral { lit, user_ty: _ } => { let val = ty::ValTree::from_scalar_int(lit); - tcx.mk_const(val, node.ty) + tcx.mk().const_(val, node.ty) } &ExprKind::ZstLiteral { user_ty: _ } => { let val = ty::ValTree::zst(); - tcx.mk_const(val, node.ty) + tcx.mk().const_(val, node.ty) } &ExprKind::NamedConst { def_id, substs, user_ty: _ } => { let uneval = ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs); - tcx.mk_const(uneval, node.ty) + tcx.mk().const_(uneval, node.ty) } - ExprKind::ConstParam { param, .. } => tcx.mk_const(*param, node.ty), + ExprKind::ConstParam { param, .. } => tcx.mk().const_(*param, node.ty), ExprKind::Call { fun, args, .. } => { let fun = recurse_build(tcx, body, *fun, root_span)?; @@ -145,16 +145,16 @@ fn recurse_build<'tcx>( new_args.push(recurse_build(tcx, body, id, root_span)?); } let new_args = tcx.mk_const_list(&new_args); - tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty) + tcx.mk().const_(Expr::FunctionCall(fun, new_args), node.ty) } &ExprKind::Binary { op, lhs, rhs } if check_binop(op) => { let lhs = recurse_build(tcx, body, lhs, root_span)?; let rhs = recurse_build(tcx, body, rhs, root_span)?; - tcx.mk_const(Expr::Binop(op, lhs, rhs), node.ty) + tcx.mk().const_(Expr::Binop(op, lhs, rhs), node.ty) } &ExprKind::Unary { op, arg } if check_unop(op) => { let arg = recurse_build(tcx, body, arg, root_span)?; - tcx.mk_const(Expr::UnOp(op, arg), node.ty) + tcx.mk().const_(Expr::UnOp(op, arg), node.ty) } // This is necessary so that the following compiles: // @@ -175,11 +175,11 @@ fn recurse_build<'tcx>( // This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested) &ExprKind::Use { source } => { let arg = recurse_build(tcx, body, source, root_span)?; - tcx.mk_const(Expr::Cast(CastKind::Use, arg, node.ty), node.ty) + tcx.mk().const_(Expr::Cast(CastKind::Use, arg, node.ty), node.ty) } &ExprKind::Cast { source } => { let arg = recurse_build(tcx, body, source, root_span)?; - tcx.mk_const(Expr::Cast(CastKind::As, arg, node.ty), node.ty) + tcx.mk().const_(Expr::Cast(CastKind::As, arg, node.ty), node.ty) } ExprKind::Borrow { arg, .. } => { let arg_node = &body.exprs[*arg]; diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 56d6cc28bc83f..ee4a655162724 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -18,16 +18,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List> { let mut assumed_wf_types: Vec<_> = tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into(); assumed_wf_types.extend(liberated_sig.inputs_and_output); - tcx.mk_type_list(&assumed_wf_types) + tcx.mk().type_list(&assumed_wf_types) } DefKind::Impl { .. } => { match tcx.impl_trait_ref(def_id) { Some(trait_ref) => { let types: Vec<_> = trait_ref.skip_binder().substs.types().collect(); - tcx.mk_type_list(&types) + tcx.mk().type_list(&types) } // Only the impl self type - None => tcx.mk_type_list(&[tcx.type_of(def_id).subst_identity()]), + None => tcx.mk().type_list(&[tcx.type_of(def_id).subst_identity()]), } } DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 1788f544a7f9a..91bb56bafded9 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -163,7 +163,7 @@ fn layout_of_uncached<'tcx>( { let metadata_ty = tcx.normalize_erasing_regions( param_env, - tcx.mk_projection(metadata_def_id, [pointee]), + tcx.mk().projection(metadata_def_id, [pointee]), ); let metadata_layout = cx.layout_of(metadata_ty)?; // If the metadata is a 1-zst, then the pointer is thin. @@ -645,7 +645,7 @@ fn generator_layout<'tcx>( let promoted_layouts = ineligible_locals .iter() .map(|local| subst_field(info.field_tys[local].ty)) - .map(|ty| tcx.mk_maybe_uninit(ty)) + .map(|ty| tcx.mk().maybe_uninit(ty)) .map(|ty| Ok(cx.layout_of(ty)?.layout)); let prefix_layouts = substs .as_generator() diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index de7fd003176bb..ea279f1c1d109 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -303,7 +303,7 @@ fn adt_drop_tys<'tcx>( false, ) .collect::, _>>() - .map(|components| tcx.mk_type_list(&components)) + .map(|components| tcx.mk().type_list(&components)) } // If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed // a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters @@ -320,7 +320,7 @@ fn adt_significant_drop_tys( true, ) .collect::, _>>() - .map(|components| tcx.mk_type_list(&components)) + .map(|components| tcx.mk().type_list(&components)) } pub(crate) fn provide(providers: &mut ty::query::Providers) { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index d41bf603983c0..43b8fc1a1cc1f 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -61,7 +61,7 @@ fn sized_constraint_for_ty<'tcx>( // it on the impl. let Some(sized_trait) = tcx.lang_items().sized_trait() else { return vec![ty] }; - let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref(sized_trait, [ty])) + let sized_predicate = ty::Binder::dummy(tcx.mk().trait_ref(sized_trait, [ty])) .without_const() .to_predicate(tcx); let predicates = tcx.predicates_of(adtdef.did()).predicates; @@ -98,12 +98,12 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness { fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] { if let Some(def_id) = def_id.as_local() { if matches!(tcx.representability(def_id), ty::Representability::Infinite) { - return tcx.mk_type_list(&[tcx.ty_error_misc()]); + return tcx.mk().type_list(&[tcx.ty_error_misc()]); } } let def = tcx.adt_def(def_id); - let result = tcx.mk_type_list_from_iter( + let result = tcx.mk().type_list_from_iter( def.variants() .iter() .flat_map(|v| v.fields.last()) @@ -235,7 +235,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { }; let unnormalized_env = - ty::ParamEnv::new(tcx.mk_predicates(&predicates), traits::Reveal::UserFacing, constness); + ty::ParamEnv::new(tcx.mk().predicates(&predicates), traits::Reveal::UserFacing, constness); let body_id = local_did.unwrap_or(CRATE_DEF_ID); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); @@ -277,7 +277,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { // constructing the top-level projection predicate. let alias_ty = self.tcx.fold_regions(alias_ty, |re, _| { if let ty::ReLateBound(index, bv) = re.kind() { - self.tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv) + self.tcx.mk().re_late_bound(index.shifted_out_to_binder(self.depth), bv) } else { re } @@ -286,7 +286,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { ty::Binder::bind_with_vars( ty::ProjectionPredicate { projection_ty: alias_ty, - term: self.tcx.mk_alias(ty::Opaque, alias_ty).into(), + term: self.tcx.mk().alias(ty::Opaque, alias_ty).into(), }, self.bound_vars, ) @@ -401,7 +401,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List { let binder = Binder::dummy(PredicateKind::TypeWellFormedFromEnv(ty)); - Some(tcx.mk_predicate(binder)) + Some(tcx.mk().predicate(binder)) } // FIXME(eddyb) no WF conditions from lifetimes? @@ -412,7 +412,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List, def_id: DefId) -> ty::ParamEnv<'_> { From d560bb52b06d1bd6a450d90a385c583d89f6fed1 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Mar 2023 18:09:22 +0000 Subject: [PATCH 4/8] Use `.mk().*` instead of `.mk_*` part 1 --- .../src/diagnostics/conflict_errors.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../rustc_codegen_cranelift/src/main_shim.rs | 4 +- .../src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- .../src/const_eval/eval_queries.rs | 2 +- .../rustc_const_eval/src/interpret/intern.rs | 6 +-- .../src/interpret/intrinsics.rs | 2 +- .../interpret/intrinsics/caller_location.rs | 2 +- .../src/transform/promote_consts.rs | 2 +- .../src/transform/validate.rs | 2 +- .../src/astconv/generics.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 6 +-- .../src/check/compare_impl_item.rs | 4 +- .../rustc_hir_analysis/src/check/intrinsic.rs | 4 +- .../src/generator_interior/mod.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 2 +- .../src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 2 +- .../rustc_middle/src/mir/type_foldable.rs | 2 +- compiler/rustc_middle/src/mir/visit.rs | 2 +- compiler/rustc_middle/src/traits/solve.rs | 20 +++++----- compiler/rustc_middle/src/ty/codec.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 6 +-- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 6 +-- compiler/rustc_middle/src/ty/relate.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 4 +- compiler/rustc_middle/src/ty/sty.rs | 10 ++--- compiler/rustc_middle/src/ty/subst.rs | 8 ++-- compiler/rustc_middle/src/ty/vtable.rs | 2 +- .../src/build/expr/as_constant.rs | 4 +- .../src/build/expr/as_operand.rs | 2 +- .../src/build/expr/as_place.rs | 4 +- .../rustc_mir_build/src/build/matches/mod.rs | 4 +- compiler/rustc_mir_build/src/build/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/mod.rs | 2 +- .../src/move_paths/builder.rs | 6 +-- compiler/rustc_mir_transform/src/copy_prop.rs | 2 +- .../src/elaborate_box_derefs.rs | 4 +- compiler/rustc_mir_transform/src/generator.rs | 15 +++---- compiler/rustc_mir_transform/src/inline.rs | 2 +- .../rustc_mir_transform/src/instcombine.rs | 2 +- .../rustc_mir_transform/src/large_enums.rs | 5 ++- compiler/rustc_mir_transform/src/lib.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 2 +- compiler/rustc_mir_transform/src/sroa.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- .../src/solve/canonical/canonicalize.rs | 4 +- .../src/solve/canonical/mod.rs | 3 +- .../rustc_trait_selection/src/solve/mod.rs | 2 +- .../src/traits/project.rs | 2 +- .../src/traits/select/confirmation.rs | 4 +- compiler/rustc_ty_utils/src/abi.rs | 6 +-- compiler/rustc_ty_utils/src/consts.rs | 2 +- compiler/rustc_ty_utils/src/layout.rs | 40 +++++++++---------- 57 files changed, 126 insertions(+), 121 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index f43b611f54eda..23db24745cc33 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1517,7 +1517,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { assert!(root_place.projection.is_empty()); let proper_span = self.body.local_decls[root_place.local].source_info.span; - let root_place_projection = self.infcx.tcx.mk_place_elems(root_place.projection); + let root_place_projection = self.infcx.tcx.mk().place_elems(root_place.projection); if self.access_place_error_reported.contains(&( Place { local: root_place.local, projection: root_place_projection }, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 8f1ab7c7b2070..7661abc444e17 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -2618,7 +2618,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { DefKind::InlineConst => substs.as_inline_const().parent_substs(), other => bug!("unexpected item {:?}", other), }; - let parent_substs = tcx.mk_substs(parent_substs); + let parent_substs = tcx.mk().substs(parent_substs); assert_eq!(typeck_root_substs.len(), parent_substs.len()); if let Err(_) = self.eq_substs( diff --git a/compiler/rustc_codegen_cranelift/src/main_shim.rs b/compiler/rustc_codegen_cranelift/src/main_shim.rs index be908df83e8f5..fb30d58a6d5e3 100644 --- a/compiler/rustc_codegen_cranelift/src/main_shim.rs +++ b/compiler/rustc_codegen_cranelift/src/main_shim.rs @@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper( tcx, ParamEnv::reveal_all(), report.def_id, - tcx.mk_substs(&[GenericArg::from(main_ret_ty)]), + tcx.mk().substs(&[GenericArg::from(main_ret_ty)]), ) .unwrap() .unwrap() @@ -146,7 +146,7 @@ pub(crate) fn maybe_create_entry_wrapper( tcx, ParamEnv::reveal_all(), start_def_id, - tcx.mk_substs(&[main_ret_ty.into()]), + tcx.mk().substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap() diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 7b58e55dbe84a..de03b9d2b2e5d 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -376,7 +376,7 @@ fn upstream_monomorphizations_provider( ExportedSymbol::Generic(def_id, substs) => (def_id, substs), ExportedSymbol::DropGlue(ty) => { if let Some(drop_in_place_fn_def_id) = drop_in_place_fn_def_id { - (drop_in_place_fn_def_id, tcx.mk_substs(&[ty.into()])) + (drop_in_place_fn_def_id, tcx.mk().substs(&[ty.into()])) } else { // `drop_in_place` in place does not exist, don't try // to use it. diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index f7072fe4da311..59cdce76b05e0 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -477,7 +477,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx.tcx(), ty::ParamEnv::reveal_all(), start_def_id, - cx.tcx().mk_substs(&[main_ret_ty.into()]), + cx.tcx().mk().substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap(), diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 7564ba17b404a..0b25fe1df9e35 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -180,7 +180,7 @@ pub(super) fn op_to_const<'tcx>( (ecx.tcx.global_alloc(alloc_id).unwrap_memory(), offset.bytes()) } (None, _offset) => ( - ecx.tcx.mk_const_alloc(Allocation::from_bytes_byte_aligned_immutable( + ecx.tcx.mk().const_alloc(Allocation::from_bytes_byte_aligned_immutable( b"" as &[u8], )), 0, diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index b220d21f68b72..8c0e66b0df78c 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -135,7 +135,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval: }; // link the alloc id to the actual allocation leftover_allocations.extend(alloc.provenance().ptrs().iter().map(|&(_, alloc_id)| alloc_id)); - let alloc = tcx.mk_const_alloc(alloc); + let alloc = tcx.mk().const_alloc(alloc); tcx.set_alloc_id_memory(alloc_id, alloc); None } @@ -437,7 +437,7 @@ pub fn intern_const_alloc_recursive< alloc.mutability = Mutability::Not; } } - let alloc = tcx.mk_const_alloc(alloc); + let alloc = tcx.mk().const_alloc(alloc); tcx.set_alloc_id_memory(alloc_id, alloc); for &(_, alloc_id) in alloc.inner().provenance().ptrs().iter() { if leftover_allocations.insert(alloc_id) { @@ -479,6 +479,6 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>> f(self, &dest.into())?; let mut alloc = self.memory.alloc_map.remove(&dest.ptr.provenance.unwrap()).unwrap().1; alloc.mutability = Mutability::Not; - Ok(self.tcx.mk_const_alloc(alloc)) + Ok(self.tcx.mk().const_alloc(alloc)) } } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index ad91227ba9a75..0fe395483ecc7 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -45,7 +45,7 @@ fn numeric_intrinsic(name: Symbol, bits: u128, kind: Primitive) -> Scalar< pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> { let path = crate::util::type_name(tcx, ty); let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes()); - tcx.mk_const_alloc(alloc) + tcx.mk().const_alloc(alloc) } /// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs b/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs index cf52299b7ba82..df8f21a990ca9 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs @@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let loc_ty = self .tcx .type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)) - .subst(*self.tcx, self.tcx.mk_substs(&[self.tcx.lifetimes.re_erased.into()])); + .subst(*self.tcx, self.tcx.mk().substs(&[self.tcx.lifetimes.re_erased.into()])); let loc_layout = self.layout_of(loc_ty).unwrap(); let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap(); diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index ab7ac1941b0b6..107b1b6eb619b 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -866,7 +866,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let mut projection = vec![PlaceElem::Deref]; projection.extend(place.projection); - place.projection = tcx.mk_place_elems(&projection); + place.projection = tcx.mk().place_elems(&projection); // Create a temp to hold the promoted reference. // This is because `*r` requires `r` to be a local, diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 49b1e6d967c70..27a5918affcaa 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -326,7 +326,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } ProjectionElem::Field(f, ty) => { - let parent = Place { local, projection: self.tcx.mk_place_elems(proj_base) }; + let parent = Place { local, projection: self.tcx.mk().place_elems(proj_base) }; let parent_ty = parent.ty(&self.body.local_decls, self.tcx); let fail_out_of_bounds = |this: &Self, location| { this.fail(location, format!("Out of bounds field {:?} for {:?}", f, parent_ty)); diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index 2f4963f6bc311..d2831ef875609 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -369,7 +369,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>( } } - tcx.mk_substs(&substs) + tcx.mk().substs(&substs) } /// Checks that the correct number of generic arguments have been provided. diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index ab4265bed4f6d..d9a87e76c2b27 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -381,7 +381,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // here and so associated type bindings will be handled regardless of whether there are any // non-`Self` generic parameters. if generics.params.is_empty() { - return (tcx.mk_substs(parent_substs), arg_count); + return (tcx.mk().substs(parent_substs), arg_count); } struct SubstsForAstPathCtxt<'a, 'tcx> { @@ -1528,7 +1528,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg }) .collect(); - let substs = tcx.mk_substs(&substs); + let substs = tcx.mk().substs(&substs); let span = i.bottom().1; let empty_generic_args = hir_trait_bounds.iter().any(|hir_bound| { @@ -1590,7 +1590,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg }) .collect(); - b.projection_ty.substs = tcx.mk_substs(&substs); + b.projection_ty.substs = tcx.mk().substs(&substs); } ty::ExistentialProjection::erase_self_ty(tcx, b) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index bc3de03747971..b19010bf68d04 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -1947,8 +1947,8 @@ pub(super) fn check_type_bounds<'tcx>( .into() } }); - let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); - let impl_ty_substs = tcx.mk_substs(&substs); + let bound_vars = tcx.mk().bound_variable_kinds(&bound_vars); + let impl_ty_substs = tcx.mk().substs(&substs); let container_id = impl_ty.container_id(tcx); let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index efd58aea42472..637a4854b3208 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -137,7 +137,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let intrinsic_name = tcx.item_name(intrinsic_id); let name_str = intrinsic_name.as_str(); - let bound_vars = tcx.mk_bound_variable_kinds(&[ + let bound_vars = tcx.mk().bound_variable_kinds(&[ ty::BoundVariableKind::Region(ty::BrAnon(0, None)), ty::BoundVariableKind::Region(ty::BrEnv), ]); @@ -376,7 +376,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { ( 1, vec![tcx.mk().imm_ref(tcx.mk().re_late_bound(ty::INNERMOST, br), param(0))], - tcx.mk().projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])), + tcx.mk().projection(discriminant_def_id, tcx.mk().substs(&[param(0).into()])), ) } diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 74a4f421388b6..1f62962a8abd9 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -312,7 +312,7 @@ pub fn resolve_interior<'a, 'tcx>( // Extract type components to build the witness type. let type_list = fcx.tcx.mk().type_list_from_iter(type_causes.iter().map(|cause| cause.ty)); - let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars); + let bound_vars = fcx.tcx.mk().bound_variable_kinds(&bound_vars); let witness = fcx.tcx.mk().generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone())); diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 9ac5b59cd9a04..c6183cbe83691 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -601,7 +601,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { debug_assert!(!out_value.needs_infer() && !out_value.has_placeholders()); let canonical_variables = - tcx.mk_canonical_var_infos(&canonicalizer.universe_canonicalized_variables()); + tcx.mk().canonical_var_infos(&canonicalizer.universe_canonicalized_variables()); let max_universe = canonical_variables .iter() diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fd21663fe08d0..0520f10e8f396 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -924,7 +924,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ) -> Option<()> { // FIXME/HACK: Go back to `SubstsRef` to use its inherent methods, // ideally that shouldn't be necessary. - let sub = self.tcx.mk_substs(sub); + let sub = self.tcx.mk().substs(sub); for (i, ta) in sub.types().enumerate() { if ta == other_ty { self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, other_ty); diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 44771e6bb5b35..dfa2fd50ef780 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -47,7 +47,7 @@ impl<'tcx> ty::TypeFoldable> for CanonicalVarInfos<'tcx> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_canonical_var_infos(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().canonical_var_infos(v)) } } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 283dd6901b055..d1cc3d94c948e 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1623,7 +1623,7 @@ impl<'tcx> Place<'tcx> { &v }; - Place { local: self.local, projection: tcx.mk_place_elems(new_projections) } + Place { local: self.local, projection: tcx.mk().place_elems(new_projections) } } } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 9881583214eb4..aa1c80d877ef0 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -53,6 +53,6 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_place_elems(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().place_elems(v)) } } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index cbeacf21c19f0..47754e0410e45 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1038,7 +1038,7 @@ macro_rules! visit_place_fns { self.visit_local(&mut place.local, context, location); if let Some(new_projection) = self.process_projection(&place.projection, location) { - place.projection = self.tcx().mk_place_elems(&new_projection); + place.projection = self.tcx().mk().place_elems(&new_projection); } } diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index 92d3e73e683cd..9a4b40a628496 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -128,18 +128,20 @@ impl<'tcx> TypeFoldable> for ExternalConstraints<'tcx> { self, folder: &mut F, ) -> Result { - Ok(FallibleTypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { - region_constraints: self.region_constraints.clone().try_fold_with(folder)?, - opaque_types: self - .opaque_types - .iter() - .map(|opaque| opaque.try_fold_with(folder)) - .collect::>()?, - })) + Ok(FallibleTypeFolder::interner(folder).mk().external_constraints( + ExternalConstraintsData { + region_constraints: self.region_constraints.clone().try_fold_with(folder)?, + opaque_types: self + .opaque_types + .iter() + .map(|opaque| opaque.try_fold_with(folder)) + .collect::>()?, + }, + )) } fn fold_with>>(self, folder: &mut F) -> Self { - TypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { + TypeFolder::interner(folder).mk().external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().fold_with(folder), opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), }) diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 032f89871527d..be7a022a70675 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -345,13 +345,13 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for [ty::ValTre impl<'tcx, D: TyDecoder>> Decodable for ConstAllocation<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().mk_const_alloc(Decodable::decode(decoder)) + decoder.interner().mk().const_alloc(Decodable::decode(decoder)) } } impl<'tcx, D: TyDecoder>> Decodable for AdtDef<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().mk_adt_def_from_data(Decodable::decode(decoder)) + decoder.interner().mk().adt_def_from_data(Decodable::decode(decoder)) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 64c40b6e11b16..7dfdb10732bdb 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -636,7 +636,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn allocate_bytes(self, bytes: &[u8]) -> interpret::AllocId { // Create an allocation that just contains these bytes. let alloc = interpret::Allocation::from_bytes_byte_aligned_immutable(bytes); - let alloc = self.mk_const_alloc(alloc); + let alloc = self.mk().const_alloc(alloc); self.create_memory_alloc(alloc) } @@ -1204,7 +1204,7 @@ impl<'tcx> TyCtxt<'tcx> { self.mk().imm_ref( self.lifetimes.re_static, self.type_of(self.require_lang_item(LangItem::PanicLocation, None)) - .subst(self, self.mk_substs(&[self.lifetimes.re_static.into()])), + .subst(self, self.mk().substs(&[self.lifetimes.re_static.into()])), ) } @@ -2472,7 +2472,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn late_bound_vars(self, id: HirId) -> &'tcx List { - self.mk_bound_variable_kinds( + self.mk().bound_variable_kinds( &self .late_bound_vars_map(id.owner) .and_then(|map| map.get(&id.local_id).cloned()) diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 7396a2ce6c777..a74be1b0babac 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -540,7 +540,7 @@ impl<'tcx> Instance<'tcx> { pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { let def_id = tcx.require_lang_item(LangItem::DropInPlace, None); - let substs = tcx.mk_substs(&[ty.into()]); + let substs = tcx.mk().substs(&[ty.into()]); Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs) } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index ea9b2d2e90c9d..ce3fc8313998a 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -632,7 +632,7 @@ where ty::Adt(def, _) => def.variant(variant_index).fields.len(), _ => bug!(), }; - tcx.mk_layout(LayoutS { + tcx.mk().layout(LayoutS { variants: Variants::Single { index: variant_index }, fields: match NonZeroUsize::new(fields) { Some(fields) => FieldsShape::Union(fields), @@ -645,7 +645,7 @@ where }) } - Variants::Multiple { ref variants, .. } => cx.tcx().mk_layout(variants[variant_index].clone()), + Variants::Multiple { ref variants, .. } => cx.tcx().mk().layout(variants[variant_index].clone()), }; assert_eq!(*layout.variants(), Variants::Single { index: variant_index }); @@ -667,7 +667,7 @@ where let tcx = cx.tcx(); let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> { TyAndLayout { - layout: tcx.mk_layout(LayoutS::scalar(cx, tag)), + layout: tcx.mk().layout(LayoutS::scalar(cx, tag)), ty: tag.primitive().to_ty(tcx), } }; diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index a39ed2a01e40a..224b818d49d4e 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -677,7 +677,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( for (a_arg, b_arg) in aa.iter().zip(ba.iter()) { related_args.push(r.consts(a_arg, b_arg)?); } - let related_args = tcx.mk_const_list(&related_args); + let related_args = tcx.mk().const_list(&related_args); Expr::FunctionCall(func, related_args) } _ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 7db8d58cd92df..bbb54d6fe79c6 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -440,7 +440,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_const_list(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().const_list(v)) } } @@ -449,7 +449,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.mk_projs(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk().projs(v)) } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a0e7b0df76b35..11d7d7df46e21 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -862,7 +862,7 @@ 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()])) + tcx.mk().trait_ref(trait_id, tcx.mk().substs(&substs[..defs.params.len()])) } } @@ -908,7 +908,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { ty::ExistentialTraitRef { def_id: trait_ref.def_id, - substs: tcx.mk_substs(&trait_ref.substs[1..]), + substs: tcx.mk().substs(&trait_ref.substs[1..]), } } @@ -1561,7 +1561,7 @@ impl<'tcx> ExistentialProjection<'tcx> { pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> { let def_id = tcx.parent(self.def_id); let subst_count = tcx.generics_of(def_id).count() - 1; - let substs = tcx.mk_substs(&self.substs[..subst_count]); + let substs = tcx.mk().substs(&self.substs[..subst_count]); ty::ExistentialTraitRef { def_id, substs } } @@ -1590,7 +1590,7 @@ impl<'tcx> ExistentialProjection<'tcx> { Self { def_id: projection_predicate.projection_ty.def_id, - substs: tcx.mk_substs(&projection_predicate.projection_ty.substs[1..]), + substs: tcx.mk().substs(&projection_predicate.projection_ty.substs[1..]), term: projection_predicate.term, } } @@ -2220,7 +2220,7 @@ impl<'tcx> Ty<'tcx> { let assoc_items = tcx.associated_item_def_ids( tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), ); - tcx.mk().projection(assoc_items[0], tcx.mk_substs(&[self.into()])) + tcx.mk().projection(assoc_items[0], tcx.mk().substs(&[self.into()])) } ty::Bool diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 1bbbc6786e82a..7a97203aa3189 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -319,7 +319,7 @@ impl<'tcx> InternalSubsts<'tcx> { let count = defs.count(); let mut substs = SmallVec::with_capacity(count); Self::fill_item(&mut substs, tcx, defs, &mut mk_kind); - tcx.mk_substs(&substs) + tcx.mk().substs(&substs) } pub fn extend_to(&self, tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx> @@ -493,7 +493,7 @@ impl<'tcx> TypeFoldable> for SubstsRef<'tcx> { if param0 == self[0] { Ok(self) } else { - Ok(folder.interner().mk_substs(&[param0])) + Ok(folder.interner().mk().substs(&[param0])) } } 2 => { @@ -502,11 +502,11 @@ impl<'tcx> TypeFoldable> for SubstsRef<'tcx> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().mk_substs(&[param0, param1])) + Ok(folder.interner().mk().substs(&[param0, param1])) } } 0 => Ok(self), - _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_substs(v)), + _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk().substs(v)), } } } diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index b9b1cd73a8b9a..502e7fa896d9c 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -112,5 +112,5 @@ pub(super) fn vtable_allocation_provider<'tcx>( } vtable.mutability = Mutability::Not; - tcx.create_memory_alloc(tcx.mk_const_alloc(vtable)) + tcx.create_memory_alloc(tcx.mk().const_alloc(vtable)) } diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 1e675d00b7625..80030c461f3f2 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -132,14 +132,14 @@ pub(crate) fn lit_to_mir_constant<'tcx>( (ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => { let s = s.as_str(); let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes()); - let allocation = tcx.mk_const_alloc(allocation); + let allocation = tcx.mk().const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: s.len() } } (ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(_)) => { let allocation = Allocation::from_bytes_byte_aligned_immutable(data as &[u8]); - let allocation = tcx.mk_const_alloc(allocation); + let allocation = tcx.mk().const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: data.len() } } (ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_array() => { diff --git a/compiler/rustc_mir_build/src/build/expr/as_operand.rs b/compiler/rustc_mir_build/src/build/expr/as_operand.rs index ff3198847df6c..ddcaf821bdf74 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_operand.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_operand.rs @@ -170,7 +170,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Return the operand *tmp0 to be used as the call argument let place = Place { local: operand, - projection: tcx.mk_place_elems(&[PlaceElem::Deref]), + projection: tcx.mk().place_elems(&[PlaceElem::Deref]), }; return block.and(Operand::Move(place)); diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 63bbb7503f760..8e13e09e02b1c 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -263,7 +263,7 @@ impl<'tcx> PlaceBuilder<'tcx> { let resolved = self.resolve_upvar(cx); let builder = resolved.as_ref().unwrap_or(self); let PlaceBase::Local(local) = builder.base else { return None }; - let projection = cx.tcx.mk_place_elems(&builder.projection); + let projection = cx.tcx.mk().place_elems(&builder.projection); Some(Place { local, projection }) } @@ -692,7 +692,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { tcx.mk().imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); let fake_borrow_temp = self.local_decls.push(LocalDecl::new(fake_borrow_ty, expr_span)); - let projection = tcx.mk_place_elems(&base_place.projection[..idx]); + let projection = tcx.mk().place_elems(&base_place.projection[..idx]); self.cfg.push_assign( block, source_info, diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index ff0a8d78d662c..585623a1674ff 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1211,7 +1211,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fake_borrows.insert(Place { local: source.local, - projection: self.tcx.mk_place_elems(proj_base), + projection: self.tcx.mk().place_elems(proj_base), }); } } @@ -1748,7 +1748,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|matched_place_ref| { let matched_place = Place { local: matched_place_ref.local, - projection: tcx.mk_place_elems(matched_place_ref.projection), + projection: tcx.mk().place_elems(matched_place_ref.projection), }; let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty; let fake_borrow_ty = tcx.mk().imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 5a722635cbd27..b0fa08bf0c912 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -802,7 +802,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let use_place = Place { local: ty::CAPTURE_STRUCT_LOCAL, - projection: tcx.mk_place_elems(&projs), + projection: tcx.mk().place_elems(&projs), }; self.var_debug_info.push(VarDebugInfo { name, diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 38723e52e0d3c..5964820226f6b 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -138,7 +138,7 @@ impl<'tcx> Cx<'tcx> { }; let bound_vars = - self.tcx.mk_bound_variable_kinds(&[ty::BoundVariableKind::Region(ty::BrEnv)]); + self.tcx.mk().bound_variable_kinds(&[ty::BoundVariableKind::Region(ty::BrEnv)]); let br = ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BrEnv, diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index b13b45a514f37..e57878e140db8 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -126,7 +126,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { BorrowedContent { target_place: Place { local: place.local, - projection: tcx.mk_place_elems(proj), + projection: tcx.mk().place_elems(proj), }, }, )); @@ -165,7 +165,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { if union_path.is_none() { base = self.add_move_path(base, elem, |tcx| Place { local: place.local, - projection: tcx.mk_place_elems(&place.projection[..i + 1]), + projection: tcx.mk().place_elems(&place.projection[..i + 1]), }); } } @@ -472,7 +472,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { // `ConstIndex` patterns. This is done to ensure that all move paths // are disjoint, which is expected by drop elaboration. let base_place = - Place { local: place.local, projection: self.builder.tcx.mk_place_elems(base) }; + Place { local: place.local, projection: self.builder.tcx.mk().place_elems(base) }; let base_path = match self.move_path_for(base_place) { Ok(path) => path, Err(MoveError::UnionMove { path }) => { diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index f27beb64a14d9..ab80d634506bc 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -124,7 +124,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) { if let Some(new_projection) = self.process_projection(&place.projection, loc) { - place.projection = self.tcx().mk_place_elems(&new_projection); + place.projection = self.tcx().mk().place_elems(&new_projection); } let observes_address = match ctxt { diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 5bef82dbd8876..4d3fdcadc4dd3 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -17,7 +17,7 @@ pub fn build_ptr_tys<'tcx>( unique_did: DefId, nonnull_did: DefId, ) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { - let substs = tcx.mk_substs(&[pointee.into()]); + let substs = tcx.mk().substs(&[pointee.into()]); let unique_ty = tcx.type_of(unique_did).subst(tcx, substs); let nonnull_ty = tcx.type_of(nonnull_did).subst(tcx, substs); let ptr_ty = tcx.mk().imm_ptr(pointee); @@ -138,7 +138,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs { if let Some(mut new_projections) = new_projections { new_projections.extend_from_slice(&place.projection[last_deref..]); - place.projection = tcx.mk_place_elems(&new_projections); + place.projection = tcx.mk().place_elems(&new_projections); } } } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 0e256e641d569..c590e1af94e83 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -126,7 +126,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> { place, Place { local: SELF_ARG, - projection: self.tcx().mk_place_elems(&[ProjectionElem::Deref]), + projection: self.tcx().mk().place_elems(&[ProjectionElem::Deref]), }, self.tcx, ); @@ -164,7 +164,8 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> { local: SELF_ARG, projection: self .tcx() - .mk_place_elems(&[ProjectionElem::Field(Field::new(0), self.ref_gen_ty)]), + .mk() + .place_elems(&[ProjectionElem::Field(Field::new(0), self.ref_gen_ty)]), }, self.tcx, ); @@ -186,7 +187,7 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx let mut new_projection = new_base.projection.to_vec(); new_projection.append(&mut place.projection.to_vec()); - place.projection = tcx.mk_place_elems(&new_projection); + place.projection = tcx.mk().place_elems(&new_projection); } const SELF_ARG: Local = Local::from_u32(1); @@ -299,7 +300,7 @@ impl<'tcx> TransformVisitor<'tcx> { let mut projection = base.projection.to_vec(); projection.push(ProjectionElem::Field(Field::new(idx), ty)); - Place { local: base.local, projection: self.tcx.mk_place_elems(&projection) } + Place { local: base.local, projection: self.tcx.mk().place_elems(&projection) } } // Create a statement which changes the discriminant @@ -427,7 +428,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span)); let pin_adt_ref = tcx.adt_def(pin_did); - let substs = tcx.mk_substs(&[ref_gen_ty.into()]); + let substs = tcx.mk().substs(&[ref_gen_ty.into()]); let pin_ref_gen_ty = tcx.mk().adt(pin_adt_ref, substs); // Replace the by ref generator argument @@ -1449,13 +1450,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // Compute Poll let poll_did = tcx.require_lang_item(LangItem::Poll, None); let poll_adt_ref = tcx.adt_def(poll_did); - let poll_substs = tcx.mk_substs(&[body.return_ty().into()]); + let poll_substs = tcx.mk().substs(&[body.return_ty().into()]); (poll_adt_ref, poll_substs) } else { // Compute GeneratorState let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); let state_adt_ref = tcx.adt_def(state_did); - let state_substs = tcx.mk_substs(&[yield_ty.into(), body.return_ty().into()]); + let state_substs = tcx.mk().substs(&[yield_ty.into(), body.return_ty().into()]); (state_adt_ref, state_substs) }; let ret_ty = tcx.mk().adt(state_adt_ref, state_substs); diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 298845bc9492d..a7c080d9693ac 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -885,7 +885,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { location: Location, ) { if let ProjectionElem::Field(f, ty) = elem { - let parent = Place { local, projection: self.tcx.mk_place_elems(proj_base) }; + let parent = Place { local, projection: self.tcx.mk().place_elems(proj_base) }; let parent_ty = parent.ty(&self.callee_body.local_decls, self.tcx); let check_equal = |this: &mut Self, f_ty| { if !util::is_equal_up_to_subtyping(this.tcx, this.param_env, ty, f_ty) { diff --git a/compiler/rustc_mir_transform/src/instcombine.rs b/compiler/rustc_mir_transform/src/instcombine.rs index 4182da1957e39..39408f833201c 100644 --- a/compiler/rustc_mir_transform/src/instcombine.rs +++ b/compiler/rustc_mir_transform/src/instcombine.rs @@ -121,7 +121,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> { *rvalue = Rvalue::Use(Operand::Copy(Place { local: base.local, - projection: self.tcx.mk_place_elems(base.projection), + projection: self.tcx.mk().place_elems(base.projection), })); } } diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index a4db9c2e1d4e9..0471ab6d78da6 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -114,7 +114,7 @@ impl EnumSizeOpt { tcx.data_layout.ptr_sized_integer().align(&tcx.data_layout).abi, Mutability::Not, ); - let alloc = tcx.create_memory_alloc(tcx.mk_const_alloc(alloc)); + let alloc = tcx.create_memory_alloc(tcx.mk().const_alloc(alloc)); Some((*adt_def, num_discrs, *alloc_cache.entry(ty).or_insert(alloc))) } fn optim<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -203,7 +203,8 @@ impl EnumSizeOpt { Rvalue::Use(Operand::Copy(Place { local: size_array_local, projection: tcx - .mk_place_elems(&[PlaceElem::Index(discr_cast_place.local)]), + .mk() + .place_elems(&[PlaceElem::Index(discr_cast_place.local)]), })), ))), }; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index b2c477c84d2ff..f976efd0bd634 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -191,7 +191,7 @@ fn remap_mir_for_const_eval_select<'tcx>( let arguments = (0..num_args).map(|x| { let mut place_elems = place_elems.to_vec(); place_elems.push(ProjectionElem::Field(x.into(), fields[x])); - let projection = tcx.mk_place_elems(&place_elems); + let projection = tcx.mk().place_elems(&place_elems); let place = Place { local: place.local, projection, diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 906500913b6e1..6d7eee51e2475 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -147,7 +147,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) assert!(!matches!(ty, Some(ty) if ty.is_generator())); let substs = if let Some(ty) = ty { - tcx.mk_substs(&[ty.into()]) + tcx.mk().substs(&[ty.into()]) } else { InternalSubsts::identity_for_item(tcx, def_id) }; diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 93f7ec3764296..afaf65359bd04 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -123,7 +123,7 @@ impl<'tcx> ReplacementMap<'tcx> { let &[PlaceElem::Field(f, _), ref rest @ ..] = place.projection else { return None; }; let fields = self.fragments[place.local].as_ref()?; let (_, new_local) = fields[f]?; - Some(Place { local: new_local, projection: tcx.mk_place_elems(&rest) }) + Some(Place { local: new_local, projection: tcx.mk().place_elems(&rest) }) } fn place_fragments( diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index aff27e5664b75..a1a1fd1905bcd 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1297,7 +1297,7 @@ impl<'v> RootCollector<'_, 'v> { self.tcx, ty::ParamEnv::reveal_all(), start_def_id, - self.tcx.mk_substs(&[main_ret_ty.into()]), + self.tcx.mk().substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap(); diff --git a/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs b/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs index 659d4faff7a61..d5c6c698cdba8 100644 --- a/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs +++ b/compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs @@ -105,7 +105,7 @@ impl<'a, 'tcx> Canonicalizer<'a, 'tcx> { .max() .unwrap_or(ty::UniverseIndex::ROOT); - let var_infos = self.infcx.tcx.mk_canonical_var_infos(&var_infos); + let var_infos = self.infcx.tcx.mk().canonical_var_infos(&var_infos); return (max_universe, var_infos); } } @@ -187,7 +187,7 @@ impl<'a, 'tcx> Canonicalizer<'a, 'tcx> { } } - let var_infos = self.infcx.tcx.mk_canonical_var_infos(&var_infos); + let var_infos = self.infcx.tcx.mk().canonical_var_infos(&var_infos); (curr_compressed_uv, var_infos) } } diff --git a/compiler/rustc_trait_selection/src/solve/canonical/mod.rs b/compiler/rustc_trait_selection/src/solve/canonical/mod.rs index 600581d5d0fb3..20c1775b875f1 100644 --- a/compiler/rustc_trait_selection/src/solve/canonical/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/canonical/mod.rs @@ -78,7 +78,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { let opaque_types = self.infcx.clone_opaque_types_for_query_response(); Ok(self .tcx() - .mk_external_constraints(ExternalConstraintsData { region_constraints, opaque_types })) + .mk() + .external_constraints(ExternalConstraintsData { region_constraints, opaque_types })) } /// After calling a canonical query, we apply the constraints returned diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs index 55d361b120441..2cf3ab12e4e14 100644 --- a/compiler/rustc_trait_selection/src/solve/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/mod.rs @@ -487,7 +487,7 @@ pub(super) fn response_no_constraints<'tcx>( var_values: CanonicalVarValues::make_identity(tcx, goal.variables), // FIXME: maybe we should store the "no response" version in tcx, like // we do for tcx.types and stuff. - external_constraints: tcx.mk_external_constraints(ExternalConstraintsData::default()), + external_constraints: tcx.mk().external_constraints(ExternalConstraintsData::default()), certainty, }, }) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 9f8a975a2e99e..cf797ce75d040 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1906,7 +1906,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( ) -> Progress<'tcx> { let tcx = selcx.tcx(); let self_ty = obligation.predicate.self_ty(); - let substs = tcx.mk_substs(&[self_ty.into()]); + let substs = tcx.mk().substs(&[self_ty.into()]); let lang_items = tcx.lang_items(); let item_def_id = obligation.predicate.def_id; let trait_def_id = tcx.trait_of_item(item_def_id).unwrap(); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 116a29f789c4d..9ac4c0ef1d39c 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -567,8 +567,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .into() } }); - let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); - let assoc_ty_substs = tcx.mk_substs(&substs); + let bound_vars = tcx.mk().bound_variable_kinds(&bound_vars); + let assoc_ty_substs = tcx.mk().substs(&substs); let bound = bound.map_bound(|b| b.kind().skip_binder()).subst(tcx, assoc_ty_substs); tcx.mk().predicate(ty::Binder::bind_with_vars(bound, bound_vars)) diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 4eade63742fa2..a84702685e929 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -99,7 +99,7 @@ fn fn_sig_for_fn_abi<'tcx>( let pin_did = tcx.require_lang_item(LangItem::Pin, None); let pin_adt_ref = tcx.adt_def(pin_did); - let pin_substs = tcx.mk_substs(&[env_ty.into()]); + let pin_substs = tcx.mk().substs(&[env_ty.into()]); let env_ty = tcx.mk().adt(pin_adt_ref, pin_substs); let sig = sig.skip_binder(); @@ -111,7 +111,7 @@ fn fn_sig_for_fn_abi<'tcx>( // The signature should be `Future::poll(_, &mut Context<'_>) -> Poll` let poll_did = tcx.require_lang_item(LangItem::Poll, None); let poll_adt_ref = tcx.adt_def(poll_did); - let poll_substs = tcx.mk_substs(&[sig.return_ty.into()]); + let poll_substs = tcx.mk().substs(&[sig.return_ty.into()]); let ret_ty = tcx.mk().adt(poll_adt_ref, poll_substs); // We have to replace the `ResumeTy` that is used for type and borrow checking @@ -133,7 +133,7 @@ fn fn_sig_for_fn_abi<'tcx>( // The signature should be `Generator::resume(_, Resume) -> GeneratorState` let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); let state_adt_ref = tcx.adt_def(state_did); - let state_substs = tcx.mk_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); + let state_substs = tcx.mk().substs(&[sig.yield_ty.into(), sig.return_ty.into()]); let ret_ty = tcx.mk().adt(state_adt_ref, state_substs); (sig.resume_ty, ret_ty) diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 98b5b299e69e5..1592e6f242963 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -144,7 +144,7 @@ fn recurse_build<'tcx>( for &id in args.iter() { new_args.push(recurse_build(tcx, body, id, root_span)?); } - let new_args = tcx.mk_const_list(&new_args); + let new_args = tcx.mk().const_list(&new_args); tcx.mk().const_(Expr::FunctionCall(fun, new_args), node.ty) } &ExprKind::Binary { op, lhs, rhs } if check_binop(op) => { diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 91bb56bafded9..ac0a04ab70d57 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -104,23 +104,23 @@ fn layout_of_uncached<'tcx>( assert!(size.bits() <= 128); Scalar::Initialized { value, valid_range: WrappingRange::full(size) } }; - let scalar = |value: Primitive| tcx.mk_layout(LayoutS::scalar(cx, scalar_unit(value))); + let scalar = |value: Primitive| tcx.mk().layout(LayoutS::scalar(cx, scalar_unit(value))); let univariant = |fields: &[Layout<'_>], repr: &ReprOptions, kind| { - Ok(tcx.mk_layout(univariant_uninterned(cx, ty, fields, repr, kind)?)) + Ok(tcx.mk().layout(univariant_uninterned(cx, ty, fields, repr, kind)?)) }; debug_assert!(!ty.has_non_region_infer()); Ok(match *ty.kind() { // Basic scalars. - ty::Bool => tcx.mk_layout(LayoutS::scalar( + ty::Bool => tcx.mk().layout(LayoutS::scalar( cx, Scalar::Initialized { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 }, }, )), - ty::Char => tcx.mk_layout(LayoutS::scalar( + ty::Char => tcx.mk().layout(LayoutS::scalar( cx, Scalar::Initialized { value: Int(I32, false), @@ -136,11 +136,11 @@ fn layout_of_uncached<'tcx>( ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer(dl.instruction_address_space)); ptr.valid_range_mut().start = 1; - tcx.mk_layout(LayoutS::scalar(cx, ptr)) + tcx.mk().layout(LayoutS::scalar(cx, ptr)) } // The never type. - ty::Never => tcx.mk_layout(cx.layout_of_never_type()), + ty::Never => tcx.mk().layout(cx.layout_of_never_type()), // Potentially-wide pointers. ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { @@ -151,7 +151,7 @@ fn layout_of_uncached<'tcx>( let pointee = tcx.normalize_erasing_regions(param_env, pointee); if pointee.is_sized(tcx, param_env) { - return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk().layout(LayoutS::scalar(cx, data_ptr))); } let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env); @@ -168,7 +168,7 @@ fn layout_of_uncached<'tcx>( let metadata_layout = cx.layout_of(metadata_ty)?; // If the metadata is a 1-zst, then the pointer is thin. if metadata_layout.is_zst() && metadata_layout.align.abi.bytes() == 1 { - return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk().layout(LayoutS::scalar(cx, data_ptr))); } let Abi::Scalar(metadata) = metadata_layout.abi else { @@ -178,7 +178,7 @@ fn layout_of_uncached<'tcx>( } else { match unsized_part.kind() { ty::Foreign(..) => { - return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk().layout(LayoutS::scalar(cx, data_ptr))); } ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { @@ -193,7 +193,7 @@ fn layout_of_uncached<'tcx>( }; // Effectively a (ptr, meta) tuple. - tcx.mk_layout(cx.scalar_pair(data_ptr, metadata)) + tcx.mk().layout(cx.scalar_pair(data_ptr, metadata)) } ty::Dynamic(_, _, ty::DynStar) => { @@ -201,7 +201,7 @@ fn layout_of_uncached<'tcx>( data.valid_range_mut().start = 0; let mut vtable = scalar_unit(Pointer(AddressSpace::DATA)); vtable.valid_range_mut().start = 1; - tcx.mk_layout(cx.scalar_pair(data, vtable)) + tcx.mk().layout(cx.scalar_pair(data, vtable)) } // Arrays and slices. @@ -226,7 +226,7 @@ fn layout_of_uncached<'tcx>( let largest_niche = if count != 0 { element.largest_niche } else { None }; - tcx.mk_layout(LayoutS { + tcx.mk().layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: element.size, count }, abi, @@ -237,7 +237,7 @@ fn layout_of_uncached<'tcx>( } ty::Slice(element) => { let element = cx.layout_of(element)?; - tcx.mk_layout(LayoutS { + tcx.mk().layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: element.size, count: 0 }, abi: Abi::Aggregate { sized: false }, @@ -246,7 +246,7 @@ fn layout_of_uncached<'tcx>( size: Size::ZERO, }) } - ty::Str => tcx.mk_layout(LayoutS { + ty::Str => tcx.mk().layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 }, abi: Abi::Aggregate { sized: false }, @@ -269,7 +269,7 @@ fn layout_of_uncached<'tcx>( Abi::Aggregate { ref mut sized } => *sized = false, _ => bug!(), } - tcx.mk_layout(unit) + tcx.mk().layout(unit) } ty::Generator(def_id, substs, _) => generator_layout(cx, ty, def_id, substs)?, @@ -398,7 +398,7 @@ fn layout_of_uncached<'tcx>( FieldsShape::Array { stride: e_ly.size, count: e_len } }; - tcx.mk_layout(LayoutS { + tcx.mk().layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields, abi: Abi::Vector { element: e_abi, count: e_len }, @@ -431,12 +431,12 @@ fn layout_of_uncached<'tcx>( return Err(LayoutError::Unknown(ty)); } - return Ok(tcx.mk_layout( + return Ok(tcx.mk().layout( cx.layout_of_union(&def.repr(), &variants).ok_or(LayoutError::Unknown(ty))?, )); } - tcx.mk_layout( + tcx.mk().layout( cx.layout_of_struct_or_enum( &def.repr(), &variants, @@ -640,7 +640,7 @@ fn generator_layout<'tcx>( value: Primitive::Int(discr_int, false), valid_range: WrappingRange { start: 0, end: max_discr }, }; - let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag)); + let tag_layout = cx.tcx.mk().layout(LayoutS::scalar(cx, tag)); let promoted_layouts = ineligible_locals .iter() @@ -788,7 +788,7 @@ fn generator_layout<'tcx>( Abi::Aggregate { sized: true } }; - let layout = tcx.mk_layout(LayoutS { + let layout = tcx.mk().layout(LayoutS { variants: Variants::Multiple { tag, tag_encoding: TagEncoding::Direct, From 959acfc2a87afe2a124080a06c2e7c769d6e4f5e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Mar 2023 17:22:18 +0000 Subject: [PATCH 5/8] Remove `mk_*` methods from `TyCtxt` --- compiler/rustc_middle/src/ty/context.rs | 728 +----------------------- 1 file changed, 8 insertions(+), 720 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 7dfdb10732bdb..2f3de0287723b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -13,19 +13,16 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::resolve_bound_vars; use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstAllocation}; -use crate::mir::{ - Body, BorrowCheckResult, Field, Local, Place, PlaceElem, ProjectionKind, Promoted, -}; +use crate::mir::{Body, BorrowCheckResult, PlaceElem, ProjectionKind, Promoted}; use crate::thir::Thir; use crate::traits; use crate::traits::solve; use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData}; use crate::ty::query::{self, TyCtxtAt}; use crate::ty::{ - self, AdtDef, AdtDefData, AdtKind, Binder, Const, ConstData, FloatTy, FloatVar, FloatVid, - GenericParamDefKind, ImplPolarity, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, - PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions, - TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut, TypeckResults, UintTy, Visibility, + self, AdtDef, AdtDefData, Binder, Const, ConstData, ImplPolarity, InferTy, List, ParamTy, + PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, + TraitObjectVisitor, Ty, TyKind, TyVid, TypeAndMut, TypeckResults, Visibility, }; use crate::ty::{GenericArg, InternalSubsts, SubstsRef}; use rustc_ast as ast; @@ -65,15 +62,14 @@ use rustc_span::def_id::{DefPathHash, StableCrateId}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use rustc_target::abi::{Layout, LayoutS, TargetDataLayout, VariantIdx}; +use rustc_target::abi::{Layout, LayoutS, TargetDataLayout}; use rustc_target::spec::abi; use rustc_type_ir::sty::TyKind::*; use rustc_type_ir::WithCachedTypeInfo; -use rustc_type_ir::{CollectAndApply, DynKind, Interner, TypeFlags}; +use rustc_type_ir::{Interner, TypeFlags}; use std::any::Any; use std::borrow::Borrow; -use std::cmp::Ordering; use std::fmt; use std::hash::{Hash, Hasher}; use std::iter; @@ -621,17 +617,6 @@ impl<'tcx> TyCtxt<'tcx> { self.arena.alloc(Steal::new(promoted)) } - #[deprecated(suggestion = "mk().adt_def")] - pub fn mk_adt_def( - self, - did: DefId, - kind: AdtKind, - variants: IndexVec, - repr: ReprOptions, - ) -> ty::AdtDef<'tcx> { - self.mk_adt_def_from_data(ty::AdtDefData::new(self, did, kind, variants, repr)) - } - /// Allocates a read-only byte or string literal for `mir::interpret`. pub fn allocate_bytes(self, bytes: &[u8]) -> interpret::AllocId { // Create an allocation that just contains these bytes. @@ -744,32 +729,6 @@ impl<'tcx> TyCtxt<'tcx> { self.mk().ty_from_kind(Error(reported)) } - /// Constructs a `RegionKind::ReError` lifetime. - #[deprecated(suggestion = "mk().re_error")] - pub fn mk_re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> { - self.intern_region(ty::ReError(reported)) - } - - /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it - /// gets used. - #[track_caller] - #[deprecated(suggestion = "mk().re_error_misc")] - pub fn mk_re_error_misc(self) -> Region<'tcx> { - self.mk_re_error_with_message( - DUMMY_SP, - "RegionKind::ReError constructed but no error reported", - ) - } - - /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given - /// `msg` to ensure it gets used. - #[track_caller] - #[deprecated(suggestion = "mk().re_error_with_message")] - pub fn mk_re_error_with_message>(self, span: S, msg: &str) -> Region<'tcx> { - let reported = self.sess.delay_span_bug(span, msg); - self.mk_re_error(reported) - } - /// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed` #[track_caller] pub fn const_error_with_guaranteed( @@ -1690,229 +1649,13 @@ impl<'tcx> TyCtxt<'tcx> { }) } - // Avoid this in favour of more specific `mk_*` methods, where possible. - #[allow(rustc::usage_of_ty_tykind)] - #[inline] - #[deprecated(suggestion = "mk().ty_from_kind")] - pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> { - self.interners.intern_ty( - st, - self.sess, - // This is only used to create a stable hashing context. - &self.untracked, - ) - } - - #[inline] - #[deprecated(suggestion = "mk().predicate")] - pub fn mk_predicate(self, binder: Binder<'tcx, PredicateKind<'tcx>>) -> Predicate<'tcx> { - self.interners.intern_predicate( - binder, - self.sess, - // This is only used to create a stable hashing context. - &self.untracked, - ) - } - #[inline] pub fn reuse_or_mk_predicate( self, pred: Predicate<'tcx>, binder: Binder<'tcx, PredicateKind<'tcx>>, ) -> Predicate<'tcx> { - if pred.kind() != binder { self.mk_predicate(binder) } else { pred } - } - - #[deprecated(suggestion = "mk().mach_int")] - pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> { - match tm { - IntTy::Isize => self.types.isize, - IntTy::I8 => self.types.i8, - IntTy::I16 => self.types.i16, - IntTy::I32 => self.types.i32, - IntTy::I64 => self.types.i64, - IntTy::I128 => self.types.i128, - } - } - - #[deprecated(suggestion = "mk().mach_uint")] - pub fn mk_mach_uint(self, tm: UintTy) -> Ty<'tcx> { - match tm { - UintTy::Usize => self.types.usize, - UintTy::U8 => self.types.u8, - UintTy::U16 => self.types.u16, - UintTy::U32 => self.types.u32, - UintTy::U64 => self.types.u64, - UintTy::U128 => self.types.u128, - } - } - - #[deprecated(suggestion = "mk().mach_float")] - pub fn mk_mach_float(self, tm: FloatTy) -> Ty<'tcx> { - match tm { - FloatTy::F32 => self.types.f32, - FloatTy::F64 => self.types.f64, - } - } - - #[inline] - #[deprecated(suggestion = "mk().static_str")] - pub fn mk_static_str(self) -> Ty<'tcx> { - self.mk_imm_ref(self.lifetimes.re_static, self.types.str_) - } - - #[inline] - #[deprecated(suggestion = "mk().adt")] - pub fn mk_adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - // Take a copy of substs so that we own the vectors inside. - self.mk_ty_from_kind(Adt(def, substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().foreign")] - pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> { - self.mk_ty_from_kind(Foreign(def_id)) - } - - fn mk_generic_adt(self, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> { - let adt_def = self.adt_def(wrapper_def_id); - let substs = - InternalSubsts::for_item(self, wrapper_def_id, |param, substs| match param.kind { - GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(), - GenericParamDefKind::Type { has_default, .. } => { - if param.index == 0 { - ty_param.into() - } else { - assert!(has_default); - self.type_of(param.def_id).subst(self, substs).into() - } - } - }); - self.mk_ty_from_kind(Adt(adt_def, substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().box_")] - pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> { - let def_id = self.require_lang_item(LangItem::OwnedBox, None); - self.mk_generic_adt(def_id, ty) - } - - #[inline] - #[deprecated(suggestion = "mk().lang_item")] - pub fn mk_lang_item(self, ty: Ty<'tcx>, item: LangItem) -> Option> { - let def_id = self.lang_items().get(item)?; - Some(self.mk_generic_adt(def_id, ty)) - } - - #[inline] - #[deprecated(suggestion = "mk().diagnostic_item")] - pub fn mk_diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option> { - let def_id = self.get_diagnostic_item(name)?; - Some(self.mk_generic_adt(def_id, ty)) - } - - #[inline] - #[deprecated(suggestion = "mk().maybe_uninit")] - pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> { - let def_id = self.require_lang_item(LangItem::MaybeUninit, None); - self.mk_generic_adt(def_id, ty) - } - - #[inline] - #[deprecated(suggestion = "mk().ptr")] - pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(RawPtr(tm)) - } - - #[inline] - #[deprecated(suggestion = "mk().ref_")] - pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(Ref(r, tm.ty, tm.mutbl)) - } - - #[inline] - #[deprecated(suggestion = "mk().mut_ref")] - pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Mut }) - } - - #[inline] - #[deprecated(suggestion = "mk().imm_ref")] - pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Not }) - } - - #[inline] - #[deprecated(suggestion = "mk().mut_ptr")] - pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Mut }) - } - - #[inline] - #[deprecated(suggestion = "mk().imm_ptr")] - pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Not }) - } - - #[inline] - #[deprecated(suggestion = "mk().array")] - pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { - self.mk_ty_from_kind(Array(ty, ty::Const::from_target_usize(self, n))) - } - - #[inline] - #[deprecated(suggestion = "mk().array_with_const_len")] - pub fn mk_array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(Array(ty, ct)) - } - - #[inline] - #[deprecated(suggestion = "mk().slice")] - pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(Slice(ty)) - } - - #[inline] - #[deprecated(suggestion = "mk().tup")] - pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { - if ts.is_empty() { - self.types.unit - } else { - self.mk_ty_from_kind(Tuple(self.mk_type_list(&ts))) - } - } - - #[deprecated(suggestion = "mk().tup_from_iter")] - pub fn mk_tup_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, Ty<'tcx>>, - { - T::collect_and_apply(iter, |ts| self.mk_tup(ts)) - } - - #[inline] - #[deprecated(suggestion = "mk().unit")] - pub fn mk_unit(self) -> Ty<'tcx> { - self.types.unit - } - - #[inline] - #[deprecated(suggestion = "mk().diverging_default")] - pub fn mk_diverging_default(self) -> Ty<'tcx> { - if self.features().never_type_fallback { self.types.never } else { self.types.unit } - } - - #[inline] - #[deprecated(suggestion = "mk().fn_def")] - pub fn mk_fn_def( - self, - def_id: DefId, - substs: impl IntoIterator>>, - ) -> Ty<'tcx> { - let substs = self.check_and_mk_substs(def_id, substs); - self.mk_ty_from_kind(FnDef(def_id, substs)) + if pred.kind() != binder { self.mk().predicate(binder) } else { pred } } #[inline(always)] @@ -1935,461 +1678,6 @@ impl<'tcx> TyCtxt<'tcx> { self.mk().substs_from_iter(substs) } - #[inline] - #[deprecated(suggestion = "mk().fn_ptr")] - pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(FnPtr(fty)) - } - - #[inline] - #[deprecated(suggestion = "mk().dynamic")] - pub fn mk_dynamic( - self, - obj: &'tcx List>, - reg: ty::Region<'tcx>, - repr: DynKind, - ) -> Ty<'tcx> { - self.mk_ty_from_kind(Dynamic(obj, reg, repr)) - } - - #[inline] - #[deprecated(suggestion = "mk().projection")] - pub fn mk_projection( - self, - item_def_id: DefId, - substs: impl IntoIterator>>, - ) -> Ty<'tcx> { - self.mk_alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().closure")] - pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(Closure(closure_id, closure_substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().generator")] - pub fn mk_generator( - self, - id: DefId, - generator_substs: SubstsRef<'tcx>, - movability: hir::Movability, - ) -> Ty<'tcx> { - self.mk_ty_from_kind(Generator(id, generator_substs, movability)) - } - - #[inline] - #[deprecated(suggestion = "mk().generator_witness")] - pub fn mk_generator_witness(self, types: ty::Binder<'tcx, &'tcx List>>) -> Ty<'tcx> { - self.mk_ty_from_kind(GeneratorWitness(types)) - } - - /// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes. - #[deprecated(suggestion = "mk().task_context")] - pub fn mk_task_context(self) -> Ty<'tcx> { - let context_did = self.require_lang_item(LangItem::Context, None); - let context_adt_ref = self.adt_def(context_did); - let context_substs = self.mk_substs(&[self.lifetimes.re_erased.into()]); - let context_ty = self.mk_adt(context_adt_ref, context_substs); - self.mk_mut_ref(self.lifetimes.re_erased, context_ty) - } - - #[inline] - #[deprecated(suggestion = "mk().generator_witness_mir")] - pub fn mk_generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(GeneratorWitnessMIR(id, substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().const_")] - pub fn mk_const(self, kind: impl Into>, ty: Ty<'tcx>) -> Const<'tcx> { - self.intern_const(ty::ConstData { kind: kind.into(), ty }) - } - - #[inline] - #[deprecated(suggestion = "mk().ty_var")] - pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> { - // Use a pre-interned one when possible. - self.types - .ty_vars - .get(v.as_usize()) - .copied() - .unwrap_or_else(|| self.mk_ty_from_kind(Infer(TyVar(v)))) - } - - #[inline] - #[deprecated(suggestion = "mk().int_var")] - pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> { - self.mk_ty_from_kind(Infer(IntVar(v))) - } - - #[inline] - #[deprecated(suggestion = "mk().float_var")] - pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> { - self.mk_ty_from_kind(Infer(FloatVar(v))) - } - - #[inline] - #[deprecated(suggestion = "mk().fresh_ty")] - pub fn mk_fresh_ty(self, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - self.types - .fresh_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshTy(n)))) - } - - #[inline] - #[deprecated(suggestion = "mk().fresh_int_ty")] - pub fn mk_fresh_int_ty(self, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - self.types - .fresh_int_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshIntTy(n)))) - } - - #[inline] - #[deprecated(suggestion = "mk().fresh_float_ty")] - pub fn mk_fresh_float_ty(self, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - self.types - .fresh_float_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshFloatTy(n)))) - } - - #[inline] - #[deprecated(suggestion = "mk().ty_param")] - pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> { - self.mk_ty_from_kind(Param(ParamTy { index, name })) - } - - #[deprecated(suggestion = "mk().param_from_def")] - pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { - match param.kind { - GenericParamDefKind::Lifetime => { - self.mk_re_early_bound(param.to_early_bound_region_data()).into() - } - GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(), - GenericParamDefKind::Const { .. } => self - .mk_const( - ParamConst { index: param.index, name: param.name }, - self.type_of(param.def_id) - .no_bound_vars() - .expect("const parameter types cannot be generic"), - ) - .into(), - } - } - - #[inline] - #[deprecated(suggestion = "mk().bound")] - pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> { - self.mk_ty_from_kind(Bound(index, bound_ty)) - } - - #[inline] - #[deprecated(suggestion = "mk().placeholder")] - pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> { - self.mk_ty_from_kind(Placeholder(placeholder)) - } - - #[inline] - #[deprecated(suggestion = "mk().alias")] - pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { - self.mk_ty_from_kind(Alias(kind, alias_ty)) - } - - #[inline] - #[deprecated(suggestion = "mk().opaque")] - pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_alias(ty::Opaque, self.mk_alias_ty(def_id, substs)) - } - - #[inline] - #[deprecated(suggestion = "mk().re_early_bound")] - pub fn mk_re_early_bound(self, early_bound_region: ty::EarlyBoundRegion) -> Region<'tcx> { - self.intern_region(ty::ReEarlyBound(early_bound_region)) - } - - #[inline] - #[deprecated(suggestion = "mk().re_late_bound")] - pub fn mk_re_late_bound( - self, - debruijn: ty::DebruijnIndex, - bound_region: ty::BoundRegion, - ) -> Region<'tcx> { - // Use a pre-interned one when possible. - if let ty::BoundRegion { var, kind: ty::BrAnon(v, None) } = bound_region - && var.as_u32() == v - && let Some(inner) = self.lifetimes.re_late_bounds.get(debruijn.as_usize()) - && let Some(re) = inner.get(v as usize).copied() - { - re - } else { - self.intern_region(ty::ReLateBound(debruijn, bound_region)) - } - } - - #[inline] - #[deprecated(suggestion = "mk().re_free")] - pub fn mk_re_free(self, scope: DefId, bound_region: ty::BoundRegionKind) -> Region<'tcx> { - self.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region })) - } - - #[inline] - #[deprecated(suggestion = "mk().re_var")] - pub fn mk_re_var(self, v: ty::RegionVid) -> Region<'tcx> { - // Use a pre-interned one when possible. - self.lifetimes - .re_vars - .get(v.as_usize()) - .copied() - .unwrap_or_else(|| self.intern_region(ty::ReVar(v))) - } - - #[inline] - #[deprecated(suggestion = "mk().re_placeholder")] - pub fn mk_re_placeholder(self, placeholder: ty::PlaceholderRegion) -> Region<'tcx> { - self.intern_region(ty::RePlaceholder(placeholder)) - } - - // Avoid this in favour of more specific `mk_re_*` methods, where possible, - // to avoid the cost of the `match`. - #[deprecated(suggestion = "mk().region_from_kind")] - pub fn mk_region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> { - match kind { - ty::ReEarlyBound(region) => self.mk_re_early_bound(region), - ty::ReLateBound(debruijn, region) => self.mk_re_late_bound(debruijn, region), - ty::ReFree(ty::FreeRegion { scope, bound_region }) => { - self.mk_re_free(scope, bound_region) - } - ty::ReStatic => self.lifetimes.re_static, - ty::ReVar(vid) => self.mk_re_var(vid), - ty::RePlaceholder(region) => self.mk_re_placeholder(region), - ty::ReErased => self.lifetimes.re_erased, - ty::ReError(reported) => self.mk_re_error(reported), - } - } - - #[deprecated(suggestion = "mk().place_field")] - pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { - self.mk_place_elem(place, PlaceElem::Field(f, ty)) - } - - #[deprecated(suggestion = "mk().place_deref")] - pub fn mk_place_deref(self, place: Place<'tcx>) -> Place<'tcx> { - self.mk_place_elem(place, PlaceElem::Deref) - } - - #[deprecated(suggestion = "mk().place_downcast")] - pub fn mk_place_downcast( - self, - place: Place<'tcx>, - adt_def: AdtDef<'tcx>, - variant_index: VariantIdx, - ) -> Place<'tcx> { - self.mk_place_elem( - place, - PlaceElem::Downcast(Some(adt_def.variant(variant_index).name), variant_index), - ) - } - - #[deprecated(suggestion = "mk().place_downcast_unnamed")] - pub fn mk_place_downcast_unnamed( - self, - place: Place<'tcx>, - variant_index: VariantIdx, - ) -> Place<'tcx> { - self.mk_place_elem(place, PlaceElem::Downcast(None, variant_index)) - } - - #[deprecated(suggestion = "mk().place_index")] - pub fn mk_place_index(self, place: Place<'tcx>, index: Local) -> Place<'tcx> { - self.mk_place_elem(place, PlaceElem::Index(index)) - } - - /// This method copies `Place`'s projection, add an element and reintern it. Should not be used - /// to build a full `Place` it's just a convenient way to grab a projection and modify it in - /// flight. - #[deprecated(suggestion = "mk().place_elem")] - pub fn mk_place_elem(self, place: Place<'tcx>, elem: PlaceElem<'tcx>) -> Place<'tcx> { - let mut projection = place.projection.to_vec(); - projection.push(elem); - - Place { local: place.local, projection: self.mk_place_elems(&projection) } - } - - #[deprecated(suggestion = "mk().poly_existential_predicates")] - - pub fn mk_poly_existential_predicates( - self, - eps: &[PolyExistentialPredicate<'tcx>], - ) -> &'tcx List> { - assert!(!eps.is_empty()); - assert!( - eps.array_windows() - .all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder()) - != Ordering::Greater) - ); - self.intern_poly_existential_predicates(eps) - } - - #[deprecated(suggestion = "mk().predicates")] - pub fn mk_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List> { - // FIXME consider asking the input slice to be sorted to avoid - // re-interning permutations, in which case that would be asserted - // here. - self.intern_predicates(preds) - } - - #[deprecated(suggestion = "mk().const_list_from_iter")] - pub fn mk_const_list_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_const_list(xs)) - } - - #[deprecated(suggestion = "mk().type_list")] - pub fn mk_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { - // Actually intern type lists as lists of `GenericArg`s. - // - // Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound - // as explained in `ty_slice_as_generic_arg`. With this, - // we guarantee that even when transmuting between `List>` - // and `List>`, the uniqueness requirement for - // lists is upheld. - let substs = self.mk_substs(ty::subst::ty_slice_as_generic_args(ts)); - substs.try_as_type_list().unwrap() - } - - // Unlike various other `mk_*_from_iter` functions, this one uses `I: - // IntoIterator` instead of `I: Iterator`, and it doesn't have a slice - // variant, because of the need to combine `inputs` and `output`. This - // explains the lack of `_from_iter` suffix. - #[deprecated(suggestion = "mk().fn_sig")] - pub fn mk_fn_sig( - self, - inputs: I, - output: I::Item, - c_variadic: bool, - unsafety: hir::Unsafety, - abi: abi::Abi, - ) -> T::Output - where - I: IntoIterator, - T: CollectAndApply, ty::FnSig<'tcx>>, - { - T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig { - inputs_and_output: self.mk_type_list(xs), - c_variadic, - unsafety, - abi, - }) - } - - #[deprecated(suggestion = "mk().poly_existential_predicates_from_iter")] - pub fn mk_poly_existential_predicates_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply< - PolyExistentialPredicate<'tcx>, - &'tcx List>, - >, - { - T::collect_and_apply(iter, |xs| self.mk_poly_existential_predicates(xs)) - } - - #[deprecated(suggestion = "mk().predicates_from_iter")] - pub fn mk_predicates_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_predicates(xs)) - } - - #[deprecated(suggestion = "mk().type_list_from_iter")] - pub fn mk_type_list_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_type_list(xs)) - } - - #[deprecated(suggestion = "mk().substs_from_iter")] - pub fn mk_substs_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_substs(xs)) - } - - #[deprecated(suggestion = "mk().canonical_var_infos_from_iter")] - pub fn mk_canonical_var_infos_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_canonical_var_infos(xs)) - } - - #[deprecated(suggestion = "mk().place_elems_from_iter")] - pub fn mk_place_elems_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply, &'tcx List>>, - { - T::collect_and_apply(iter, |xs| self.mk_place_elems(xs)) - } - - #[deprecated(suggestion = "mk().substs_trait")] - pub fn mk_substs_trait( - self, - self_ty: Ty<'tcx>, - rest: impl IntoIterator>, - ) -> SubstsRef<'tcx> { - self.mk_substs_from_iter(iter::once(self_ty.into()).chain(rest)) - } - - #[deprecated(suggestion = "mk().trait_ref")] - pub fn mk_trait_ref( - self, - trait_def_id: DefId, - substs: impl IntoIterator>>, - ) -> ty::TraitRef<'tcx> { - let substs = self.check_and_mk_substs(trait_def_id, substs); - ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } - } - - #[deprecated(suggestion = "mk().alias_ty")] - pub fn mk_alias_ty( - self, - def_id: DefId, - substs: impl IntoIterator>>, - ) -> ty::AliasTy<'tcx> { - let substs = self.check_and_mk_substs(def_id, substs); - ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } - } - - #[deprecated(suggestion = "mk().bound_variable_kinds_from_iter")] - pub fn mk_bound_variable_kinds_from_iter(self, iter: I) -> T::Output - where - I: Iterator, - T: CollectAndApply>, - { - T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs)) - } - /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// typically generated by `#[derive(LintDiagnostic)]`). pub fn emit_spanned_lint( @@ -2561,7 +1849,7 @@ impl<'tcx> TyCtxtAt<'tcx> { substs: impl IntoIterator>>, ) -> ty::TraitRef<'tcx> { let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span)); - self.tcx.mk_trait_ref(trait_def_id, substs) + self.tcx.mk().trait_ref(trait_def_id, substs) } } From 6d67b090b541b8a94a32c6fb2f33d6590b7b3c0b Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Mar 2023 18:08:28 +0000 Subject: [PATCH 6/8] Remove last `mk_*` methods from `TyCtxt` --- compiler/rustc_middle/src/ty/context.rs | 23 ++++++++++------------ compiler/rustc_middle/src/ty/context/mk.rs | 20 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2f3de0287723b..af609334c29a5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1524,15 +1524,13 @@ macro_rules! direct_interners { // Functions with a `mk_` prefix are intended for use outside this file and // crate. Functions with an `intern_` prefix are intended for use within this // file only, and have a corresponding `mk_` function. -// -// TODO(waffle): pub mk_* -> intern_* direct_interners! { region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>, const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>, - const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, - layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>, - adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>, - external_constraints: pub mk_external_constraints(ExternalConstraintsData<'tcx>): + const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, + layout: intern_layout(LayoutS): Layout -> Layout<'tcx>, + adt_def: intern_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>, + external_constraints: intern_external_constraints(ExternalConstraintsData<'tcx>): ExternalConstraints -> ExternalConstraints<'tcx>, } @@ -1555,16 +1553,15 @@ macro_rules! slice_interners { // These functions intern slices. They all have a corresponding // `mk_foo_from_iter` function that interns an iterator. The slice version // should be used when possible, because it's faster. -// TODO: deprecate/make into private `intern_*`/etc all `mk_*` methods here slice_interners!( - const_lists: pub mk_const_list(Const<'tcx>), - substs: pub mk_substs(GenericArg<'tcx>), - canonical_var_infos: pub mk_canonical_var_infos(CanonicalVarInfo<'tcx>), + const_lists: intern_const_list(Const<'tcx>), + substs: intern_substs(GenericArg<'tcx>), + canonical_var_infos: intern_canonical_var_infos(CanonicalVarInfo<'tcx>), poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>), predicates: intern_predicates(Predicate<'tcx>), - projs: pub mk_projs(ProjectionKind), - place_elems: pub mk_place_elems(PlaceElem<'tcx>), - bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind), + projs: intern_projs(ProjectionKind), + place_elems: intern_place_elems(PlaceElem<'tcx>), + bound_variable_kinds: intern_bound_variable_kinds(ty::BoundVariableKind), ); impl<'tcx> TyCtxt<'tcx> { diff --git a/compiler/rustc_middle/src/ty/context/mk.rs b/compiler/rustc_middle/src/ty/context/mk.rs index 79a306ee91dad..515f3e18f94ad 100644 --- a/compiler/rustc_middle/src/ty/context/mk.rs +++ b/compiler/rustc_middle/src/ty/context/mk.rs @@ -692,12 +692,12 @@ impl<'tcx> MkCtxt<'tcx> { #[inline] pub fn const_list(self, v: &[Const<'tcx>]) -> &'tcx List> { - self.tcx.mk_const_list(v) + self.tcx.intern_const_list(v) } #[inline] pub fn substs(self, v: &[GenericArg<'tcx>]) -> &'tcx List> { - self.tcx.mk_substs(v) + self.tcx.intern_substs(v) } #[inline] @@ -705,17 +705,17 @@ impl<'tcx> MkCtxt<'tcx> { self, v: &[CanonicalVarInfo<'tcx>], ) -> &'tcx List> { - self.tcx.mk_canonical_var_infos(v) + self.tcx.intern_canonical_var_infos(v) } #[inline] pub fn projs(self, v: &[ProjectionKind]) -> &'tcx List { - self.tcx.mk_projs(v) + self.tcx.intern_projs(v) } #[inline] pub fn place_elems(self, v: &[PlaceElem<'tcx>]) -> &'tcx List> { - self.tcx.mk_place_elems(v) + self.tcx.intern_place_elems(v) } #[inline] @@ -723,22 +723,22 @@ impl<'tcx> MkCtxt<'tcx> { self, v: &[ty::BoundVariableKind], ) -> &'tcx List { - self.tcx.mk_bound_variable_kinds(v) + self.tcx.intern_bound_variable_kinds(v) } #[inline] pub fn const_alloc(self, v: Allocation) -> ConstAllocation<'tcx> { - self.tcx.mk_const_alloc(v) + self.tcx.intern_const_alloc(v) } #[inline] pub fn layout(self, v: LayoutS) -> Layout<'tcx> { - self.tcx.mk_layout(v) + self.tcx.intern_layout(v) } #[inline] pub fn adt_def_from_data(self, v: AdtDefData) -> AdtDef<'tcx> { - self.tcx.mk_adt_def_from_data(v) + self.tcx.intern_adt_def_from_data(v) } #[inline] @@ -746,6 +746,6 @@ impl<'tcx> MkCtxt<'tcx> { self, v: ExternalConstraintsData<'tcx>, ) -> ExternalConstraints<'tcx> { - self.tcx.mk_external_constraints(v) + self.tcx.intern_external_constraints(v) } } From 82fd36fe93ef8eb29c6fcc758a5056cd197c4263 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 15 Mar 2023 17:51:59 +0000 Subject: [PATCH 7/8] Drive-by cleanup: use `.is_sorted()` instead of implementing it by hand --- compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/ty/context/mk.rs | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 627d07aa1fada..b6a631869612c 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -60,6 +60,7 @@ #![feature(result_option_inspect)] #![feature(const_option)] #![feature(trait_alias)] +#![feature(is_sorted)] #![recursion_limit = "512"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_middle/src/ty/context/mk.rs b/compiler/rustc_middle/src/ty/context/mk.rs index 515f3e18f94ad..c0bd4f724b02b 100644 --- a/compiler/rustc_middle/src/ty/context/mk.rs +++ b/compiler/rustc_middle/src/ty/context/mk.rs @@ -1,6 +1,5 @@ #![allow(rustc::usage_of_ty_tykind)] -use std::cmp::Ordering; use std::iter; use rustc_error_messages::MultiSpan; @@ -547,9 +546,7 @@ impl<'tcx> MkCtxt<'tcx> { ) -> &'tcx List> { assert!(!eps.is_empty()); assert!( - eps.array_windows() - .all(|[a, b]| a.skip_binder().stable_cmp(self.tcx, &b.skip_binder()) - != Ordering::Greater) + eps.is_sorted_by(|a, b| Some(a.skip_binder().stable_cmp(self.tcx, &b.skip_binder()))) ); self.tcx.intern_poly_existential_predicates(eps) } From 902077f72f91011841516dbc6e93399c22a4b474 Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Thu, 16 Mar 2023 00:46:48 +0400 Subject: [PATCH 8/8] Improve documentation of `TyCtxt::mk` a bit Co-authored-by: nils <48135649+Nilstrieb@users.noreply.github.com> --- compiler/rustc_middle/src/ty/context/mk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/context/mk.rs b/compiler/rustc_middle/src/ty/context/mk.rs index c0bd4f724b02b..178f9b64487ad 100644 --- a/compiler/rustc_middle/src/ty/context/mk.rs +++ b/compiler/rustc_middle/src/ty/context/mk.rs @@ -42,7 +42,7 @@ impl<'tcx> TyCtxt<'tcx> { /// /// ```rust,no_run /// # rustc_middle::ty::TyCtxt; - /// let tcx: TyCtxt = todo!(); + /// # let tcx: TyCtxt = todo!(); /// let unit_ty = tcx.mk().unit(); /// ``` #[inline]