mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Support constants in const eval
This commit is contained in:
parent
b8e1d09b90
commit
0e2989e421
5 changed files with 198 additions and 50 deletions
|
@ -32,7 +32,7 @@ pub mod symbols;
|
|||
|
||||
mod display;
|
||||
|
||||
use std::{collections::HashMap, iter, ops::ControlFlow, sync::Arc};
|
||||
use std::{iter, ops::ControlFlow, sync::Arc};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
|
||||
|
@ -58,6 +58,7 @@ use hir_ty::{
|
|||
consteval::{
|
||||
eval_const, unknown_const_as_generic, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt,
|
||||
},
|
||||
could_unify,
|
||||
diagnostics::BodyValidationDiagnostic,
|
||||
method_resolution::{self, TyFingerprint},
|
||||
primitive::UintTy,
|
||||
|
@ -1602,20 +1603,7 @@ impl Const {
|
|||
}
|
||||
|
||||
pub fn eval(self, db: &dyn HirDatabase) -> Result<ComputedExpr, ConstEvalError> {
|
||||
let body = db.body(self.id.into());
|
||||
let root = &body.exprs[body.body_expr];
|
||||
let infer = db.infer_query(self.id.into());
|
||||
let infer = infer.as_ref();
|
||||
let result = eval_const(
|
||||
root,
|
||||
&mut ConstEvalCtx {
|
||||
exprs: &body.exprs,
|
||||
pats: &body.pats,
|
||||
local_data: HashMap::default(),
|
||||
infer: &mut |x| infer[x].clone(),
|
||||
},
|
||||
);
|
||||
result
|
||||
db.const_eval(self.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue