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:
parent
77b61379b6
commit
b79a9a0900
@ -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;
|
||||
}
|
||||
|
||||
|
20
src/test/ui/const-generics/ensure_is_evaluatable.rs
Normal file
20
src/test/ui/const-generics/ensure_is_evaluatable.rs
Normal 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() {}
|
18
src/test/ui/const-generics/ensure_is_evaluatable.stderr
Normal file
18
src/test/ui/const-generics/ensure_is_evaluatable.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user