Skip to content

Commit bc2ece2

Browse files
nikomatsakisMark-Simulacrum
authored andcommitted
stop categorizing inference variables as diverging when created
Instead, we now rely on the code that looks for a NeverToAny adjustment.
1 parent 1c004f2 commit bc2ece2

File tree

5 files changed

+17
-63
lines changed

5 files changed

+17
-63
lines changed

compiler/rustc_infer/src/infer/combine.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
// is also useful to track which value is the "expected" value in
2323
// terms of error reporting.
2424

25+
use super::equate::Equate;
2526
use super::glb::Glb;
2627
use super::lub::Lub;
2728
use super::sub::Sub;
2829
use super::type_variable::TypeVariableValue;
2930
use super::unify_key::replace_if_possible;
3031
use super::unify_key::{ConstVarValue, ConstVariableValue};
3132
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
32-
use super::{equate::Equate, type_variable::Diverging};
3333
use super::{InferCtxt, MiscVariable, TypeTrace};
3434

3535
use crate::traits::{Obligation, PredicateObligations};
@@ -645,7 +645,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
645645
.inner
646646
.borrow_mut()
647647
.type_variables()
648-
.new_var(self.for_universe, Diverging::NotDiverging, origin);
648+
.new_var(self.for_universe, origin);
649649
let u = self.tcx().mk_ty_var(new_var_id);
650650

651651
// Record that we replaced `vid` with `new_var_id` as part of a generalization
@@ -885,11 +885,12 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
885885

886886
let origin =
887887
*self.infcx.inner.borrow_mut().type_variables().var_origin(vid);
888-
let new_var_id = self.infcx.inner.borrow_mut().type_variables().new_var(
889-
self.for_universe,
890-
Diverging::NotDiverging,
891-
origin,
892-
);
888+
let new_var_id = self
889+
.infcx
890+
.inner
891+
.borrow_mut()
892+
.type_variables()
893+
.new_var(self.for_universe, origin);
893894
let u = self.tcx().mk_ty_var(new_var_id);
894895
debug!(
895896
"ConstInferUnifier: replacing original vid={:?} with new={:?}",

compiler/rustc_infer/src/infer/mod.rs

+5-31
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, Veri
4646
use self::region_constraints::{
4747
RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot,
4848
};
49-
use self::type_variable::{Diverging, TypeVariableOrigin, TypeVariableOriginKind};
49+
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
5050

5151
pub mod at;
5252
pub mod canonical;
@@ -701,23 +701,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
701701
t.fold_with(&mut self.freshener())
702702
}
703703

704-
/// Returns whether `ty` is a diverging type variable or not.
705-
/// (If `ty` is not a type variable at all, returns not diverging.)
706-
///
707-
/// No attempt is made to resolve `ty`.
708-
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> Diverging {
709-
match *ty.kind() {
710-
ty::Infer(ty::TyVar(vid)) => self.ty_vid_diverges(vid),
711-
_ => Diverging::NotDiverging,
712-
}
713-
}
714-
715-
/// Returns true if the type inference variable `vid` was created
716-
/// as a diverging type variable. No attempt is made to resolve `vid`.
717-
pub fn ty_vid_diverges(&'a self, vid: ty::TyVid) -> Diverging {
718-
self.inner.borrow_mut().type_variables().var_diverges(vid)
719-
}
720-
721704
/// Returns the origin of the type variable identified by `vid`, or `None`
722705
/// if this is not a type variable.
723706
///
@@ -1081,31 +1064,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10811064
self.inner.borrow_mut().type_variables().num_vars()
10821065
}
10831066

1084-
pub fn next_ty_var_id(&self, diverging: Diverging, origin: TypeVariableOrigin) -> TyVid {
1085-
self.inner.borrow_mut().type_variables().new_var(self.universe(), diverging, origin)
1067+
pub fn next_ty_var_id(&self, origin: TypeVariableOrigin) -> TyVid {
1068+
self.inner.borrow_mut().type_variables().new_var(self.universe(), origin)
10861069
}
10871070

10881071
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1089-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::NotDiverging, origin))
1072+
self.tcx.mk_ty_var(self.next_ty_var_id(origin))
10901073
}
10911074

