Skip to content

Commit b79a9a0

Browse files
committed
Set !const_evaluatable if ambig. and not inferred
This prevents an ICE due to a value not actually being evaluatable later.
1 parent 77b6137 commit b79a9a0

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,16 @@ fn satisfied_from_param_env<'tcx>(
215215
}
216216
}
217217

218-
if let Some(c) = single_match {
219-
if let Ok(c) = c {
220-
let is_ok = infcx
221-
.commit_if_ok(|_| {
222-
let ocx = ObligationCtxt::new_in_snapshot(infcx);
223-
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c.ty(), ct.ty()).is_ok());
224-
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok());
225-
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(()) }
226-
})
227-
.is_ok();
228-
assert!(is_ok);
229-
}
218+
if let Some(Ok(c)) = single_match {
219+
let is_ok = infcx
220+
.commit_if_ok(|_| {
221+
let ocx = ObligationCtxt::new_in_snapshot(infcx);
222+
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c.ty(), ct.ty()).is_ok());
223+
assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok());
224+
if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(()) }
225+
})
226+
.is_ok();
227+
assert!(is_ok);
230228
return true;
231229
}
232230

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
fn foo<const N: usize, const M: usize>() -> [(); N+2]
5+
where
6+
[(); N + 1]:,
7+
[(); M + 1]:,
8+
{
9+
bar()
10+
//~^ ERROR: unconstrained
11+
}
12+
13+
fn bar<const N: usize>() -> [(); N]
14+
where
15+
[(); N + 1]:,
16+
{
17+
[(); N]
18+
}
19+
20+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: unconstrained generic constant
2+
--> $DIR/ensure_is_evaluatable.rs:9:5
3+
|
4+
LL | bar()
5+
| ^^^
6+
|
7+
= help: try adding a `where` bound using this expression: `where [(); N + 1]:`
8+
note: required by a bound in `bar`
9+
--> $DIR/ensure_is_evaluatable.rs:15:10
10+
|
11+
LL | fn bar<const N: usize>() -> [(); N]
12+
| --- required by a bound in this
13+
LL | where
14+
LL | [(); N + 1]:,
15+
| ^^^^^ required by this bound in `bar`
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)