Skip to content

Commit 9220558

Browse files
committed
Fix an issue with const inference variables sticking around under Chalk + NLL
1 parent 50ffa79 commit 9220558

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

src/librustc/infer/combine.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -602,19 +602,15 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
602602
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
603603
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
604604

605-
match c {
606-
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
605+
match c.val {
606+
ConstValue::Infer(InferConst::Var(vid)) => {
607607
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
608-
match variable_table.probe_value(*vid).val.known() {
609-
Some(u) => {
610-
self.relate(&u, &u)
611-
}
608+
match variable_table.probe_value(vid).val.known() {
609+
Some(u) => self.relate(&u, &u),
612610
None => Ok(c),
613611
}
614612
}
615-
_ => {
616-
relate::super_relate_consts(self, c, c)
617-
}
613+
_ => relate::super_relate_consts(self, c, c),
618614
}
619615
}
620616
}

src/librustc/infer/nll_relate/mod.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::ty::error::TypeError;
2727
use crate::ty::fold::{TypeFoldable, TypeVisitor};
2828
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
2929
use crate::ty::subst::GenericArg;
30-
use crate::ty::{self, Ty, TyCtxt};
30+
use crate::ty::{self, Ty, TyCtxt, InferConst};
3131
use crate::mir::interpret::ConstValue;
3232
use rustc_data_structures::fx::FxHashMap;
3333
use std::fmt::Debug;
@@ -616,15 +616,20 @@ where
616616
fn consts(
617617
&mut self,
618618
a: &'tcx ty::Const<'tcx>,
619-
b: &'tcx ty::Const<'tcx>,
619+
mut b: &'tcx ty::Const<'tcx>,
620620
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
621-
if let ty::Const { val: ConstValue::Bound(..), .. } = a {
622-
// FIXME(const_generics): I'm unsure how this branch should actually be handled,
623-
// so this is probably not correct.
624-
self.infcx.super_combine_consts(self, a, b)
625-
} else {
626-
debug!("consts(a={:?}, b={:?}, variance={:?})", a, b, self.ambient_variance);
627-
relate::super_relate_consts(self, a, b)
621+
let a = self.infcx.shallow_resolve(a);
622+
623+
if !D::forbid_inference_vars() {
624+
b = self.infcx.shallow_resolve(b);
625+
}
626+
627+
match b.val {
628+
ConstValue::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
629+
// Forbid inference variables in the RHS.
630+
bug!("unexpected inference var {:?}", b)
631+
}
632+
_ => self.infcx.super_combine_consts(self, a, b)
628633
}
629634
}
630635

@@ -991,15 +996,15 @@ where
991996
a: &'tcx ty::Const<'tcx>,
992997
_: &'tcx ty::Const<'tcx>,
993998
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
994-
debug!("TypeGeneralizer::consts(a={:?})", a);
995-
996-
if let ty::Const { val: ConstValue::Bound(..), .. } = a {
997-
bug!(
998-
"unexpected inference variable encountered in NLL generalization: {:?}",
999-
a
1000-
);
1001-
} else {
1002-
relate::super_relate_consts(self, a, a)
999+
match a.val {
1000+
ConstValue::Infer(InferConst::Var(vid)) => {
1001+
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
1002+
match variable_table.probe_value(vid).val.known() {
1003+
Some(u) => self.relate(&u, &u),
1004+
None => Ok(a),
1005+
}
1006+
}
1007+
_ => relate::super_relate_consts(self, a, a),
10031008
}
10041009
}
10051010

0 commit comments

Comments
 (0)