Skip to content

Commit e339e84

Browse files
committed
move force_instantiate_unchecked to be local to nll_relate code
1 parent e7ed997 commit e339e84

File tree

2 files changed

+61
-59
lines changed

2 files changed

+61
-59
lines changed

src/librustc/infer/mod.rs

-59
Original file line numberDiff line numberDiff line change
@@ -1231,65 +1231,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12311231
self.inlined_shallow_resolve(typ)
12321232
}
12331233

1234-
/// A hacky sort of method used by the NLL type-relating code:
1235-
///
1236-
/// - `var` must be some unbound type variable.
1237-
/// - `value` must be a suitable type to use as its value.
1238-
///
1239-
/// `var` will then be equated with `value`. Note that this
1240-
/// sidesteps a number of important checks, such as the "occurs
1241-
/// check" that prevents cyclic types, so it is important not to
1242-
/// use this method during regular type-check.
1243-
fn force_instantiate_unchecked(&self, var: Ty<'tcx>, value: Ty<'tcx>) {
1244-
match (&var.sty, &value.sty) {
1245-
(&ty::Infer(ty::TyVar(vid)), _) => {
1246-
let mut type_variables = self.type_variables.borrow_mut();
1247-
1248-
// In NLL, we don't have type inference variables
1249-
// floating around, so we can do this rather imprecise
1250-
// variant of the occurs-check.
1251-
assert!(!value.has_infer_types());
1252-
1253-
type_variables.instantiate(vid, value);
1254-
}
1255-
1256-
(&ty::Infer(ty::IntVar(vid)), &ty::Int(value)) => {
1257-
let mut int_unification_table = self.int_unification_table.borrow_mut();
1258-
int_unification_table
1259-
.unify_var_value(vid, Some(ty::IntVarValue::IntType(value)))
1260-
.unwrap_or_else(|_| {
1261-
bug!("failed to unify int var `{:?}` with `{:?}`", vid, value);
1262-
});
1263-
}
1264-
1265-
(&ty::Infer(ty::IntVar(vid)), &ty::Uint(value)) => {
1266-
let mut int_unification_table = self.int_unification_table.borrow_mut();
1267-
int_unification_table
1268-
.unify_var_value(vid, Some(ty::IntVarValue::UintType(value)))
1269-
.unwrap_or_else(|_| {
1270-
bug!("failed to unify int var `{:?}` with `{:?}`", vid, value);
1271-
});
1272-
}
1273-
1274-
(&ty::Infer(ty::FloatVar(vid)), &ty::Float(value)) => {
1275-
let mut float_unification_table = self.float_unification_table.borrow_mut();
1276-
float_unification_table
1277-
.unify_var_value(vid, Some(ty::FloatVarValue(value)))
1278-
.unwrap_or_else(|_| {
1279-
bug!("failed to unify float var `{:?}` with `{:?}`", vid, value)
1280-
});
1281-
}
1282-
1283-
_ => {
1284-
bug!(
1285-
"force_instantiate_unchecked invoked with bad combination: var={:?} value={:?}",
1286-
var,
1287-
value,
1288-
);
1289-
}
1290-
}
1291-
}
1292-
12931234
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
12941235
where
12951236
T: TypeFoldable<'tcx>,

src/librustc/infer/nll_relate/mod.rs

+61
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,64 @@ where
673673
Ok(ty::Binder::bind(result))
674674
}
675675
}
676+
677+
impl InferCtxt<'_, '_, 'tcx> {
678+
/// A hacky sort of method used by the NLL type-relating code:
679+
///
680+
/// - `var` must be some unbound type variable.
681+
/// - `value` must be a suitable type to use as its value.
682+
///
683+
/// `var` will then be equated with `value`. Note that this
684+
/// sidesteps a number of important checks, such as the "occurs
685+
/// check" that prevents cyclic types, so it is important not to
686+
/// use this method during regular type-check.
687+
fn force_instantiate_unchecked(&self, var: Ty<'tcx>, value: Ty<'tcx>) {
688+
match (&var.sty, &value.sty) {
689+
(&ty::Infer(ty::TyVar(vid)), _) => {
690+
let mut type_variables = self.type_variables.borrow_mut();
691+
692+
// In NLL, we don't have type inference variables
693+
// floating around, so we can do this rather imprecise
694+
// variant of the occurs-check.
695+
assert!(!value.has_infer_types());
696+
697+
type_variables.instantiate(vid, value);
698+
}
699+
700+
(&ty::Infer(ty::IntVar(vid)), &ty::Int(value)) => {
701+
let mut int_unification_table = self.int_unification_table.borrow_mut();
702+
int_unification_table
703+
.unify_var_value(vid, Some(ty::IntVarValue::IntType(value)))
704+
.unwrap_or_else(|_| {
705+
bug!("failed to unify int var `{:?}` with `{:?}`", vid, value);
706+
});
707+
}
708+
709+
(&ty::Infer(ty::IntVar(vid)), &ty::Uint(value)) => {
710+
let mut int_unification_table = self.int_unification_table.borrow_mut();
711+
int_unification_table
712+
.unify_var_value(vid, Some(ty::IntVarValue::UintType(value)))
713+
.unwrap_or_else(|_| {
714+
bug!("failed to unify int var `{:?}` with `{:?}`", vid, value);
715+
});
716+
}
717+
718+
(&ty::Infer(ty::FloatVar(vid)), &ty::Float(value)) => {
719+
let mut float_unification_table = self.float_unification_table.borrow_mut();
720+
float_unification_table
721+
.unify_var_value(vid, Some(ty::FloatVarValue(value)))
722+
.unwrap_or_else(|_| {
723+
bug!("failed to unify float var `{:?}` with `{:?}`", vid, value)
724+
});
725+
}
726+
727+
_ => {
728+
bug!(
729+
"force_instantiate_unchecked invoked with bad combination: var={:?} value={:?}",
730+
var,
731+
value,
732+
);
733+
}
734+
}
735+
}
736+
}

0 commit comments

Comments
 (0)