Skip to content

Commit 39d4fe4

Browse files
authored
Rollup merge of rust-lang#63153 - varkor:remove-resolve_const_var, r=cramertj
Remove redundant method with const variable resolution I've also removed a `bug!()` in const value relation code and replaced it with a `FIXME`. Now `ConstValue::Slice` and `ConstValue::ByRef` will simply fail to unify rather than ICEing, which seems more user-friendly for testers.
2 parents e83fd29 + 87e73c1 commit 39d4fe4

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

src/librustc/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
693693
const_var: &'tcx ty::Const<'tcx>
694694
) -> &'tcx ty::Const<'tcx> {
695695
let infcx = self.infcx.expect("encountered const-var without infcx");
696-
let bound_to = infcx.resolve_const_var(const_var);
696+
let bound_to = infcx.shallow_resolve(const_var);
697697
if bound_to != const_var {
698698
self.fold_const(bound_to)
699699
} else {

src/librustc/infer/mod.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -1351,23 +1351,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13511351
}
13521352
}
13531353

1354-
pub fn resolve_const_var(
1355-
&self,
1356-
ct: &'tcx ty::Const<'tcx>
1357-
) -> &'tcx ty::Const<'tcx> {
1358-
if let ty::Const { val: ConstValue::Infer(InferConst::Var(v)), .. } = ct {
1359-
self.const_unification_table
1360-
.borrow_mut()
1361-
.probe_value(*v)
1362-
.val
1363-
.known()
1364-
.map(|c| self.resolve_const_var(c))
1365-
.unwrap_or(ct)
1366-
} else {
1367-
ct
1368-
}
1369-
}
1370-
13711354
pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
13721355
/*!
13731356
* Attempts to resolve all type/region/const variables in
@@ -1586,7 +1569,7 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
15861569
// it can be resolved to an int/float variable, which
15871570
// can then be recursively resolved, hence the
15881571
// recursion. Note though that we prevent type
1589-
// variables from unifyxing to other type variables
1572+
// variables from unifying to other type variables
15901573
// directly (though they may be embedded
15911574
// structurally), and we prevent cycles in any case,
15921575
// so this recursion should always be of very limited
@@ -1626,17 +1609,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
16261609
}
16271610

16281611
fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
1629-
match ct {
1630-
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
1612+
if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = ct {
16311613
self.infcx.const_unification_table
16321614
.borrow_mut()
16331615
.probe_value(*vid)
16341616
.val
16351617
.known()
1636-
.map(|c| self.fold_const(c))
16371618
.unwrap_or(ct)
1638-
}
1639-
_ => ct,
1619+
} else {
1620+
ct
16401621
}
16411622
}
16421623
}

src/librustc/ty/relate.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,11 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
594594
ty: a.ty,
595595
}))
596596
}
597-
(ConstValue::ByRef { .. }, _) => {
598-
bug!(
599-
"non-Scalar ConstValue encountered in super_relate_consts {:?} {:?}",
600-
a,
601-
b,
602-
);
603-
}
597+
598+
// FIXME(const_generics): we should either handle `Scalar::Ptr` or add a comment
599+
// saying that we're not handling it intentionally.
600+
601+
// FIXME(const_generics): handle `ConstValue::ByRef` and `ConstValue::Slice`.
604602

605603
// FIXME(const_generics): this is wrong, as it is a projection
606604
(ConstValue::Unevaluated(a_def_id, a_substs),

0 commit comments

Comments
 (0)