Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/mir/eval.rs')
-rw-r--r--crates/hir-ty/src/mir/eval.rs36
1 files changed, 20 insertions, 16 deletions
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 6e62bcbbdd..da15ca695e 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -42,8 +42,8 @@ use crate::{
layout::{Layout, LayoutError, RustcEnumVariantIdx},
method_resolution::{is_dyn_method, lookup_impl_const},
next_solver::{
- Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region,
- SolverDefId, Ty, TyKind, TypingMode, UnevaluatedConst, ValueConst,
+ Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region, Ty, TyKind,
+ TypingMode, UnevaluatedConst, ValueConst,
infer::{DbInternerInferExt, InferCtxt, traits::ObligationCause},
obligation_ctxt::ObligationCtxt,
},
@@ -1917,24 +1917,28 @@ impl<'db> Evaluator<'db> {
let value = match konst.kind() {
ConstKind::Value(value) => value,
ConstKind::Unevaluated(UnevaluatedConst { def: const_id, args: subst }) => 'b: {
- let mut const_id = match const_id {
- SolverDefId::ConstId(it) => GeneralConstId::from(it),
- SolverDefId::StaticId(it) => it.into(),
- _ => unreachable!("unevaluated consts should be consts or statics"),
- };
+ let mut id = const_id.0;
let mut subst = subst;
- if let hir_def::GeneralConstId::ConstId(c) = const_id {
+ if let hir_def::GeneralConstId::ConstId(c) = id {
let (c, s) = lookup_impl_const(&self.infcx, self.trait_env.clone(), c, subst);
- const_id = hir_def::GeneralConstId::ConstId(c);
+ id = hir_def::GeneralConstId::ConstId(c);
subst = s;
}
- result_owner = self
- .db
- .const_eval(const_id, subst, Some(self.trait_env.clone()))
- .map_err(|e| {
- let name = const_id.name(self.db);
- MirEvalError::ConstEvalError(name, Box::new(e))
- })?;
+ result_owner = match id {
+ GeneralConstId::ConstId(const_id) => self
+ .db
+ .const_eval(const_id, subst, Some(self.trait_env.clone()))
+ .map_err(|e| {
+ let name = id.name(self.db);
+ MirEvalError::ConstEvalError(name, Box::new(e))
+ })?,
+ GeneralConstId::StaticId(static_id) => {
+ self.db.const_eval_static(static_id).map_err(|e| {
+ let name = id.name(self.db);
+ MirEvalError::ConstEvalError(name, Box::new(e))
+ })?
+ }
+ };
if let ConstKind::Value(value) = result_owner.kind() {
break 'b value;
}