Skip to content

Commit fc02f0f

Browse files
committed
stop categorizing inference variables as diverging when created
Instead, we now rely on the code that looks for a NeverToAny adjustment.
1 parent fceb523 commit fc02f0f

File tree

5 files changed

+17
-63
lines changed

5 files changed

+17
-63
lines changed

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 8 additions & 7 deletions
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};
@@ -639,7 +639,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
639639
.inner
640640
.borrow_mut()
641641
.type_variables()
642-
.new_var(self.for_universe, Diverging::NotDiverging, origin);
642+
.new_var(self.for_universe, origin);
643643
let u = self.tcx().mk_ty_var(new_var_id);
644644

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

862862
let origin =
863863
*self.infcx.inner.borrow_mut().type_variables().var_origin(vid);
864-
let new_var_id = self.infcx.inner.borrow_mut().type_variables().new_var(
865-
self.for_universe,
866-
Diverging::NotDiverging,
867-
origin,
868-
);
864+
let new_var_id = self
865+
.infcx
866+
.inner
867+
.borrow_mut()
868+
.type_variables()
869+
.new_var(self.for_universe, origin);
869870
let u = self.tcx().mk_ty_var(new_var_id);
870871
debug!(
871872
"ConstInferUnifier: replacing original vid={:?} with new={:?}",

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, Veri
4444
use self::region_constraints::{
4545
RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot,
4646
};
47-
use self::type_variable::{Diverging, TypeVariableOrigin, TypeVariableOriginKind};
47+
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
4848

4949
pub mod at;
5050
pub mod canonical;
@@ -641,23 +641,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
641641
t.fold_with(&mut self.freshener())
642642
}
643643

644-
/// Returns whether `ty` is a diverging type variable or not.
645-
/// (If `ty` is not a type variable at all, returns not diverging.)
646-
///
647-
/// No attempt is made to resolve `ty`.
648-
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> Diverging {
649-
match *ty.kind() {
650-
ty::Infer(ty::TyVar(vid)) => self.ty_vid_diverges(vid),
651-
_ => Diverging::NotDiverging,
652-
}
653-
}
654-
655-
/// Returns true if the type inference variable `vid` was created
656-
/// as a diverging type variable. No attempt is made to resolve `vid`.
657-
pub fn ty_vid_diverges(&'a self, vid: ty::TyVid) -> Diverging {
658-
self.inner.borrow_mut().type_variables().var_diverges(vid)
659-
}
660-
661644
/// Returns the origin of the type variable identified by `vid`, or `None`
662645
/// if this is not a type variable.
663646
///
@@ -1014,31 +997,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1014997
self.inner.borrow_mut().type_variables().num_vars()
1015998
}
1016999

1017-
pub fn next_ty_var_id(&self, diverging: Diverging, origin: TypeVariableOrigin) -> TyVid {
1018-
self.inner.borrow_mut().type_variables().new_var(self.universe(), diverging, origin)
1000+
pub fn next_ty_var_id(&self, origin: TypeVariableOrigin) -> TyVid {
1001+
self.inner.borrow_mut().type_variables().new_var(self.universe(), origin)
10191002
}
10201003

10211004
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1022-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::NotDiverging, origin))
1005+
self.tcx.mk_ty_var(self.next_ty_var_id(origin))
10231006
}
10241007

10251008
pub fn next_ty_var_in_universe(
10261009
&self,
10271010
origin: TypeVariableOrigin,
10281011
universe: ty::UniverseIndex,
10291012
) -> Ty<'tcx> {
1030-
let vid = self.inner.borrow_mut().type_variables().new_var(
1031-
universe,
1032-
Diverging::NotDiverging,
1033-
origin,
1034-
);
1013+
let vid = self.inner.borrow_mut().type_variables().new_var(universe, origin);
10351014
self.tcx.mk_ty_var(vid)
10361015
}
10371016

1038-
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1039-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::Diverges, origin))
1040-
}
1041-
10421017
pub fn next_const_var(
10431018
&self,
10441019
ty: Ty<'tcx>,
@@ -1150,7 +1125,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11501125
// as the substitutions for the default, `(T, U)`.
11511126
let ty_var_id = self.inner.borrow_mut().type_variables().new_var(
11521127
self.universe(),
1153-
Diverging::NotDiverging,
11541128
TypeVariableOrigin {
11551129
kind: TypeVariableOriginKind::TypeParameterDefinition(
11561130
param.name,

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

Lines changed: 1 addition & 3 deletions
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;
@@ -899,8 +898,7 @@ where
899898
// Replacing with a new variable in the universe `self.universe`,
900899
// it will be unified later with the original type variable in
901900
// the universe `_universe`.
902-
let new_var_id =
903-
variables.new_var(self.universe, Diverging::NotDiverging, origin);
901+
let new_var_id = variables.new_var(self.universe, origin);
904902

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

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 2 additions & 21 deletions
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)]
@@ -197,14 +190,6 @@ impl<'tcx> TypeVariableStorage<'tcx> {
197190
}
198191

199192
impl<'tcx> TypeVariableTable<'_, 'tcx> {
200-
/// Returns the diverges flag given when `vid` was created.
201-
///
202-
/// Note that this function does not return care whether
203-
/// `vid` has been unified with something else or not.
204-
pub fn var_diverges(&self, vid: ty::TyVid) -> Diverging {
205-
self.storage.values.get(vid.as_usize()).diverging
206-
}
207-
208193
/// Returns the origin that was given when `vid` was created.
209194
///
210195
/// Note that this function does not return care whether
@@ -266,21 +251,17 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
266251
pub fn new_var(
267252
&mut self,
268253
universe: ty::UniverseIndex,
269-
diverging: Diverging,
270254
origin: TypeVariableOrigin,
271255
) -> ty::TyVid {
272256
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
273257

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

277-
let index = self.values().push(TypeVariableData { origin, diverging });
261+
let index = self.values().push(TypeVariableData { origin });
278262
assert_eq!(eq_key.vid.as_usize(), index);
279263

280-
debug!(
281-
"new_var(index={:?}, universe={:?}, diverging={:?}, origin={:?}",
282-
eq_key.vid, universe, diverging, origin,
283-
);
264+
debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,);
284265

285266
eq_key.vid
286267
}

compiler/rustc_typeck/src/check/expr.rs

Lines changed: 1 addition & 1 deletion
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)