10921075
pub fn next_ty_var_in_universe(
10931076
&self,
10941077
origin: TypeVariableOrigin,
10951078
universe: ty::UniverseIndex,
10961079
) -> Ty<'tcx> {
1097-
let vid = self.inner.borrow_mut().type_variables().new_var(
1098-
universe,
1099-
Diverging::NotDiverging,
1100-
origin,
1101-
);
1080+
let vid = self.inner.borrow_mut().type_variables().new_var(universe, origin);
11021081
self.tcx.mk_ty_var(vid)
11031082
}
11041083

1105-
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1106-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::Diverges, origin))
1107-
}
1108-
11091084
pub fn next_const_var(
11101085
&self,
11111086
ty: Ty<'tcx>,
@@ -1217,7 +1192,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12171192
// as the substitutions for the default, `(T, U)`.
12181193
let ty_var_id = self.inner.borrow_mut().type_variables().new_var(
12191194
self.universe(),
1220-
Diverging::NotDiverging,
12211195
TypeVariableOrigin {
12221196
kind: TypeVariableOriginKind::TypeParameterDefinition(
12231197
param.name,

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
//! constituents)
2323
2424
use crate::infer::combine::ConstEquateRelation;
25-
use crate::infer::type_variable::Diverging;
2625
use crate::infer::InferCtxt;
2726
use crate::infer::{ConstVarValue, ConstVariableValue};
2827
use rustc_data_structures::fx::FxHashMap;
@@ -927,8 +926,7 @@ where
927926
// Replacing with a new variable in the universe `self.universe`,
928927
// it will be unified later with the original type variable in
929928
// the universe `_universe`.
930-
let new_var_id =
931-
variables.new_var(self.universe, Diverging::NotDiverging, origin);
929+
let new_var_id = variables.new_var(self.universe, origin);
932930

933931
let u = self.tcx().mk_ty_var(new_var_id);
934932
debug!("generalize: replacing original vid={:?} with new={:?}", vid, u);

compiler/rustc_infer/src/infer/type_variable.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ pub enum TypeVariableOriginKind {
139139

140140
pub(crate) struct TypeVariableData {
141141
origin: TypeVariableOrigin,
142-
diverging: Diverging,
143-
}
144-
145-
#[derive(Copy, Clone, Debug)]
146-
pub enum Diverging {
147-
NotDiverging,
148-
Diverges,
149142
}
150143

151144
#[derive(Copy, Clone, Debug)]
@@ -195,14 +188,6 @@ impl<'tcx> TypeVariableStorage<'tcx> {
195188
}
196189

197190
impl<'tcx> TypeVariableTable<'_, 'tcx> {
198-
/// Returns the diverges flag given when `vid` was created.
199-
///
200-
/// Note that this function does not return care whether
201-
/// `vid` has been unified with something else or not.
202-
pub fn var_diverges(&self, vid: ty::TyVid) -> Diverging {
203-
self.storage.values.get(vid.index()).diverging
204-
}
205-
206191
/// Returns the origin that was given when `vid` was created.
207192
///
208193
/// Note that this function does not return care whether
@@ -264,21 +249,17 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
264249
pub fn new_var(
265250
&mut self,
266251
universe: ty::UniverseIndex,
267-
diverging: Diverging,
268252
origin: TypeVariableOrigin,
269253
) -> ty::TyVid {
270254
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
271255

272256
let sub_key = self.sub_relations().new_key(());
273257
assert_eq!(eq_key.vid, sub_key);
274258

275-
let index = self.values().push(TypeVariableData { origin, diverging });
259+
let index = self.values().push(TypeVariableData { origin });
276260
assert_eq!(eq_key.vid.as_u32(), index as u32);
277261

278-
debug!(
279-
"new_var(index={:?}, universe={:?}, diverging={:?}, origin={:?}",
280-
eq_key.vid, universe, diverging, origin,
281-
);
262+
debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,);
282263

283264
eq_key.vid
284265
}

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7777
!self.typeck_results.borrow().adjustments().contains_key(expr.hir_id),
7878
"expression with never type wound up being adjusted"
7979
);
80-
let adj_ty = self.next_diverging_ty_var(TypeVariableOrigin {
80+
let adj_ty = self.next_ty_var(TypeVariableOrigin {
8181
kind: TypeVariableOriginKind::AdjustmentType,
8282
span: expr.span,
8383
});

0 commit comments

Comments
 (0)