Skip to content

Commit

Permalink
Fix an issue with const inference variables sticking around under Cha…
Browse files Browse the repository at this point in the history
…lk + NLL
  • Loading branch information
varkor committed Oct 22, 2019
1 parent 50ffa79 commit 9220558
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
14 changes: 5 additions & 9 deletions src/librustc/infer/combine.rs
Expand Up @@ -602,19 +602,15 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==

match c {
ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
match c.val {
ConstValue::Infer(InferConst::Var(vid)) => {
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
match variable_table.probe_value(*vid).val.known() {
Some(u) => {
self.relate(&u, &u)
}
match variable_table.probe_value(vid).val.known() {
Some(u) => self.relate(&u, &u),
None => Ok(c),
}
}
_ => {
relate::super_relate_consts(self, c, c)
}
_ => relate::super_relate_consts(self, c, c),
}
}
}
Expand Down
41 changes: 23 additions & 18 deletions src/librustc/infer/nll_relate/mod.rs
Expand Up @@ -27,7 +27,7 @@ use crate::ty::error::TypeError;
use crate::ty::fold::{TypeFoldable, TypeVisitor};
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
use crate::ty::subst::GenericArg;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::{self, Ty, TyCtxt, InferConst};
use crate::mir::interpret::ConstValue;
use rustc_data_structures::fx::FxHashMap;
use std::fmt::Debug;
Expand Down Expand Up @@ -616,15 +616,20 @@ where
fn consts(
&mut self,
a: &'tcx ty::Const<'tcx>,
b: &'tcx ty::Const<'tcx>,
mut b: &'tcx ty::Const<'tcx>,
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
if let ty::Const { val: ConstValue::Bound(..), .. } = a {
// FIXME(const_generics): I'm unsure how this branch should actually be handled,
// so this is probably not correct.
self.infcx.super_combine_consts(self, a, b)
} else {
debug!("consts(a={:?}, b={:?}, variance={:?})", a, b, self.ambient_variance);
relate::super_relate_consts(self, a, b)
let a = self.infcx.shallow_resolve(a);

if !D::forbid_inference_vars() {
b = self.infcx.shallow_resolve(b);
}

match b.val {
ConstValue::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
// Forbid inference variables in the RHS.
bug!("unexpected inference var {:?}", b)
}
_ => self.infcx.super_combine_consts(self, a, b)
}
}

Expand Down Expand Up @@ -991,15 +996,15 @@ where
a: &'tcx ty::Const<'tcx>,
_: &'tcx ty::Const<'tcx>,
) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> {
debug!("TypeGeneralizer::consts(a={:?})", a);

if let ty::Const { val: ConstValue::Bound(..), .. } = a {
bug!(
"unexpected inference variable encountered in NLL generalization: {:?}",
a
);
} else {
relate::super_relate_consts(self, a, a)
match a.val {
ConstValue::Infer(InferConst::Var(vid)) => {
let mut variable_table = self.infcx.const_unification_table.borrow_mut();
match variable_table.probe_value(vid).val.known() {
Some(u) => self.relate(&u, &u),
None => Ok(a),
}
}
_ => relate::super_relate_consts(self, a, a),
}
}

Expand Down

0 comments on commit 9220558

Please sign in to comment.