Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-65675.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// run-pass
// compile-flags: -Z chalk

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

pub struct Foo<T, const N: usize>([T; N]);
impl<T, const N: usize> Foo<T, {N}> {}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/const-generics/issues/issue-65675.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-65675.rs:4:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default