Skip to content

Commit 3a762b9

Browse files
committed
remove fresh inference variables from the compiler
1 parent 4d1fc22 commit 3a762b9

File tree

27 files changed

+102
-487
lines changed

27 files changed

+102
-487
lines changed

compiler/rustc_const_eval/src/const_eval/valtrees.rs

-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
140140
ty::Never
141141
| ty::Error(_)
142142
| ty::Foreign(..)
143-
| ty::Infer(ty::FreshIntTy(_))
144-
| ty::Infer(ty::FreshFloatTy(_))
145143
| ty::Projection(..)
146144
| ty::Param(_)
147145
| ty::Bound(..)
@@ -305,8 +303,6 @@ pub fn valtree_to_const_value<'tcx>(
305303
ty::Never
306304
| ty::Error(_)
307305
| ty::Foreign(..)
308-
| ty::Infer(ty::FreshIntTy(_))
309-
| ty::Infer(ty::FreshFloatTy(_))
310306
| ty::Projection(..)
311307
| ty::Param(_)
312308
| ty::Bound(..)

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::infer::InferCtxt;
1313
use rustc_middle::ty::flags::FlagComputation;
1414
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
1515
use rustc_middle::ty::subst::GenericArg;
16-
use rustc_middle::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags};
16+
use rustc_middle::ty::{self, BoundVar, List, Ty, TyCtxt, TypeFlags};
1717
use std::sync::atomic::Ordering;
1818

1919
use rustc_data_structures::fx::FxHashMap;
@@ -416,10 +416,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
416416
t,
417417
),
418418

419-
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
420-
bug!("encountered a fresh type during canonicalization")
421-
}
422-
423419
ty::Placeholder(placeholder) => self.canonicalize_ty_var(
424420
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderTy(placeholder) },
425421
t,
@@ -468,7 +464,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
468464

469465
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
470466
match ct.kind() {
471-
ty::ConstKind::Infer(InferConst::Var(vid)) => {
467+
ty::ConstKind::Infer(vid) => {
472468
debug!("canonical: const var found with vid {:?}", vid);
473469
match self.infcx.probe_const_var(vid) {
474470
Ok(c) => {
@@ -490,9 +486,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
490486
}
491487
}
492488
}
493-
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
494-
bug!("encountered a fresh const during canonicalization")
495-
}
496489
ty::ConstKind::Bound(debruijn, _) => {
497490
if debruijn >= self.binder_index {
498491
bug!("escaping bound type during canonicalization")

compiler/rustc_infer/src/infer/combine.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_middle::traits::ObligationCause;
3737
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3838
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
3939
use rustc_middle::ty::subst::SubstsRef;
40-
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitable};
40+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeVisitable};
4141
use rustc_middle::ty::{IntType, UintType};
4242
use rustc_span::{Span, DUMMY_SP};
4343

@@ -143,25 +143,16 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
143143
let a_is_expected = relation.a_is_expected();
144144

145145
match (a.kind(), b.kind()) {
146-
(
147-
ty::ConstKind::Infer(InferConst::Var(a_vid)),
148-
ty::ConstKind::Infer(InferConst::Var(b_vid)),
149-
) => {
146+
(ty::ConstKind::Infer(a_vid), ty::ConstKind::Infer(b_vid)) => {
150147
self.inner.borrow_mut().const_unification_table().union(a_vid, b_vid);
151148
return Ok(a);
152149
}
153150

154-
// All other cases of inference with other variables are errors.
155-
(ty::ConstKind::Infer(InferConst::Var(_)), ty::ConstKind::Infer(_))
156-
| (ty::ConstKind::Infer(_), ty::ConstKind::Infer(InferConst::Var(_))) => {
157-
bug!("tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var)")
158-
}
159-
160-
(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
151+
(ty::ConstKind::Infer(vid), _) => {
161152
return self.unify_const_variable(relation.param_env(), vid, b, a_is_expected);
162153
}
163154

164-
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
155+
(_, ty::ConstKind::Infer(vid)) => {
165156
return self.unify_const_variable(relation.param_env(), vid, a, !a_is_expected);
166157
}
167158
(ty::ConstKind::Unevaluated(..), _) if self.tcx.lazy_normalization() => {
@@ -712,7 +703,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
712703
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
713704

714705
match c.kind() {
715-
ty::ConstKind::Infer(InferConst::Var(vid)) => {
706+
ty::ConstKind::Infer(vid) => {
716707
let mut inner = self.infcx.inner.borrow_mut();
717708
let variable_table = &mut inner.const_unification_table();
718709
let var_value = variable_table.probe_value(vid);
@@ -729,7 +720,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
729720
origin: var_value.origin,
730721
val: ConstVariableValue::Unknown { universe: self.for_universe },
731722
});
732-
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
723+
Ok(self.tcx().mk_const_infer(new_var_id, c.ty()))
733724
}
734725
}
735726
}
@@ -909,7 +900,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
909900
debug_assert_eq!(c, _c);
910901

911902
match c.kind() {
912-
ty::ConstKind::Infer(InferConst::Var(vid)) => {
903+
ty::ConstKind::Infer(vid) => {
913904
// Check if the current unification would end up
914905
// unifying `target_vid` with a const which contains
915906
// an inference variable which is unioned with `target_vid`.
@@ -942,7 +933,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
942933
},
943934
},
944935
);
945-
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
936+
Ok(self.tcx().mk_const_infer(new_var_id, c.ty()))
946937
}
947938
}
948939
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
574574
match *cause.code() {
575575
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
576576
let ty = self.resolve_vars_if_possible(root_ty);
577-
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
577+
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_)))
578578
{
579579
// don't show type `_`
580580
if span.desugaring_kind() == Some(DesugaringKind::ForLoop)

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::hir::nested_filter;
1616
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
1717
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
1818
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
19-
use rustc_middle::ty::{self, DefIdTree, InferConst};
19+
use rustc_middle::ty::{self, DefIdTree};
2020
use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef};
2121
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
2222
use rustc_span::symbol::{kw, Ident};
@@ -269,7 +269,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
269269
}
270270
}
271271
GenericArgKind::Const(ct) => {
272-
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
272+
if let ty::ConstKind::Infer(vid) = ct.kind() {
273273
let origin =
274274
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
275275
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
@@ -821,9 +821,8 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
821821
}
822822
}
823823
(GenericArgKind::Const(inner_ct), GenericArgKind::Const(target_ct)) => {
824-
use ty::InferConst::*;
825824
match (inner_ct.kind(), target_ct.kind()) {
826-
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => self
825+
(ty::ConstKind::Infer(a_vid), ty::ConstKind::Infer(b_vid)) => self
827826
.infcx
828827
.inner
829828
.borrow_mut()

0 commit comments

Comments
 (0)