Skip to content

Commit 71d7550

Browse files
committed
const_evaluatable_checked: fix occurs check
1 parent 92e4fb0 commit 71d7550

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

compiler/rustc_infer/src/infer/combine.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
543543
true
544544
}
545545

546+
fn visit_ct_substs(&self) -> bool {
547+
true
548+
}
549+
546550
fn binders<T>(
547551
&mut self,
548552
a: ty::Binder<T>,
@@ -716,7 +720,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
716720
let variable_table = &mut inner.const_unification_table();
717721
let var_value = variable_table.probe_value(vid);
718722
match var_value.val {
719-
ConstVariableValue::Known { value: u } => self.relate(u, u),
723+
ConstVariableValue::Known { value: u } => {
724+
drop(inner);
725+
self.relate(u, u)
726+
}
720727
ConstVariableValue::Unknown { universe } => {
721728
if self.for_universe.can_name(universe) {
722729
Ok(c)
@@ -815,6 +822,10 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
815822
true
816823
}
817824

825+
fn visit_ct_substs(&self) -> bool {
826+
true
827+
}
828+
818829
fn relate_with_variance<T: Relate<'tcx>>(
819830
&mut self,
820831
_variance: ty::Variance,
@@ -870,6 +881,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
870881
}
871882
}
872883
}
884+
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => {
885+
Ok(t)
886+
}
873887
_ => relate::super_relate_tys(self, t, t),
874888
}
875889
}

compiler/rustc_middle/src/ty/relate.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub trait TypeRelation<'tcx>: Sized {
3333
/// relation. Just affects error messages.
3434
fn a_is_expected(&self) -> bool;
3535

36+
fn visit_ct_substs(&self) -> bool {
37+
false
38+
}
39+
3640
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
3741
where
3842
F: FnOnce(&mut Self) -> R,
@@ -579,7 +583,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
579583
(
580584
ty::ConstKind::Unevaluated(a_def, a_substs, None),
581585
ty::ConstKind::Unevaluated(b_def, b_substs, None),
582-
) if tcx.features().const_evaluatable_checked => {
586+
) if tcx.features().const_evaluatable_checked && !relation.visit_ct_substs() => {
583587
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
584588
Ok(a.val)
585589
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(const_generics, const_evaluatable_checked)]
2+
#![allow(incomplete_features)]
3+
4+
// `N + 1` also depends on `T` here even if it doesn't use it.
5+
fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
6+
todo!()
7+
}
8+
9+
fn supplier<T>() -> T {
10+
todo!()
11+
}
12+
13+
fn catch_me<const N: usize>() where [u8; N + 1]: Default {
14+
let mut x = supplier();
15+
x = q::<_, N>(x); //~ ERROR mismatched types
16+
}
17+
18+
fn main() {
19+
catch_me::<3>();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unused-substs-5.rs:15:9
3+
|
4+
LL | x = q::<_, N>(x);
5+
| ^^^^^^^^^^^^
6+
| |
7+
| cyclic type of infinite size
8+
| help: try using a conversion method: `q::<_, N>(x).to_vec()`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)