1
Fork 0

Move TyCtxt::mk_x to Ty::new_x where applicable

This commit is contained in:
Boxy 2023-07-05 20:13:26 +01:00
parent 5dac6b320b
commit 12138b8e5e
164 changed files with 1386 additions and 1185 deletions

View file

@ -382,7 +382,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> 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 = Ty::new_var(self.infcx.tcx, root_vid);
vid = root_vid;
}
@ -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())
Ty::new_bound(self.tcx, self.binder_index, var.into())
}
}

View file

@ -26,7 +26,7 @@ use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVari
use rustc_index::IndexVec;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::{self, List, TyCtxt};
use rustc_middle::ty::{self, List, Ty, TyCtxt};
use rustc_span::source_map::Span;
pub use rustc_middle::infer::canonical::*;
@ -128,7 +128,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound };
self.tcx.mk_placeholder(placeholder_mapped).into()
Ty::new_placeholder(self.tcx, placeholder_mapped).into()
}
CanonicalVarKind::Region(ui) => self

View file

@ -520,7 +520,7 @@ impl<'tcx> InferCtxt<'tcx> {
self.at(cause, param_env)
.eq(
DefineOpaqueTypes::Yes,
self.tcx.mk_opaque(a.def_id.to_def_id(), a.substs),
Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.substs),
b,
)?
.obligations,

View file

@ -322,8 +322,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(Ty::new_int(self.tcx, v)),
UintType(v) => Ok(Ty::new_uint(self.tcx, v)),
}
}
@ -338,7 +338,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(Ty::new_float(self.tcx, val))
}
}

View file

@ -315,7 +315,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: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
});

View file

@ -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 = Ty::new_opaque(tcx, did, ty::InternalSubsts::identity_for_item(tcx, did));
if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
GenericBound::Outlives(Lifetime {

View file

@ -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)),
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(expected)),
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(found)),
*trait_item_def_id,
);
return Some(guar);

View file

@ -11,7 +11,7 @@ use rustc_errors::{
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{self, IsSuggestable, Region};
use rustc_middle::ty::{self, IsSuggestable, Region, Ty};
use rustc_span::symbol::kw;
use super::ObligationCauseAsDiagArg;
@ -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, Ty::new_param(self.tcx, 0, kw::SelfUpper))
.substs;
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_substs);

View file

@ -188,7 +188,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| Ty::new_fresh(self.infcx.tcx, n)))
}
ty::IntVar(v) => Some(
@ -200,7 +200,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| Ty::new_fresh_int(self.infcx.tcx, n),
),
),
@ -213,7 +213,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| Ty::new_fresh_float(self.infcx.tcx, n),
),
),

View file

@ -277,7 +277,7 @@ where
let origin = *inner.type_variables().var_origin(vid);
let new_var_id =
inner.type_variables().new_var(self.for_universe, origin);
let u = self.tcx().mk_ty_var(new_var_id);
let u = Ty::new_var(self.tcx(), 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

View file

@ -6,7 +6,7 @@ use super::{HigherRankedType, InferCtxt};
use crate::infer::CombinedSnapshot;
use rustc_middle::ty::fold::FnMutDelegate;
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
use rustc_middle::ty::{self, Binder, TyCtxt, TypeFoldable};
use rustc_middle::ty::{self, Binder, Ty, TyCtxt, TypeFoldable};
impl<'a, 'tcx> CombineFields<'a, 'tcx> {
/// Checks whether `for<..> sub <: for<..> sup` holds.
@ -88,10 +88,10 @@ impl<'tcx> InferCtxt<'tcx> {
)
},
types: &mut |bound_ty: ty::BoundTy| {
self.tcx.mk_placeholder(ty::PlaceholderType {
universe: next_universe,
bound: bound_ty,
})
Ty::new_placeholder(
self.tcx,
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
)
},
consts: &mut |bound_var: ty::BoundVar, ty| {
ty::Const::new_placeholder(

View file

@ -725,19 +725,19 @@ impl<'tcx> InferCtxt<'tcx> {
.type_variables()
.unsolved_variables()
.into_iter()
.map(|t| self.tcx.mk_ty_var(t))
.map(|t| Ty::new_var(self.tcx, 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| Ty::new_int_var(self.tcx, 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| Ty::new_float_var(self.tcx, v)),
);
vars
}
@ -978,7 +978,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))
Ty::new_var(self.tcx, self.next_ty_var_id(origin))
}
pub fn next_ty_var_id_in_universe(
@ -995,7 +995,7 @@ 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)
Ty::new_var(self.tcx, vid)
}
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
@ -1028,7 +1028,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
pub fn next_int_var(&self) -> Ty<'tcx> {
self.tcx.mk_int_var(self.next_int_var_id())
Ty::new_int_var(self.tcx, self.next_int_var_id())
}
fn next_float_var_id(&self) -> FloatVid {
@ -1036,7 +1036,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
pub fn next_float_var(&self) -> Ty<'tcx> {
self.tcx.mk_float_var(self.next_float_var_id())
Ty::new_float_var(self.tcx, self.next_float_var_id())
}
/// Creates a fresh region variable with the next available index.
@ -1116,7 +1116,7 @@ impl<'tcx> InferCtxt<'tcx> {
},
);
self.tcx.mk_ty_var(ty_var_id).into()
Ty::new_var(self.tcx, ty_var_id).into()
}
GenericParamDefKind::Const { .. } => {
let origin = ConstVariableOrigin {
@ -1265,7 +1265,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))
Ty::new_int_var(self.tcx, inner.int_unification_table().find(vid))
}
}
@ -1276,7 +1276,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))
Ty::new_float_var(self.tcx, inner.float_unification_table().find(vid))
}
}
@ -1945,13 +1945,16 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
self.idx += 1;
idx
};
self.tcx.mk_placeholder(ty::PlaceholderType {
universe: ty::UniverseIndex::ROOT,
bound: ty::BoundTy {
var: ty::BoundVar::from_u32(idx),
kind: ty::BoundTyKind::Anon,
Ty::new_placeholder(
self.tcx,
ty::PlaceholderType {
universe: ty::UniverseIndex::ROOT,
bound: ty::BoundTy {
var: ty::BoundVar::from_u32(idx),
kind: ty::BoundTyKind::Anon,
},
},
})
)
} else {
t.super_fold_with(self)
}

View file

@ -118,7 +118,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
(&ty::Error(e), _) | (_, &ty::Error(e)) => {
infcx.set_tainted_by_errors(e);
Ok(self.tcx().ty_error(e))
Ok(Ty::new_error(self.tcx(), e))
}
(

View file

@ -3,7 +3,7 @@ use smallvec::smallvec;
use crate::infer::outlives::components::{push_outlives_components, Component};
use crate::traits::{self, Obligation, PredicateObligation};
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_middle::ty::{self, ToPredicate, TyCtxt};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
use rustc_span::symbol::Ident;
use rustc_span::Span;
@ -344,7 +344,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
}
Component::Param(p) => {
let ty = tcx.mk_ty_param(p.index, p.name);
let ty = Ty::new_param(tcx, p.index, p.name);
Some(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, r_min)))
}