Skip to content

Commit b58f5a7

Browse files
Don't ICE when we cannot eval a const to a valtree in the new solver
1 parent cc8d9b6 commit b58f5a7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1052,12 +1052,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
10521052
ty: Ty<'tcx>,
10531053
) -> Option<ty::Const<'tcx>> {
10541054
use rustc_middle::mir::interpret::ErrorHandled;
1055-
match self.infcx.try_const_eval_resolve(param_env, unevaluated, ty, DUMMY_SP) {
1056-
Ok(ct) => Some(ct),
1055+
match self.infcx.const_eval_resolve(param_env, unevaluated, DUMMY_SP) {
1056+
Ok(Some(val)) => Some(ty::Const::new_value(self.tcx(), val, ty)),
1057+
Ok(None) | Err(ErrorHandled::TooGeneric(_)) => None,
10571058
Err(ErrorHandled::Reported(e, _)) => {
10581059
Some(ty::Const::new_error(self.tcx(), e.into(), ty))
10591060
}
1060-
Err(ErrorHandled::TooGeneric(_)) => None,
10611061
}
10621062
}
10631063

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
//@ compile-flags: -Znext-solver=coherence
1+
//@ compile-flags: -Znext-solver
22

33
#[derive(Debug)]
44
struct X<const FN: fn() = { || {} }>;
55
//~^ ERROR using function pointers as const generic parameters is forbidden
66
//~| ERROR using function pointers as const generic parameters is forbidden
7+
//~| ERROR type annotations needed
78

89
fn main() {}

tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/const-region-infer-to-static-in-binder.rs:4:10
3+
|
4+
LL | struct X<const FN: fn() = { || {} }>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `{ || {} }`
6+
17
error: using function pointers as const generic parameters is forbidden
28
--> $DIR/const-region-infer-to-static-in-binder.rs:4:20
39
|
@@ -15,5 +21,6 @@ LL | struct X<const FN: fn() = { || {} }>;
1521
= note: the only supported types are integers, `bool` and `char`
1622
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1723

18-
error: aborting due to 2 previous errors
24+
error: aborting due to 3 previous errors
1925

26+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)