From 089de8b73d043b1da697f1865b1dc0d82c6bc8db Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 28 Jul 2025 16:51:35 +1000 Subject: [PATCH] Remove indices from fresh ty/const vars. Each of `InferTy::Fresh{Ty,IntTy,FloatTy}` and `InferConst::Fresh` have a `u32` index. It turns out the index is only used for some weak sanity checking during freshening and can be removed, making these values a bit like `ReErased`. This change simplifies things quite a bit, e.g. `TypeFreshener` no longers needs maps, and we can eliminate a bunch of pre-interned fresh types. --- .../src/const_eval/valtrees.rs | 8 +- .../rustc_const_eval/src/interpret/stack.rs | 3 +- compiler/rustc_hir_typeck/src/demand.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 4 +- compiler/rustc_infer/src/infer/context.rs | 8 +- compiler/rustc_infer/src/infer/freshen.rs | 135 ++++-------------- compiler/rustc_infer/src/infer/mod.rs | 8 +- .../src/infer/relate/generalize.rs | 2 +- compiler/rustc_infer/src/infer/resolve.rs | 2 +- .../rustc_infer/src/infer/snapshot/fudge.rs | 4 +- compiler/rustc_middle/src/ty/consts.rs | 5 - compiler/rustc_middle/src/ty/context.rs | 40 +++--- compiler/rustc_middle/src/ty/diagnostics.rs | 8 +- compiler/rustc_middle/src/ty/error.rs | 6 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 42 +----- compiler/rustc_middle/src/ty/util.rs | 4 +- .../src/canonicalizer.rs | 4 +- .../src/solve/assembly/mod.rs | 4 +- .../src/solve/assembly/structural_traits.rs | 12 +- .../src/solve/normalizes_to/mod.rs | 4 +- .../src/solve/trait_goals.rs | 4 +- compiler/rustc_symbol_mangling/src/v0.rs | 2 +- .../src/error_reporting/infer/mod.rs | 2 +- .../src/traits/effects.rs | 2 +- .../src/traits/fulfill.rs | 2 +- .../src/traits/query/dropck_outlives.rs | 4 +- .../src/traits/select/_match.rs | 6 +- .../src/traits/select/candidate_assembly.rs | 14 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 6 +- compiler/rustc_type_ir/src/const_kind.rs | 12 +- compiler/rustc_type_ir/src/flags.rs | 4 +- compiler/rustc_type_ir/src/relate/combine.rs | 4 +- compiler/rustc_type_ir/src/ty_kind.rs | 20 +-- .../direct-use-of-rustc-type-ir.rs | 2 +- .../direct-use-of-rustc-type-ir.stderr | 2 +- 37 files changed, 133 insertions(+), 262 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 37c6c4a61d8d6..d6ec430f3603b 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -164,8 +164,8 @@ fn const_to_valtree_inner<'tcx>( ty::Never | ty::Error(_) | ty::Foreign(..) - | ty::Infer(ty::FreshIntTy(_)) - | ty::Infer(ty::FreshFloatTy(_)) + | ty::Infer(ty::FreshIntTy) + | ty::Infer(ty::FreshFloatTy) // FIXME(oli-obk): we could look behind opaque types | ty::Alias(..) | ty::Param(_) @@ -326,8 +326,8 @@ pub fn valtree_to_const_value<'tcx>( ty::Never | ty::Error(_) | ty::Foreign(..) - | ty::Infer(ty::FreshIntTy(_)) - | ty::Infer(ty::FreshFloatTy(_)) + | ty::Infer(ty::FreshIntTy) + | ty::Infer(ty::FreshFloatTy) | ty::Alias(..) | ty::Param(_) | ty::Bound(..) diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 2e99bb4209f2b..082767112f201 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -521,8 +521,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ty::Infer(ty::TyVar(_)) => false, - ty::Bound(..) - | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Bound(..) | ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("`is_very_trivially_sized` applied to unexpected type: {}", ty) } } diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e5684f8cbe669..99c8e7166cd3c 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -347,7 +347,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::TyVar(_) => self.next_ty_var(DUMMY_SP), ty::IntVar(_) => self.next_int_var(), ty::FloatVar(_) => self.next_float_var(), - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => { + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => { bug!("unexpected fresh ty outside of the trait solver") } } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 060447ba72068..89298ba51089f 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -386,7 +386,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { } } - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("encountered a fresh type during canonicalization") } @@ -470,7 +470,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { } } } - ty::ConstKind::Infer(InferConst::Fresh(_)) => { + ty::ConstKind::Infer(InferConst::Fresh) => { bug!("encountered a fresh const during canonicalization") } ty::ConstKind::Bound(debruijn, _) => { diff --git a/compiler/rustc_infer/src/infer/context.rs b/compiler/rustc_infer/src/infer/context.rs index bb9c88500936f..8cee243497b8f 100644 --- a/compiler/rustc_infer/src/infer/context.rs +++ b/compiler/rustc_infer/src/infer/context.rs @@ -117,9 +117,9 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> { if inner.float_unification_table().find(vid) == vid ) } - ty::InferTy::FreshTy(_) - | ty::InferTy::FreshIntTy(_) - | ty::InferTy::FreshFloatTy(_) => true, + ty::InferTy::FreshTy + | ty::InferTy::FreshIntTy + | ty::InferTy::FreshFloatTy => true, } } else { true @@ -131,7 +131,7 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> { ty::InferConst::Var(vid) => !self .probe_const_var(vid) .is_err_and(|_| self.root_const_var(vid) == vid), - ty::InferConst::Fresh(_) => true, + ty::InferConst::Fresh => true, } } else { true diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index ddc0b11680627..5393d715df74b 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -31,9 +31,6 @@ //! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type //! inferencer knows "so far". -use std::collections::hash_map::Entry; - -use rustc_data_structures::fx::FxHashMap; use rustc_middle::bug; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, @@ -43,63 +40,11 @@ use super::InferCtxt; pub struct TypeFreshener<'a, 'tcx> { infcx: &'a InferCtxt<'tcx>, - ty_freshen_count: u32, - const_freshen_count: u32, - ty_freshen_map: FxHashMap>, - const_freshen_map: FxHashMap>, } impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { pub fn new(infcx: &'a InferCtxt<'tcx>) -> TypeFreshener<'a, 'tcx> { - TypeFreshener { - infcx, - ty_freshen_count: 0, - const_freshen_count: 0, - ty_freshen_map: Default::default(), - const_freshen_map: Default::default(), - } - } - - fn freshen_ty(&mut self, input: Result, ty::InferTy>, mk_fresh: F) -> Ty<'tcx> - where - F: FnOnce(u32) -> Ty<'tcx>, - { - match input { - Ok(ty) => ty.fold_with(self), - Err(key) => match self.ty_freshen_map.entry(key) { - Entry::Occupied(entry) => *entry.get(), - Entry::Vacant(entry) => { - let index = self.ty_freshen_count; - self.ty_freshen_count += 1; - let t = mk_fresh(index); - entry.insert(t); - t - } - }, - } - } - - fn freshen_const( - &mut self, - input: Result, ty::InferConst>, - freshener: F, - ) -> ty::Const<'tcx> - where - F: FnOnce(u32) -> ty::InferConst, - { - match input { - Ok(ct) => ct.fold_with(self), - Err(key) => match self.const_freshen_map.entry(key) { - Entry::Occupied(entry) => *entry.get(), - Entry::Vacant(entry) => { - let index = self.const_freshen_count; - self.const_freshen_count += 1; - let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index)); - entry.insert(ct); - ct - } - }, - } + TypeFreshener { infcx } } } @@ -145,25 +90,14 @@ impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { match ct.kind() { ty::ConstKind::Infer(ty::InferConst::Var(v)) => { - let mut inner = self.infcx.inner.borrow_mut(); let input = - inner.const_unification_table().probe_value(v).known().ok_or_else(|| { - ty::InferConst::Var(inner.const_unification_table().find(v).vid) - }); - drop(inner); - self.freshen_const(input, ty::InferConst::Fresh) - } - ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => { - if i >= self.const_freshen_count { - bug!( - "Encountered a freshend const with id {} \ - but our counter is only at {}", - i, - self.const_freshen_count, - ); + self.infcx.inner.borrow_mut().const_unification_table().probe_value(v).known(); + match input { + Some(ct) => ct.fold_with(self), + None => self.infcx.tcx.consts.fresh_const, } - ct } + ty::ConstKind::Infer(ty::InferConst::Fresh) => ct, ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => { bug!("unexpected const {:?}", ct) @@ -184,54 +118,35 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> { fn fold_infer_ty(&mut self, v: ty::InferTy) -> Option> { match v { ty::TyVar(v) => { - let mut inner = self.infcx.inner.borrow_mut(); - let input = inner - .type_variables() - .probe(v) - .known() - .ok_or_else(|| ty::TyVar(inner.type_variables().root_var(v))); - drop(inner); - Some(self.freshen_ty(input, |n| Ty::new_fresh(self.infcx.tcx, n))) + let value = self.infcx.inner.borrow_mut().type_variables().probe(v).known(); + Some(match value { + Some(ty) => ty.fold_with(self), + None => self.infcx.tcx.types.fresh_ty, + }) } ty::IntVar(v) => { - let mut inner = self.infcx.inner.borrow_mut(); - let value = inner.int_unification_table().probe_value(v); - let input = match value { - ty::IntVarValue::IntType(ty) => Ok(Ty::new_int(self.infcx.tcx, ty)), - ty::IntVarValue::UintType(ty) => Ok(Ty::new_uint(self.infcx.tcx, ty)), - ty::IntVarValue::Unknown => { - Err(ty::IntVar(inner.int_unification_table().find(v))) + let value = self.infcx.inner.borrow_mut().int_unification_table().probe_value(v); + Some(match value { + ty::IntVarValue::IntType(ty) => Ty::new_int(self.infcx.tcx, ty).fold_with(self), + ty::IntVarValue::UintType(ty) => { + Ty::new_uint(self.infcx.tcx, ty).fold_with(self) } - }; - drop(inner); - Some(self.freshen_ty(input, |n| Ty::new_fresh_int(self.infcx.tcx, n))) + ty::IntVarValue::Unknown => self.infcx.tcx.types.fresh_int_ty, + }) } ty::FloatVar(v) => { - let mut inner = self.infcx.inner.borrow_mut(); - let value = inner.float_unification_table().probe_value(v); - let input = match value { - ty::FloatVarValue::Known(ty) => Ok(Ty::new_float(self.infcx.tcx, ty)), - ty::FloatVarValue::Unknown => { - Err(ty::FloatVar(inner.float_unification_table().find(v))) + let value = self.infcx.inner.borrow_mut().float_unification_table().probe_value(v); + Some(match value { + ty::FloatVarValue::Known(ty) => { + Ty::new_float(self.infcx.tcx, ty).fold_with(self) } - }; - drop(inner); - Some(self.freshen_ty(input, |n| Ty::new_fresh_float(self.infcx.tcx, n))) + ty::FloatVarValue::Unknown => self.infcx.tcx.types.fresh_float_ty, + }) } - ty::FreshTy(ct) | ty::FreshIntTy(ct) | ty::FreshFloatTy(ct) => { - if ct >= self.ty_freshen_count { - bug!( - "Encountered a freshend type with id {} \ - but our counter is only at {}", - ct, - self.ty_freshen_count - ); - } - None - } + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => None, } } } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 2d269e320b64d..d924192d753a7 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1028,7 +1028,7 @@ impl<'tcx> InferCtxt<'tcx> { } } - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => ty, + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => ty, } } else { ty @@ -1045,7 +1045,7 @@ impl<'tcx> InferCtxt<'tcx> { .probe_value(vid) .known() .unwrap_or(ct), - InferConst::Fresh(_) => ct, + InferConst::Fresh => ct, }, ty::ConstKind::Param(_) | ty::ConstKind::Bound(_, _) @@ -1448,8 +1448,8 @@ impl<'tcx> TypeFolder> for InferenceLiteralEraser<'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { match ty.kind() { - ty::Infer(ty::IntVar(_) | ty::FreshIntTy(_)) => self.tcx.types.i32, - ty::Infer(ty::FloatVar(_) | ty::FreshFloatTy(_)) => self.tcx.types.f64, + ty::Infer(ty::IntVar(_) | ty::FreshIntTy) => self.tcx.types.i32, + ty::Infer(ty::FloatVar(_) | ty::FreshFloatTy) => self.tcx.types.f64, _ => ty.super_fold_with(self), } } diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index 9e451f16a9d8b..ff4228be98912 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -462,7 +462,7 @@ impl<'tcx> TypeRelation> for Generalizer<'_, 'tcx> { // subtyping. This is basically our "occurs check", preventing // us from creating infinitely sized types. let g = match *t.kind() { - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("unexpected infer type: {t}") } diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 13df23a39b967..450a9b691fe4d 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -186,7 +186,7 @@ impl<'a, 'tcx> FallibleTypeFolder> for FullTypeResolver<'a, 'tcx> { ty::ConstKind::Infer(InferConst::Var(vid)) => { return Err(FixupError { unresolved: super::TyOrConstInferVar::Const(vid) }); } - ty::ConstKind::Infer(InferConst::Fresh(_)) => { + ty::ConstKind::Infer(InferConst::Fresh) => { bug!("Unexpected const in full const resolver: {:?}", c); } _ => {} diff --git a/compiler/rustc_infer/src/infer/snapshot/fudge.rs b/compiler/rustc_infer/src/infer/snapshot/fudge.rs index e210479581ba6..85111ac03ce75 100644 --- a/compiler/rustc_infer/src/infer/snapshot/fudge.rs +++ b/compiler/rustc_infer/src/infer/snapshot/fudge.rs @@ -207,7 +207,7 @@ impl<'a, 'tcx> TypeFolder> for InferenceFudger<'a, 'tcx> { ty } } - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => { + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => { unreachable!("unexpected fresh infcx var") } } @@ -244,7 +244,7 @@ impl<'a, 'tcx> TypeFolder> for InferenceFudger<'a, 'tcx> { ct } } - ty::InferConst::Fresh(_) => { + ty::InferConst::Fresh => { unreachable!("unexpected fresh infcx var") } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index fd1aa4042bcfd..108df9c3de55c 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -79,11 +79,6 @@ impl<'tcx> Const<'tcx> { Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Var(infer))) } - #[inline] - pub fn new_fresh(tcx: TyCtxt<'tcx>, fresh: u32) -> Const<'tcx> { - Const::new(tcx, ty::ConstKind::Infer(ty::InferConst::Fresh(fresh))) - } - #[inline] pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst) -> Const<'tcx> { Const::new(tcx, ty::ConstKind::Infer(infer)) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6f21160d1f66e..cdfdc72feb06f 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -613,7 +613,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ty::CoroutineWitness(..) => (), // These variants should not exist as a self type. - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Param(_) | ty::Bound(_, _) => bug!("unexpected self type: {self_ty}"), } @@ -1038,9 +1038,6 @@ impl<'tcx> CtxtInterners<'tcx> { // slightly more complex and no faster. const NUM_PREINTERNED_TY_VARS: u32 = 100; -const NUM_PREINTERNED_FRESH_TYS: u32 = 20; -const NUM_PREINTERNED_FRESH_INT_TYS: u32 = 3; -const NUM_PREINTERNED_FRESH_FLOAT_TYS: u32 = 3; const NUM_PREINTERNED_ANON_BOUND_TYS_I: u32 = 3; const NUM_PREINTERNED_ANON_BOUND_TYS_V: u32 = 20; @@ -1076,20 +1073,20 @@ pub struct CommonTypes<'tcx> { /// Dummy type used for the `Self` of a `TraitRef` created for converting /// a trait object, and which gets removed in `ExistentialTraitRef`. /// This type must not appear anywhere in other converted types. - /// `Infer(ty::FreshTy(0))` does the job. + /// `Infer(ty::FreshTy)` does the job. pub trait_object_dummy_self: Ty<'tcx>, /// Pre-interned `Infer(ty::TyVar(n))` for small values of `n`. pub ty_vars: Vec>, - /// Pre-interned `Infer(ty::FreshTy(n))` for small values of `n`. - pub fresh_tys: Vec>, + /// Pre-interned `Infer(ty::FreshTy)`. + pub fresh_ty: Ty<'tcx>, - /// Pre-interned `Infer(ty::FreshIntTy(n))` for small values of `n`. - pub fresh_int_tys: Vec>, + /// Pre-interned `Infer(ty::FreshIntTy)`. + pub fresh_int_ty: Ty<'tcx>, - /// Pre-interned `Infer(ty::FreshFloatTy(n))` for small values of `n`. - pub fresh_float_tys: Vec>, + /// Pre-interned `Infer(ty::FreshFloatTy)`. + pub fresh_float_ty: Ty<'tcx>, /// Pre-interned values of the form: /// `Bound(DebruijnIndex(i), BoundTy { var: v, kind: BoundTyKind::Anon})` @@ -1117,6 +1114,9 @@ pub struct CommonConsts<'tcx> { pub unit: Const<'tcx>, pub true_: Const<'tcx>, pub false_: Const<'tcx>, + + pub fresh_const: Const<'tcx>, + /// Use [`ty::ValTree::zst`] instead. pub(crate) valtree_zst: ValTree<'tcx>, } @@ -1131,12 +1131,9 @@ impl<'tcx> CommonTypes<'tcx> { let ty_vars = (0..NUM_PREINTERNED_TY_VARS).map(|n| mk(Infer(ty::TyVar(TyVid::from(n))))).collect(); - let fresh_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_TYS).map(|n| mk(Infer(ty::FreshTy(n)))).collect(); - let fresh_int_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_INT_TYS).map(|n| mk(Infer(ty::FreshIntTy(n)))).collect(); - let fresh_float_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_FLOAT_TYS).map(|n| mk(Infer(ty::FreshFloatTy(n)))).collect(); + let fresh_ty = mk(Infer(ty::FreshTy)); + let fresh_int_ty = mk(Infer(ty::FreshIntTy)); + let fresh_float_ty = mk(Infer(ty::FreshFloatTy)); let anon_bound_tys = (0..NUM_PREINTERNED_ANON_BOUND_TYS_I) .map(|i| { @@ -1175,12 +1172,12 @@ impl<'tcx> CommonTypes<'tcx> { str_: mk(Str), self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })), - trait_object_dummy_self: fresh_tys[0], + trait_object_dummy_self: fresh_ty, ty_vars, - fresh_tys, - fresh_int_tys, - fresh_float_tys, + fresh_ty, + fresh_int_ty, + fresh_float_ty, anon_bound_tys, } } @@ -1259,6 +1256,7 @@ impl<'tcx> CommonConsts<'tcx> { ty: types.bool, valtree: valtree_false, })), + fresh_const: mk_const(ty::ConstKind::Infer(ty::InferConst::Fresh)), valtree_zst, } } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index b122ada0925d6..1dcfdab6f2ffb 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -45,8 +45,8 @@ impl<'tcx> Ty<'tcx> { | Infer( InferTy::IntVar(_) | InferTy::FloatVar(_) - | InferTy::FreshIntTy(_) - | InferTy::FreshFloatTy(_) + | InferTy::FreshIntTy + | InferTy::FreshFloatTy ) ) } @@ -64,8 +64,8 @@ impl<'tcx> Ty<'tcx> { | Infer( InferTy::IntVar(_) | InferTy::FloatVar(_) - | InferTy::FreshIntTy(_) - | InferTy::FreshFloatTy(_), + | InferTy::FreshIntTy + | InferTy::FreshFloatTy, ) => true, Ref(_, x, _) | Array(x, _) | Slice(x) => x.peel_refs().is_simple_ty(), Tuple(tys) if tys.is_empty() => true, diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 13723874ad3a1..a92dfaee53474 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -144,9 +144,9 @@ impl<'tcx> Ty<'tcx> { ty::Infer(ty::FloatVar(_)) => "floating-point number".into(), ty::Placeholder(..) => "placeholder type".into(), ty::Bound(..) => "bound type".into(), - ty::Infer(ty::FreshTy(_)) => "fresh type".into(), - ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), - ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), + ty::Infer(ty::FreshTy) => "fresh type".into(), + ty::Infer(ty::FreshIntTy) => "fresh integral type".into(), + ty::Infer(ty::FreshFloatTy) => "fresh floating-point type".into(), ty::Alias(ty::Projection | ty::Inherent, _) => "associated type".into(), ty::Param(p) => format!("type parameter `{p}`").into(), ty::Alias(ty::Opaque, ..) => { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index fd4472e1f9658..80d0b0eab139c 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -3248,7 +3248,7 @@ define_print! { ty::ExistentialTraitRef<'tcx> { // Use a type that can't appear in defaults of type parameters. - let dummy_self = Ty::new_fresh(cx.tcx(), 0); + let dummy_self = cx.tcx().types.fresh_ty; 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/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 4569596cfbe83..21d06b175c98c 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -444,36 +444,6 @@ impl<'tcx> Ty<'tcx> { Ty::new_infer(tcx, FloatVar(v)) } - #[inline] - pub fn new_fresh(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - tcx.types - .fresh_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshTy(n))) - } - - #[inline] - pub fn new_fresh_int(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - tcx.types - .fresh_int_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshIntTy(n))) - } - - #[inline] - pub fn new_fresh_float(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { - // Use a pre-interned one when possible. - tcx.types - .fresh_float_tys - .get(n as usize) - .copied() - .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshFloatTy(n))) - } - #[inline] pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> { Ty::new(tcx, Param(ParamTy { index, name })) @@ -1361,12 +1331,12 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn is_fresh_ty(self) -> bool { - matches!(self.kind(), Infer(FreshTy(_))) + matches!(self.kind(), Infer(FreshTy)) } #[inline] pub fn is_fresh(self) -> bool { - matches!(self.kind(), Infer(FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_))) + matches!(self.kind(), Infer(FreshTy | FreshIntTy | FreshFloatTy)) } #[inline] @@ -1597,7 +1567,7 @@ impl<'tcx> Ty<'tcx> { ty::Bound(..) | ty::Placeholder(_) - | ty::Infer(FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("`discriminant_ty` applied to unexpected type: {:?}", self) } } @@ -1656,7 +1626,7 @@ impl<'tcx> Ty<'tcx> { | ty::Pat(..) | ty::Bound(..) | ty::Placeholder(..) - | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!( + | ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => bug!( "`ptr_metadata_ty_or_tail` applied to unexpected type: {self:?} (tail = {tail:?})" ), } @@ -1842,7 +1812,7 @@ impl<'tcx> Ty<'tcx> { ty::Infer(ty::TyVar(_)) => false, - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("`has_trivial_sizedness` applied to unexpected type: {:?}", self) } } @@ -1933,7 +1903,7 @@ impl<'tcx> Ty<'tcx> { ty::Infer(infer) => match infer { ty::TyVar(_) => false, ty::IntVar(_) | ty::FloatVar(_) => true, - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => true, + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => true, }, ty::Adt(_, _) diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 174892c6f4d2c..a1c525d56ad84 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1495,8 +1495,8 @@ pub fn needs_drop_components_with_async<'tcx>( asyncness: Asyncness, ) -> Result; 2]>, AlwaysRequiresDrop> { match *ty.kind() { - ty::Infer(ty::FreshIntTy(_)) - | ty::Infer(ty::FreshFloatTy(_)) + ty::Infer(ty::FreshIntTy) + | ty::Infer(ty::FreshFloatTy) | ty::Bool | ty::Int(_) | ty::Uint(_) diff --git a/compiler/rustc_next_trait_solver/src/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonicalizer.rs index a418aa82100c4..347923f36d2ce 100644 --- a/compiler/rustc_next_trait_solver/src/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonicalizer.rs @@ -335,7 +335,7 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { ); CanonicalVarKind::Ty(CanonicalTyVarKind::Float) } - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => { + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => { panic!("fresh vars not expected in canonicalization") } }, @@ -504,7 +504,7 @@ impl, I: Interner> TypeFolder for Canonicaliz } } } - ty::InferConst::Fresh(_) => todo!(), + ty::InferConst::Fresh => todo!(), }, ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode { CanonicalizeMode::Input { .. } => CanonicalVarKind::PlaceholderConst( diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index b2d4014634855..33833b85703b1 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -629,7 +629,7 @@ where | ty::Placeholder(..) | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Error(_) => return, - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | ty::Bound(..) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Bound(..) => { panic!("unexpected self type for `{goal:?}`") } @@ -743,7 +743,7 @@ where | ty::Placeholder(..) | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Error(_) => return, - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Bound(..) => panic!("unexpected self type for `{goal:?}`"), ty::Dynamic(bounds, ..) => bounds, }; diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index c0bebdf6fb639..04e2942e1d6c4 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -149,7 +149,7 @@ where ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => Err(NoSolution), ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{ty:?}`") } @@ -223,7 +223,7 @@ where | ty::Placeholder(..) => Err(NoSolution), ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{ty:?}`") } @@ -395,7 +395,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable Err(NoSolution), ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } } @@ -568,7 +568,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable Err(NoSolution), ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } } @@ -718,7 +718,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable( | ty::UnsafeBinder(_) => return Err(NoSolution), ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } } @@ -799,7 +799,7 @@ pub(in crate::solve) fn const_conditions_for_destruct( } ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 1e0a90eb2eefe..cb108d7463cbe 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -716,7 +716,7 @@ where todo!() } - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Bound(..) => panic!( "unexpected self ty `{:?}` when normalizing `::Metadata`", goal.predicate.self_ty() @@ -934,7 +934,7 @@ where }); } - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Bound(..) => panic!( "unexpected self ty `{:?}` when normalizing `::Discriminant`", goal.predicate.self_ty() diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 650b85d99d2cd..1c0ae79f27c69 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -754,9 +754,7 @@ where } ty::Bound(..) - | ty::Infer( - ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_), - ) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{ty:?}`") } } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index fe0f8e6113ef7..850bc96f7b707 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -632,7 +632,7 @@ impl<'tcx> Printer<'tcx> for 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 = Ty::new_fresh(cx.tcx, 0); + let dummy_self = cx.tcx().types.fresh_ty; let trait_ref = trait_ref.with_self_ty(cx.tcx, dummy_self); cx.print_def_path(trait_ref.def_id, trait_ref.args)?; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index b9acadc406e9c..d35fde11f67b3 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -446,7 +446,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let expected_ty = self.resolve_vars_if_possible(root_ty); if !matches!( expected_ty.kind(), - ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) + ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy) ) { // don't show type `_` if span.desugaring_kind() == Some(DesugaringKind::ForLoop) diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index d694a092853af..0d767234434d7 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -385,7 +385,7 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>( } ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } }; diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 6b884b3608044..3a72d6009e1f1 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -511,7 +511,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { ty::ConstKind::Infer(var) => { let var = match var { ty::InferConst::Var(vid) => TyOrConstInferVar::Const(vid), - ty::InferConst::Fresh(_) => { + ty::InferConst::Fresh => { bug!("encountered fresh const in fulfill") } }; diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 38cfdcdc22d33..72f6040c05677 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -28,8 +28,8 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { // None of these types have a destructor and hence they do not // require anything in particular to outlive the dtor's // execution. - ty::Infer(ty::FreshIntTy(_)) - | ty::Infer(ty::FreshFloatTy(_)) + ty::Infer(ty::FreshIntTy) + | ty::Infer(ty::FreshFloatTy) | ty::Bool | ty::Int(_) | ty::Uint(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/_match.rs b/compiler/rustc_trait_selection/src/traits/select/_match.rs index 7c19c35a4f784..a6c050c890153 100644 --- a/compiler/rustc_trait_selection/src/traits/select/_match.rs +++ b/compiler/rustc_trait_selection/src/traits/select/_match.rs @@ -64,9 +64,7 @@ impl<'tcx> TypeRelation> for MatchAgainstFreshVars<'tcx> { match (a.kind(), b.kind()) { ( _, - &ty::Infer(ty::FreshTy(_)) - | &ty::Infer(ty::FreshIntTy(_)) - | &ty::Infer(ty::FreshFloatTy(_)), + &ty::Infer(ty::FreshTy) | &ty::Infer(ty::FreshIntTy) | &ty::Infer(ty::FreshFloatTy), ) => Ok(a), (&ty::Infer(_), _) | (_, &ty::Infer(_)) => { @@ -90,7 +88,7 @@ impl<'tcx> TypeRelation> for MatchAgainstFreshVars<'tcx> { } match (a.kind(), b.kind()) { - (_, ty::ConstKind::Infer(InferConst::Fresh(_))) => { + (_, ty::ConstKind::Infer(InferConst::Fresh)) => { return Ok(a); } 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 2c7089507a897..6aaa75d310639 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -810,7 +810,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!( "asked to assemble auto trait candidates of unexpected type: {:?}", self_ty @@ -1212,7 +1212,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Only appears when assembling higher-ranked `for T: Clone`. ty::Bound(..) => {} - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty); } } @@ -1280,7 +1280,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Only appears when assembling higher-ranked `for T: Sized`. ty::Bound(..) => {} - ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty); } } @@ -1377,10 +1377,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Infer( ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(_) - | ty::InferTy::FreshIntTy(_) - | ty::InferTy::FreshFloatTy(_), + | ty::InferTy::FreshIntTy + | ty::InferTy::FreshFloatTy, ) => {} - ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => { + ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy) => { candidates.ambiguous = true; } } @@ -1424,7 +1424,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { candidates.vec.push(BikeshedGuaranteedNoDropCandidate); } - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { candidates.ambiguous = true; } } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 488094b15ac60..c9b77e5850ac5 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -1321,7 +1321,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { )); } - ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { panic!("unexpected type `{self_ty:?}`") } } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index f90316f520b3e..082ab7628de84 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2150,7 +2150,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) | ty::Bound(..) => { bug!("asked to assemble `Sized` of unexpected type: {:?}", self_ty); } @@ -2234,7 +2234,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ty::Placeholder(..) | ty::Bound(..) | ty::Ref(_, _, ty::Mutability::Mut) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("asked to assemble builtin bounds of unexpected type: {:?}", self_ty); } } @@ -2297,7 +2297,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ty::Param(..) | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..) | ty::Bound(..) - | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + | ty::Infer(ty::TyVar(_) | ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy) => { bug!("asked to assemble constituent types of unexpected type: {:?}", t); } diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 70a8509b51339..c06f5f4c56887 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -97,26 +97,24 @@ pub enum InferConst { /// Infer the value of the const. Var(ConstVid), /// A fresh const variable. See `infer::freshen` for more details. - Fresh(u32), + Fresh, } impl fmt::Debug for InferConst { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { InferConst::Var(var) => write!(f, "{var:?}"), - InferConst::Fresh(var) => write!(f, "Fresh({var:?})"), + InferConst::Fresh => write!(f, "Fresh"), } } } #[cfg(feature = "nightly")] impl HashStable for InferConst { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + fn hash_stable(&self, _hcx: &mut CTX, _hasher: &mut StableHasher) { match self { - InferConst::Var(_) => { - panic!("const variables should not be hashed: {self:?}") - } - InferConst::Fresh(i) => i.hash_stable(hcx, hasher), + InferConst::Var(_) => panic!("const variables should not be hashed: {self:?}"), + InferConst::Fresh => {} } } } diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index d7b9e0ca340ac..33ffd27280fa5 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -265,7 +265,7 @@ impl FlagComputation { } ty::Infer(infer) => match infer { - ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => { + ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy => { self.add_flags(TypeFlags::HAS_TY_FRESH) } @@ -452,7 +452,7 @@ impl FlagComputation { self.add_flags(TypeFlags::HAS_CT_PROJECTION); } ty::ConstKind::Infer(infer) => match infer { - ty::InferConst::Fresh(_) => self.add_flags(TypeFlags::HAS_CT_FRESH), + ty::InferConst::Fresh => self.add_flags(TypeFlags::HAS_CT_FRESH), ty::InferConst::Var(_) => self.add_flags(TypeFlags::HAS_CT_INFER), }, ty::ConstKind::Bound(debruijn, _) => { diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index 8dd7c4df24421..932925bcea9df 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -105,8 +105,8 @@ where -- they should have been handled earlier" ) } - (_, ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))) - | (ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)), _) + (_, ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy)) + | (ty::Infer(ty::FreshTy | ty::FreshIntTy | ty::FreshFloatTy), _) if infcx.next_trait_solver() => { panic!("We do not expect to encounter `Fresh` variables in the new solver") diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 7c66542475050..a85eb9431d49a 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -759,11 +759,11 @@ pub enum InferTy { /// `rustc_infer::infer::freshen` for more details. /// /// Compare with [`TyVar`][Self::TyVar]. - FreshTy(u32), + FreshTy, /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar]. - FreshIntTy(u32), + FreshIntTy, /// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar]. - FreshFloatTy(u32), + FreshFloatTy, } impl UnifyValue for IntVarValue { @@ -841,7 +841,7 @@ impl HashStable for InferTy { TyVar(_) | IntVar(_) | FloatVar(_) => { panic!("type variables should not be hashed: {self:?}") } - FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher), + FreshTy | FreshIntTy | FreshFloatTy => {} } } } @@ -853,9 +853,9 @@ impl fmt::Display for InferTy { TyVar(_) => write!(f, "_"), IntVar(_) => write!(f, "{}", "{integer}"), FloatVar(_) => write!(f, "{}", "{float}"), - FreshTy(v) => write!(f, "FreshTy({v})"), - FreshIntTy(v) => write!(f, "FreshIntTy({v})"), - FreshFloatTy(v) => write!(f, "FreshFloatTy({v})"), + FreshTy => write!(f, "FreshTy"), + FreshIntTy => write!(f, "FreshIntTy"), + FreshFloatTy => write!(f, "FreshFloatTy"), } } } @@ -885,9 +885,9 @@ impl fmt::Debug for InferTy { TyVar(ref v) => v.fmt(f), IntVar(ref v) => v.fmt(f), FloatVar(ref v) => v.fmt(f), - FreshTy(v) => write!(f, "FreshTy({v:?})"), - FreshIntTy(v) => write!(f, "FreshIntTy({v:?})"), - FreshFloatTy(v) => write!(f, "FreshFloatTy({v:?})"), + FreshTy => write!(f, "FreshTy"), + FreshIntTy => write!(f, "FreshIntTy"), + FreshFloatTy => write!(f, "FreshFloatTy"), } } } diff --git a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs index 5c68df4e1e4a8..0038dce7c01c6 100644 --- a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs +++ b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.rs @@ -19,7 +19,7 @@ fn foo(cx: I, did: I::DefId) { } fn main() { - let _ = rustc_type_ir::InferConst::Fresh(42); + let _ = rustc_type_ir::InferConst::Fresh; //~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals let _: rustc_type_ir::InferConst; //~^ ERROR: do not use `rustc_type_ir` unless you are implementing type system internals diff --git a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr index d1716494d52e6..a1bdedc401a06 100644 --- a/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr +++ b/tests/ui-fulldeps/internal-lints/direct-use-of-rustc-type-ir.stderr @@ -22,7 +22,7 @@ LL | fn foo(cx: I, did: I::DefId) { error: do not use `rustc_type_ir` unless you are implementing type system internals --> $DIR/direct-use-of-rustc-type-ir.rs:22:13 | -LL | let _ = rustc_type_ir::InferConst::Fresh(42); +LL | let _ = rustc_type_ir::InferConst::Fresh; | ^^^^^^^^^^^^^ | = note: use `rustc_middle::ty` instead