diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-07 18:12:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-07 18:12:56 +0200 |
| commit | 067f6327a5924ebfd3d4cc2752f3462eee34fb15 (patch) | |
| tree | dcf765229b0299419f3500cf01a2fc5c536b85cc | |
| parent | a29a7d1551cc67a06fde4380370f313f4eba1ca6 (diff) | |
| parent | b58f5a780061c44c793d6c87a4d7eb6cfb3be743 (diff) | |
Rollup merge of #124846 - compiler-errors:const-eval, r=lcnr
Don't ICE when we cannot eval a const to a valtree in the new solver Use `const_eval_resolve` instead of `try_const_eval_resolve` because naming aside, the former doesn't ICE when a value can't be evaluated to a valtree. r? lcnr
3 files changed, 13 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs index 55ade5e3e2f..98aac581c6e 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs @@ -1052,12 +1052,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty: Ty<'tcx>, ) -> Option<ty::Const<'tcx>> { use rustc_middle::mir::interpret::ErrorHandled; - match self.infcx.try_const_eval_resolve(param_env, unevaluated, ty, DUMMY_SP) { - Ok(ct) => Some(ct), + match self.infcx.const_eval_resolve(param_env, unevaluated, DUMMY_SP) { + Ok(Some(val)) => Some(ty::Const::new_value(self.tcx(), val, ty)), + Ok(None) | Err(ErrorHandled::TooGeneric(_)) => None, Err(ErrorHandled::Reported(e, _)) => { Some(ty::Const::new_error(self.tcx(), e.into(), ty)) } - Err(ErrorHandled::TooGeneric(_)) => None, } } diff --git a/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.rs b/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.rs index 33a6d7aa783..26d63fdde99 100644 --- a/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.rs +++ b/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.rs @@ -1,8 +1,9 @@ -//@ compile-flags: -Znext-solver=coherence +//@ compile-flags: -Znext-solver #[derive(Debug)] struct X<const FN: fn() = { || {} }>; //~^ ERROR using function pointers as const generic parameters is forbidden //~| ERROR using function pointers as const generic parameters is forbidden +//~| ERROR type annotations needed fn main() {} diff --git a/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr b/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr index 4eef8c0ab6c..044c24fd2b2 100644 --- a/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr +++ b/tests/ui/traits/next-solver/canonical/const-region-infer-to-static-in-binder.stderr @@ -1,3 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/const-region-infer-to-static-in-binder.rs:4:10 + | +LL | struct X<const FN: fn() = { || {} }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `{ || {} }` + error: using function pointers as const generic parameters is forbidden --> $DIR/const-region-infer-to-static-in-binder.rs:4:20 | @@ -15,5 +21,6 @@ LL | struct X<const FN: fn() = { || {} }>; = note: the only supported types are integers, `bool` and `char` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0282`. |
