Set !const_evaluatable if ambig. and not inferred

This prevents an ICE due to a value not actually being evaluatable later.
This commit is contained in:
kadmin 2022-12-20 03:36:32 +00:00
parent 77b61379b6
commit b79a9a0900
3 changed files with 48 additions and 12 deletions

View File

@ -215,18 +215,16 @@ fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
}
}
if let Some(c) = single_match {
if let Ok(c) = c {
let is_ok = infcx
.commit_if_ok(|_| {
let ocx = ObligationCtxt::new_in_snapshot(infcx);
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c.ty(), ct.ty()).is_ok());
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok());
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(()) }
})
.is_ok();
assert!(is_ok);
}
if let Some(Ok(c)) = single_match {
let is_ok = infcx
.commit_if_ok(|_| {
let ocx = ObligationCtxt::new_in_snapshot(infcx);
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c.ty(), ct.ty()).is_ok());
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok());
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(()) }
})
.is_ok();
assert!(is_ok);
return true;
}

View File

@ -0,0 +1,20 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
fn foo<const N: usize, const M: usize>() -> [(); N+2]
where
[(); N + 1]:,
[(); M + 1]:,
{
bar()
//~^ ERROR: unconstrained
}
fn bar<const N: usize>() -> [(); N]
where
[(); N + 1]:,
{
[(); N]
}
fn main() {}

View File

@ -0,0 +1,18 @@
error: unconstrained generic constant
--> $DIR/ensure_is_evaluatable.rs:9:5
|
LL | bar()
| ^^^
|
= help: try adding a `where` bound using this expression: `where [(); N + 1]:`
note: required by a bound in `bar`
--> $DIR/ensure_is_evaluatable.rs:15:10
|
LL | fn bar<const N: usize>() -> [(); N]
| --- required by a bound in this
LL | where
LL | [(); N + 1]:,
| ^^^^^ required by this bound in `bar`
error: aborting due to previous error