Ensure param-env is const before calling eval_to_valtree

This commit is contained in:
Michael Goulet 2022-12-17 22:32:57 +00:00
parent 984eab57f7
commit c1181e1224
3 changed files with 51 additions and 2 deletions

View File

@ -569,7 +569,9 @@ fn eval_ty_constant(
ty::ConstKind::Unevaluated(uv) => {
let instance = self.resolve(uv.def, uv.substs)?;
let cid = GlobalId { instance, promoted: None };
self.ctfe_query(span, |tcx| tcx.eval_to_valtree(self.param_env.and(cid)))?
self.ctfe_query(span, |tcx| {
tcx.eval_to_valtree(self.param_env.with_const().and(cid))
})?
.unwrap_or_else(|| bug!("unable to create ValTree for {uv:?}"))
}
ty::ConstKind::Bound(..) | ty::ConstKind::Infer(..) => {

View File

@ -0,0 +1,36 @@
// compile-flags: -Zmir-opt-level=3
// check-pass
#![feature(generic_const_exprs)]
//~^ WARN the feature `generic_const_exprs` is incomplete
#[inline(always)]
fn from_fn_1<const N: usize, F: FnMut(usize) -> f32>(mut f: F) -> [f32; N] {
let mut result = [0.0; N];
let mut i = 0;
while i < N {
result[i] = f(i);
i += 1;
}
result
}
pub struct TestArray<const N: usize>
where
[(); N / 2]:,
{
array: [f32; N / 2],
}
impl<const N: usize> TestArray<N>
where
[(); N / 2]:,
{
fn from_fn_2<F: FnMut(usize) -> f32>(f: F) -> Self {
Self { array: from_fn_1(f) }
}
}
fn main() {
TestArray::<4>::from_fn_2(|i| 0.0);
}

View File

@ -0,0 +1,11 @@
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-104396.rs:4:12
|
LL | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted