const_evaluatable_checked: fix occurs check
This commit is contained in:
parent
92e4fb0732
commit
71d7550350
4 changed files with 52 additions and 2 deletions
|
@ -543,6 +543,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_ct_substs(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn binders<T>(
|
fn binders<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
a: ty::Binder<T>,
|
a: ty::Binder<T>,
|
||||||
|
@ -716,7 +720,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
let variable_table = &mut inner.const_unification_table();
|
let variable_table = &mut inner.const_unification_table();
|
||||||
let var_value = variable_table.probe_value(vid);
|
let var_value = variable_table.probe_value(vid);
|
||||||
match var_value.val {
|
match var_value.val {
|
||||||
ConstVariableValue::Known { value: u } => self.relate(u, u),
|
ConstVariableValue::Known { value: u } => {
|
||||||
|
drop(inner);
|
||||||
|
self.relate(u, u)
|
||||||
|
}
|
||||||
ConstVariableValue::Unknown { universe } => {
|
ConstVariableValue::Unknown { universe } => {
|
||||||
if self.for_universe.can_name(universe) {
|
if self.for_universe.can_name(universe) {
|
||||||
Ok(c)
|
Ok(c)
|
||||||
|
@ -815,6 +822,10 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_ct_substs(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn relate_with_variance<T: Relate<'tcx>>(
|
fn relate_with_variance<T: Relate<'tcx>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_variance: ty::Variance,
|
_variance: ty::Variance,
|
||||||
|
@ -870,6 +881,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => {
|
||||||
|
Ok(t)
|
||||||
|
}
|
||||||
_ => relate::super_relate_tys(self, t, t),
|
_ => relate::super_relate_tys(self, t, t),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ pub trait TypeRelation<'tcx>: Sized {
|
||||||
/// relation. Just affects error messages.
|
/// relation. Just affects error messages.
|
||||||
fn a_is_expected(&self) -> bool;
|
fn a_is_expected(&self) -> bool;
|
||||||
|
|
||||||
|
fn visit_ct_substs(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
|
fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> R,
|
F: FnOnce(&mut Self) -> R,
|
||||||
|
@ -579,7 +583,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
|
||||||
(
|
(
|
||||||
ty::ConstKind::Unevaluated(a_def, a_substs, None),
|
ty::ConstKind::Unevaluated(a_def, a_substs, None),
|
||||||
ty::ConstKind::Unevaluated(b_def, b_substs, None),
|
ty::ConstKind::Unevaluated(b_def, b_substs, None),
|
||||||
) if tcx.features().const_evaluatable_checked => {
|
) if tcx.features().const_evaluatable_checked && !relation.visit_ct_substs() => {
|
||||||
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
|
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
|
||||||
Ok(a.val)
|
Ok(a.val)
|
||||||
} else {
|
} else {
|
||||||
|
|
20
src/test/ui/const-generics/occurs-check/unused-substs-5.rs
Normal file
20
src/test/ui/const-generics/occurs-check/unused-substs-5.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#![feature(const_generics, const_evaluatable_checked)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
// `N + 1` also depends on `T` here even if it doesn't use it.
|
||||||
|
fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn supplier<T>() -> T {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn catch_me<const N: usize>() where [u8; N + 1]: Default {
|
||||||
|
let mut x = supplier();
|
||||||
|
x = q::<_, N>(x); //~ ERROR mismatched types
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
catch_me::<3>();
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/unused-substs-5.rs:15:9
|
||||||
|
|
|
||||||
|
LL | x = q::<_, N>(x);
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| cyclic type of infinite size
|
||||||
|
| help: try using a conversion method: `q::<_, N>(x).to_vec()`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue