Unnamed repository; edit this file 'description' to name the repository.
Make InferenceResult take an `ExpressionStore`
Lukas Wirth 2 months ago
parent df96d01 · commit e231f8e
-rw-r--r--crates/hir-ty/src/consteval.rs17
-rw-r--r--crates/hir-ty/src/infer.rs57
-rw-r--r--crates/hir-ty/src/infer/closure/analysis.rs26
-rw-r--r--crates/hir-ty/src/infer/expr.rs24
-rw-r--r--crates/hir-ty/src/infer/mutability.rs12
-rw-r--r--crates/hir-ty/src/infer/pat.rs26
-rw-r--r--crates/hir-ty/src/infer/path.rs4
-rw-r--r--crates/hir-ty/src/method_resolution/confirm.rs2
-rw-r--r--crates/hir-ty/src/mir.rs8
-rw-r--r--crates/hir/src/has_source.rs4
10 files changed, 83 insertions, 97 deletions
diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs
index 9ff788c2e2..c294238030 100644
--- a/crates/hir-ty/src/consteval.rs
+++ b/crates/hir-ty/src/consteval.rs
@@ -8,7 +8,7 @@ use hir_def::{
ConstId, EnumVariantId, GeneralConstId, HasModule, StaticId,
attrs::AttrFlags,
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
- expr_store::Body,
+ expr_store::ExpressionStore,
hir::{Expr, ExprId, Literal},
};
use hir_expand::Lookup;
@@ -311,23 +311,23 @@ pub(crate) fn const_eval_discriminant_variant(
// and make this function private. See the fixme comment on `InferenceContext::resolve_all`.
pub(crate) fn eval_to_const<'db>(expr: ExprId, ctx: &mut InferenceContext<'_, 'db>) -> Const<'db> {
let infer = ctx.fixme_resolve_all_clone();
- fn has_closure(body: &Body, expr: ExprId) -> bool {
- if matches!(body[expr], Expr::Closure { .. }) {
+ fn has_closure(store: &ExpressionStore, expr: ExprId) -> bool {
+ if matches!(store[expr], Expr::Closure { .. }) {
return true;
}
let mut r = false;
- body.walk_child_exprs(expr, |idx| r |= has_closure(body, idx));
+ store.walk_child_exprs(expr, |idx| r |= has_closure(store, idx));
r
}
- if has_closure(ctx.body, expr) {
+ if has_closure(ctx.store, expr) {
// Type checking clousres need an isolated body (See the above FIXME). Bail out early to prevent panic.
return Const::error(ctx.interner());
}
- if let Expr::Path(p) = &ctx.body[expr] {
+ if let Expr::Path(p) = &ctx.store[expr] {
let mut ctx = TyLoweringContext::new(
ctx.db,
&ctx.resolver,
- ctx.body,
+ ctx.store,
ctx.generic_def,
LifetimeElisionKind::Infer,
);
@@ -336,7 +336,8 @@ pub(crate) fn eval_to_const<'db>(expr: ExprId, ctx: &mut InferenceContext<'_, 'd
}
}
if let Some(body_owner) = ctx.owner.as_def_with_body()
- && let Ok(mir_body) = lower_body_to_mir(ctx.db, body_owner, ctx.body, &infer, expr)
+ && let Ok(mir_body) =
+ lower_body_to_mir(ctx.db, body_owner, &ctx.db.body(body_owner), &infer, expr)
&& let Ok((Ok(result), _)) = interpret_mir(ctx.db, Arc::new(mir_body), true, None)
{
return result;
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index a4fcded42b..a78d5d8a30 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -36,7 +36,7 @@ use hir_def::{
AdtId, AnonConstId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, ExpressionStoreOwner,
FieldId, FunctionId, GenericDefId, GenericParamId, ItemContainerId, LocalFieldId, Lookup,
TraitId, TupleFieldId, TupleId, TypeAliasId, TypeOrConstParamId, VariantId,
- expr_store::{Body, ConstExprOrigin, ExpressionStore, HygieneId, path::Path},
+ expr_store::{ConstExprOrigin, ExpressionStore, HygieneId, path::Path},
hir::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, LabelId, PatId},
lang_item::LangItems,
layout::Integer,
@@ -106,16 +106,14 @@ pub fn infer_query_with_inspect<'db>(
let _p = tracing::info_span!("infer_query").entered();
let resolver = def.resolver(db);
let body = db.body(def);
- let mut ctx = InferenceContext::new(db, ExpressionStoreOwner::Body(def), &body, resolver);
+ let mut ctx = InferenceContext::new(db, ExpressionStoreOwner::Body(def), &body.store, resolver);
if let Some(inspect) = inspect {
ctx.table.infer_ctxt.attach_obligation_inspector(inspect);
}
match def {
- DefWithBodyId::FunctionId(f) => {
- ctx.collect_fn(f);
- }
+ DefWithBodyId::FunctionId(f) => ctx.collect_fn(f, body.self_param, &body.params),
DefWithBodyId::ConstId(c) => ctx.collect_const(c, &db.const_signature(c)),
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_signature(s)),
DefWithBodyId::VariantId(v) => {
@@ -144,9 +142,9 @@ pub fn infer_query_with_inspect<'db>(
}
}
- ctx.infer_body();
+ ctx.infer_body(body.body_expr);
- ctx.infer_mut_body();
+ ctx.infer_mut_body(body.body_expr);
ctx.handle_opaque_type_uses();
@@ -190,25 +188,14 @@ fn infer_signature_query(db: &dyn HirDatabase, def: GenericDefId) -> InferenceRe
let _p = tracing::info_span!("infer_signature_query").entered();
let (_, store) = db.generic_params_and_store(def);
let mut roots = store.signature_const_expr_roots_with_origins().peekable();
- let Some(&(first, _)) = roots.peek() else {
+ let Some(_) = roots.peek() else {
return InferenceResult::new(crate::next_solver::default_types(db).types.error);
};
let resolver = def.resolver(db);
let owner = ExpressionStoreOwner::Signature(def);
- // Construct a synthetic `Body` to satisfy `InferenceContext`.
- // The `body_expr` is set to the first root as a placeholder; we infer
- // each root expression individually below rather than calling `infer_body`.
- let body = Body {
- // FIXME: Get rid of this clone
- store: (*store).clone(),
- params: Box::new([]),
- self_param: None,
- body_expr: first,
- };
-
- let mut ctx = InferenceContext::new(db, owner, &body, resolver);
+ let mut ctx = InferenceContext::new(db, owner, &store, resolver);
for (root_expr, origin) in roots {
let expected = match origin {
@@ -846,7 +833,7 @@ impl InferenceResult {
pub(crate) struct InferenceContext<'body, 'db> {
pub(crate) db: &'db dyn HirDatabase,
pub(crate) owner: ExpressionStoreOwner,
- pub(crate) body: &'body Body,
+ pub(crate) store: &'body ExpressionStore,
/// Generally you should not resolve things via this resolver. Instead create a TyLoweringContext
/// and resolve the path via its methods. This will ensure proper error reporting.
pub(crate) resolver: Resolver<'db>,
@@ -947,7 +934,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
fn new(
db: &'db dyn HirDatabase,
owner: ExpressionStoreOwner,
- body: &'body Body,
+ store: &'body ExpressionStore,
resolver: Resolver<'db>,
) -> Self {
let trait_env = match owner {
@@ -976,7 +963,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
db,
owner,
generic_def: owner.generic_def(db),
- body,
+ store,
traits_in_scope: resolver.traits_in_scope(db),
resolver,
diverges: Diverges::Maybe,
@@ -1196,7 +1183,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
self.return_ty = return_ty;
}
- fn collect_fn(&mut self, func: FunctionId) {
+ fn collect_fn(&mut self, func: FunctionId, self_param: Option<BindingId>, params: &[PatId]) {
let data = self.db.function_signature(func);
let mut param_tys = self.with_ty_lowering(
&data.store,
@@ -1224,13 +1211,13 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
param_tys.push(va_list_ty);
}
let mut param_tys = param_tys.into_iter().chain(iter::repeat(self.table.next_ty_var()));
- if let Some(self_param) = self.body.self_param
+ if let Some(self_param) = self_param
&& let Some(ty) = param_tys.next()
{
let ty = self.process_user_written_ty(ty);
self.write_binding_ty(self_param, ty);
}
- for (ty, pat) in param_tys.zip(&*self.body.params) {
+ for (ty, pat) in param_tys.zip(params) {
let ty = self.process_user_written_ty(ty);
self.infer_top_pat(*pat, ty, None);
@@ -1264,12 +1251,12 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
&self.table.infer_ctxt
}
- fn infer_body(&mut self) {
+ fn infer_body(&mut self, body_expr: ExprId) {
match self.return_coercion {
- Some(_) => self.infer_return(self.body.body_expr),
+ Some(_) => self.infer_return(body_expr),
None => {
_ = self.infer_expr_coerce(
- self.body.body_expr,
+ body_expr,
&Expectation::has_type(self.return_ty),
ExprIsRead::Yes,
)
@@ -1376,7 +1363,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
f: impl FnOnce(&mut TyLoweringContext<'db, '_>) -> R,
) -> R {
self.with_ty_lowering(
- self.body,
+ self.store,
InferenceTyDiagnosticSource::Body,
LifetimeElisionKind::Infer,
f,
@@ -1418,7 +1405,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
pub(crate) fn make_body_ty(&mut self, type_ref: TypeRefId) -> Ty<'db> {
self.make_ty(
type_ref,
- self.body,
+ self.store,
InferenceTyDiagnosticSource::Body,
LifetimeElisionKind::Infer,
)
@@ -1426,7 +1413,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
pub(crate) fn make_body_const(&mut self, const_ref: ConstRef, ty: Ty<'db>) -> Const<'db> {
let const_ = self.with_ty_lowering(
- self.body,
+ self.store,
InferenceTyDiagnosticSource::Body,
LifetimeElisionKind::Infer,
|ctx| ctx.lower_const(const_ref, ty),
@@ -1436,7 +1423,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
pub(crate) fn make_path_as_body_const(&mut self, path: &Path, ty: Ty<'db>) -> Const<'db> {
let const_ = self.with_ty_lowering(
- self.body,
+ self.store,
InferenceTyDiagnosticSource::Body,
LifetimeElisionKind::Infer,
|ctx| ctx.lower_path_as_const(path, ty),
@@ -1450,7 +1437,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
pub(crate) fn make_body_lifetime(&mut self, lifetime_ref: LifetimeRefId) -> Region<'db> {
let lt = self.with_ty_lowering(
- self.body,
+ self.store,
InferenceTyDiagnosticSource::Body,
LifetimeElisionKind::Infer,
|ctx| ctx.lower_lifetime(lifetime_ref),
@@ -1665,7 +1652,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
let mut ctx = TyLoweringContext::new(
self.db,
&self.resolver,
- &self.body.store,
+ self.store,
&self.diagnostics,
InferenceTyDiagnosticSource::Body,
self.generic_def,
diff --git a/crates/hir-ty/src/infer/closure/analysis.rs b/crates/hir-ty/src/infer/closure/analysis.rs
index b4cc2ab4ae..2b9d3a7f5d 100644
--- a/crates/hir-ty/src/infer/closure/analysis.rs
+++ b/crates/hir-ty/src/infer/closure/analysis.rs
@@ -346,7 +346,7 @@ impl<'db> InferenceContext<'_, 'db> {
if path.type_anchor().is_some() {
return None;
}
- let hygiene = self.body.expr_or_pat_path_hygiene(id);
+ let hygiene = self.store.expr_or_pat_path_hygiene(id);
self.resolver.resolve_path_in_value_ns_fully(self.db, path, hygiene).and_then(|result| {
match result {
ValueNs::LocalBinding(binding) => {
@@ -365,7 +365,7 @@ impl<'db> InferenceContext<'_, 'db> {
/// Changes `current_capture_span_stack` to contain the stack of spans for this expr.
fn place_of_expr_without_adjust(&mut self, tgt_expr: ExprId) -> Option<HirPlace> {
self.current_capture_span_stack.clear();
- match &self.body[tgt_expr] {
+ match &self.store[tgt_expr] {
Expr::Path(p) => {
let resolver_guard =
self.resolver.update_to_inner_scope(self.db, self.owner, tgt_expr);
@@ -416,7 +416,7 @@ impl<'db> InferenceContext<'_, 'db> {
let mut actual_truncate_to = 0;
for &span in &*span_stack {
actual_truncate_to += 1;
- if !span.is_ref_span(self.body) {
+ if !span.is_ref_span(self.store) {
remained -= 1;
if remained == 0 {
break;
@@ -424,7 +424,7 @@ impl<'db> InferenceContext<'_, 'db> {
}
}
if actual_truncate_to < span_stack.len()
- && span_stack[actual_truncate_to].is_ref_span(self.body)
+ && span_stack[actual_truncate_to].is_ref_span(self.store)
{
// Include the ref operator if there is one, we will fix it later (in `strip_captures_ref_span()`) if it's incorrect.
actual_truncate_to += 1;
@@ -533,7 +533,7 @@ impl<'db> InferenceContext<'_, 'db> {
}
fn walk_expr_without_adjust(&mut self, tgt_expr: ExprId) {
- match &self.body[tgt_expr] {
+ match &self.store[tgt_expr] {
Expr::OffsetOf(_) => (),
Expr::InlineAsm(e) => e.operands.iter().for_each(|(_, op)| match op {
AsmOperand::In { expr, .. }
@@ -733,7 +733,7 @@ impl<'db> InferenceContext<'_, 'db> {
self.consume_with_pat(rhs_place, target);
self.inside_assignment = false;
}
- None => self.body.walk_pats(target, &mut |pat| match &self.body[pat] {
+ None => self.store.walk_pats(target, &mut |pat| match &self.store[pat] {
Pat::Path(path) => self.mutate_path_pat(path, pat),
&Pat::Expr(expr) => {
let place = self.place_of_expr(expr);
@@ -775,7 +775,7 @@ impl<'db> InferenceContext<'_, 'db> {
update_result: &mut impl FnMut(CaptureKind),
mut for_mut: BorrowKind,
) {
- match &self.body[p] {
+ match &self.store[p] {
Pat::Ref { .. }
| Pat::Box { .. }
| Pat::Missing
@@ -819,13 +819,13 @@ impl<'db> InferenceContext<'_, 'db> {
if self.result.pat_adjustments.get(&p).is_some_and(|it| !it.is_empty()) {
for_mut = BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture };
}
- self.body.walk_pats_shallow(p, |p| self.walk_pat_inner(p, update_result, for_mut));
+ self.store.walk_pats_shallow(p, |p| self.walk_pat_inner(p, update_result, for_mut));
}
fn is_upvar(&self, place: &HirPlace) -> bool {
if let Some(c) = self.current_closure {
let InternedClosure(_, root) = self.db.lookup_intern_closure(c);
- return self.body.is_binding_upvar(place.local, root);
+ return self.store.is_binding_upvar(place.local, root);
}
false
}
@@ -938,7 +938,7 @@ impl<'db> InferenceContext<'_, 'db> {
self.current_capture_span_stack
.extend((0..adjustments_count).map(|_| MirSpan::PatId(tgt_pat)));
'reset_span_stack: {
- match &self.body[tgt_pat] {
+ match &self.store[tgt_pat] {
Pat::Missing | Pat::Wild => (),
Pat::Tuple { args, ellipsis } => {
let (al, ar) = args.split_at(ellipsis.map_or(args.len(), |it| it as usize));
@@ -1089,7 +1089,7 @@ impl<'db> InferenceContext<'_, 'db> {
fn analyze_closure(&mut self, closure: InternedClosureId) -> FnTrait {
let InternedClosure(_, root) = self.db.lookup_intern_closure(closure);
self.current_closure = Some(closure);
- let Expr::Closure { body, capture_by, .. } = &self.body[root] else {
+ let Expr::Closure { body, capture_by, .. } = &self.store[root] else {
unreachable!("Closure expression id is always closure");
};
self.consume_expr(*body);
@@ -1133,7 +1133,7 @@ impl<'db> InferenceContext<'_, 'db> {
for capture in &mut captures {
if matches!(capture.kind, CaptureKind::ByValue) {
for span_stack in &mut capture.span_stacks {
- if span_stack[span_stack.len() - 1].is_ref_span(self.body) {
+ if span_stack[span_stack.len() - 1].is_ref_span(self.store) {
span_stack.truncate(span_stack.len() - 1);
}
}
@@ -1149,7 +1149,7 @@ impl<'db> InferenceContext<'_, 'db> {
let kind = self.analyze_closure(closure);
for (derefed_callee, callee_ty, params, expr) in exprs {
- if let &Expr::Call { callee, .. } = &self.body[expr] {
+ if let &Expr::Call { callee, .. } = &self.store[expr] {
let mut adjustments =
self.result.expr_adjustments.remove(&callee).unwrap_or_default().into_vec();
self.write_fn_trait_method_resolution(
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 45b181eff8..2e80bad614 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -155,7 +155,7 @@ impl<'db> InferenceContext<'_, 'db> {
/// it is matching against. This is used to determine whether we should
/// perform `NeverToAny` coercions.
fn pat_guaranteed_to_constitute_read_for_never(&self, pat: PatId) -> bool {
- match &self.body[pat] {
+ match &self.store[pat] {
// Does not constitute a read.
Pat::Wild => false,
@@ -197,25 +197,25 @@ impl<'db> InferenceContext<'_, 'db> {
// FIXME(tschottdorf): this is problematic as the HIR is being scraped, but
// ref bindings are be implicit after #42640 (default match binding modes). See issue #44848.
fn contains_explicit_ref_binding(&self, pat: PatId) -> bool {
- if let Pat::Bind { id, .. } = self.body[pat]
- && matches!(self.body[id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut)
+ if let Pat::Bind { id, .. } = self.store[pat]
+ && matches!(self.store[id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut)
{
return true;
}
let mut result = false;
- self.body.walk_pats_shallow(pat, |pat| result |= self.contains_explicit_ref_binding(pat));
+ self.store.walk_pats_shallow(pat, |pat| result |= self.contains_explicit_ref_binding(pat));
result
}
fn is_syntactic_place_expr(&self, expr: ExprId) -> bool {
- match &self.body[expr] {
+ match &self.store[expr] {
// Lang item paths cannot currently be local variables or statics.
Expr::Path(Path::LangItem(_, _)) => false,
Expr::Path(Path::Normal(path)) => path.type_anchor.is_none(),
Expr::Path(path) => self
.resolver
- .resolve_path_in_value_ns_fully(self.db, path, self.body.expr_path_hygiene(expr))
+ .resolve_path_in_value_ns_fully(self.db, path, self.store.expr_path_hygiene(expr))
.is_none_or(|res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))),
Expr::Underscore => true,
Expr::UnaryOp { op: UnaryOp::Deref, .. } => true,
@@ -311,7 +311,7 @@ impl<'db> InferenceContext<'_, 'db> {
) -> Ty<'db> {
self.db.unwind_if_revision_cancelled();
- let expr = &self.body[tgt_expr];
+ let expr = &self.store[tgt_expr];
tracing::trace!(?expr);
let ty = match expr {
Expr::Missing => self.err_ty(),
@@ -717,7 +717,7 @@ impl<'db> InferenceContext<'_, 'db> {
// instantiations in RHS can be coerced to it. Note that this
// cannot happen in destructuring assignments because of how
// they are desugared.
- let lhs_ty = match &self.body[target] {
+ let lhs_ty = match &self.store[target] {
// LHS of assignment doesn't constitute reads.
&Pat::Expr(expr) => {
Some(self.infer_expr(expr, &Expectation::none(), ExprIsRead::No))
@@ -728,7 +728,7 @@ impl<'db> InferenceContext<'_, 'db> {
let resolution = self.resolver.resolve_path_in_value_ns_fully(
self.db,
path,
- self.body.pat_path_hygiene(target),
+ self.store.pat_path_hygiene(target),
);
self.resolver.reset_to_guard(resolver_guard);
@@ -1351,7 +1351,7 @@ impl<'db> InferenceContext<'_, 'db> {
ExprIsRead::Yes,
);
let usize = self.types.types.usize;
- let len = match self.body[repeat] {
+ let len = match self.store[repeat] {
Expr::Underscore => {
self.write_expr_ty(repeat, usize);
self.table.next_const_var()
@@ -1491,7 +1491,7 @@ impl<'db> InferenceContext<'_, 'db> {
} else {
ExprIsRead::No
};
- let ty = if contains_explicit_ref_binding(this.body, *pat) {
+ let ty = if contains_explicit_ref_binding(this.store, *pat) {
this.infer_expr(
*expr,
&Expectation::has_type(decl_ty),
@@ -2117,7 +2117,7 @@ impl<'db> InferenceContext<'_, 'db> {
// the return value of an argument-position async block to an argument-position
// closure wrapped in a block.
// See <https://github.com/rust-lang/rust/issues/112225>.
- let is_closure = if let Expr::Closure { closure_kind, .. } = self.body[*arg] {
+ let is_closure = if let Expr::Closure { closure_kind, .. } = self.store[*arg] {
!matches!(closure_kind, ClosureKind::Coroutine(_))
} else {
false
diff --git a/crates/hir-ty/src/infer/mutability.rs b/crates/hir-ty/src/infer/mutability.rs
index 45fa141b6d..bfe43fc928 100644
--- a/crates/hir-ty/src/infer/mutability.rs
+++ b/crates/hir-ty/src/infer/mutability.rs
@@ -14,8 +14,8 @@ use crate::{
};
impl<'db> InferenceContext<'_, 'db> {
- pub(crate) fn infer_mut_body(&mut self) {
- self.infer_mut_expr(self.body.body_expr, Mutability::Not);
+ pub(crate) fn infer_mut_body(&mut self, body_expr: ExprId) {
+ self.infer_mut_expr(body_expr, Mutability::Not);
}
fn infer_mut_expr(&mut self, tgt_expr: ExprId, mut mutability: Mutability) {
@@ -52,7 +52,7 @@ impl<'db> InferenceContext<'_, 'db> {
}
fn infer_mut_expr_without_adjust(&mut self, tgt_expr: ExprId, mutability: Mutability) {
- match &self.body[tgt_expr] {
+ match &self.store[tgt_expr] {
Expr::Missing => (),
Expr::InlineAsm(e) => {
e.operands.iter().for_each(|(_, op)| match op {
@@ -173,7 +173,7 @@ impl<'db> InferenceContext<'_, 'db> {
self.infer_mut_expr(*rhs, Mutability::Not);
}
&Expr::Assignment { target, value } => {
- self.body.walk_pats(target, &mut |pat| match self.body[pat] {
+ self.store.walk_pats(target, &mut |pat| match self.store[pat] {
Pat::Expr(expr) => self.infer_mut_expr(expr, Mutability::Mut),
Pat::ConstBlock(block) => self.infer_mut_expr(block, Mutability::Not),
_ => {}
@@ -220,8 +220,8 @@ impl<'db> InferenceContext<'_, 'db> {
/// `let (ref x0, ref x1) = *it;` we should use `Deref`.
fn pat_bound_mutability(&self, pat: PatId) -> Mutability {
let mut r = Mutability::Not;
- self.body.walk_bindings_in_pat(pat, |b| {
- if self.body[b].mode == BindingAnnotation::RefMut {
+ self.store.walk_bindings_in_pat(pat, |b| {
+ if self.store[b].mode == BindingAnnotation::RefMut {
r = Mutability::Mut;
}
});
diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs
index 9ba2d634d5..0b6c9977f0 100644
--- a/crates/hir-ty/src/infer/pat.rs
+++ b/crates/hir-ty/src/infer/pat.rs
@@ -4,7 +4,7 @@ use std::{cmp, iter};
use hir_def::{
HasModule as _,
- expr_store::{Body, path::Path},
+ expr_store::{ExpressionStore, path::Path},
hir::{Binding, BindingAnnotation, BindingId, Expr, ExprId, Literal, Pat, PatId},
};
use hir_expand::name::Name;
@@ -260,14 +260,14 @@ impl<'db> InferenceContext<'_, 'db> {
) -> Ty<'db> {
let mut expected = self.table.structurally_resolve_type(expected);
- if matches!(&self.body[pat], Pat::Ref { .. }) || self.inside_assignment {
+ if matches!(&self.store[pat], Pat::Ref { .. }) || self.inside_assignment {
cov_mark::hit!(match_ergonomics_ref);
// When you encounter a `&pat` pattern, reset to Move.
// This is so that `w` is by value: `let (_, &w) = &(1, &2);`
// Destructuring assignments also reset the binding mode and
// don't do match ergonomics.
default_bm = BindingMode::Move;
- } else if self.is_non_ref_pat(self.body, pat) {
+ } else if self.is_non_ref_pat(self.store, pat) {
let mut pat_adjustments = Vec::new();
while let TyKind::Ref(_lifetime, inner, mutability) = expected.kind() {
pat_adjustments.push(expected.store());
@@ -289,7 +289,7 @@ impl<'db> InferenceContext<'_, 'db> {
let default_bm = default_bm;
let expected = expected;
- let ty = match &self.body[pat] {
+ let ty = match &self.store[pat] {
Pat::Tuple { args, ellipsis } => {
self.infer_tuple_pat_like(pat, expected, default_bm, *ellipsis, args, decl)
}
@@ -485,7 +485,7 @@ impl<'db> InferenceContext<'_, 'db> {
expected: Ty<'db>,
decl: Option<DeclContext>,
) -> Ty<'db> {
- let Binding { mode, .. } = self.body[binding];
+ let Binding { mode, .. } = self.store[binding];
let mode = if mode == BindingAnnotation::Unannotated {
default_bm
} else {
@@ -569,7 +569,7 @@ impl<'db> InferenceContext<'_, 'db> {
fn infer_lit_pat(&mut self, expr: ExprId, expected: Ty<'db>) -> Ty<'db> {
// Like slice patterns, byte string patterns can denote both `&[u8; N]` and `&[u8]`.
- if let Expr::Literal(Literal::ByteString(_)) = self.body[expr]
+ if let Expr::Literal(Literal::ByteString(_)) = self.store[expr]
&& let TyKind::Ref(_, inner, _) = expected.kind()
{
let inner = self.table.try_structurally_resolve_type(inner);
@@ -590,14 +590,14 @@ impl<'db> InferenceContext<'_, 'db> {
self.infer_expr(expr, &Expectation::has_type(expected), ExprIsRead::Yes)
}
- fn is_non_ref_pat(&mut self, body: &hir_def::expr_store::Body, pat: PatId) -> bool {
- match &body[pat] {
+ fn is_non_ref_pat(&mut self, store: &hir_def::expr_store::ExpressionStore, pat: PatId) -> bool {
+ match &store[pat] {
Pat::Tuple { .. }
| Pat::TupleStruct { .. }
| Pat::Record { .. }
| Pat::Range { .. }
| Pat::Slice { .. } => true,
- Pat::Or(pats) => pats.iter().all(|p| self.is_non_ref_pat(body, *p)),
+ Pat::Or(pats) => pats.iter().all(|p| self.is_non_ref_pat(store, *p)),
Pat::Path(path) => {
// A const is a reference pattern, but other value ns things aren't (see #16131).
let resolved = self.resolve_value_path_inner(path, pat.into(), true);
@@ -605,7 +605,7 @@ impl<'db> InferenceContext<'_, 'db> {
}
Pat::ConstBlock(..) => false,
Pat::Lit(expr) => !matches!(
- body[*expr],
+ store[*expr],
Expr::Literal(Literal::String(..) | Literal::CString(..) | Literal::ByteString(..))
),
Pat::Wild
@@ -670,10 +670,10 @@ impl<'db> InferenceContext<'_, 'db> {
}
}
-pub(super) fn contains_explicit_ref_binding(body: &Body, pat_id: PatId) -> bool {
+pub(super) fn contains_explicit_ref_binding(store: &ExpressionStore, pat_id: PatId) -> bool {
let mut res = false;
- body.walk_pats(pat_id, &mut |pat| {
- res |= matches!(body[pat], Pat::Bind { id, .. } if matches!(body[id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut));
+ store.walk_pats(pat_id, &mut |pat| {
+ res |= matches!(store[pat], Pat::Bind { id, .. } if matches!(store[id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut));
});
res
}
diff --git a/crates/hir-ty/src/infer/path.rs b/crates/hir-ty/src/infer/path.rs
index 40c6fdf3cc..17d4901123 100644
--- a/crates/hir-ty/src/infer/path.rs
+++ b/crates/hir-ty/src/infer/path.rs
@@ -136,7 +136,7 @@ impl<'db> InferenceContext<'_, 'db> {
let mut ctx = TyLoweringContext::new(
self.db,
&self.resolver,
- self.body,
+ self.store,
&self.diagnostics,
InferenceTyDiagnosticSource::Body,
self.generic_def,
@@ -159,7 +159,7 @@ impl<'db> InferenceContext<'_, 'db> {
let ty = self.table.process_user_written_ty(ty);
self.resolve_ty_assoc_item(ty, last.name, id).map(|(it, substs)| (it, Some(substs)))?
} else {
- let hygiene = self.body.expr_or_pat_path_hygiene(id);
+ let hygiene = self.store.expr_or_pat_path_hygiene(id);
// FIXME: report error, unresolved first path segment
let value_or_partial = path_ctx.resolve_path_in_value_ns(hygiene)?;
diff --git a/crates/hir-ty/src/method_resolution/confirm.rs b/crates/hir-ty/src/method_resolution/confirm.rs
index 0024ca16a5..ec589085a8 100644
--- a/crates/hir-ty/src/method_resolution/confirm.rs
+++ b/crates/hir-ty/src/method_resolution/confirm.rs
@@ -456,7 +456,7 @@ impl<'a, 'b, 'db> ConfirmContext<'a, 'b, 'db> {
substs_from_args_and_bindings(
self.db(),
- self.ctx.body,
+ self.ctx.store,
generic_args,
self.candidate.into(),
true,
diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs
index bf17c78468..a8865cd54e 100644
--- a/crates/hir-ty/src/mir.rs
+++ b/crates/hir-ty/src/mir.rs
@@ -6,7 +6,7 @@ use base_db::Crate;
use either::Either;
use hir_def::{
DefWithBodyId, FieldId, StaticId, TupleFieldId, UnionId, VariantId,
- expr_store::Body,
+ expr_store::ExpressionStore,
hir::{BindingAnnotation, BindingId, Expr, ExprId, Ordering, PatId},
};
use la_arena::{Arena, ArenaMap, Idx, RawIdx};
@@ -1210,12 +1210,12 @@ pub enum MirSpan {
}
impl MirSpan {
- pub fn is_ref_span(&self, body: &Body) -> bool {
+ pub fn is_ref_span(&self, store: &ExpressionStore) -> bool {
match *self {
- MirSpan::ExprId(expr) => matches!(body[expr], Expr::Ref { .. }),
+ MirSpan::ExprId(expr) => matches!(store[expr], Expr::Ref { .. }),
// FIXME: Figure out if this is correct wrt. match ergonomics.
MirSpan::BindingId(binding) => {
- matches!(body[binding].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut)
+ matches!(store[binding].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut)
}
MirSpan::PatId(_) | MirSpan::SelfParam | MirSpan::Unknown => false,
}
diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs
index 66bb357066..6a1aeb64f3 100644
--- a/crates/hir/src/has_source.rs
+++ b/crates/hir/src/has_source.rs
@@ -293,9 +293,7 @@ impl HasSource for Param<'_> {
}
Callee::Closure(closure, _) => {
let InternedClosure(owner, expr_id) = db.lookup_intern_closure(closure);
- let Some(body_owner) = owner.as_def_with_body() else {
- return None;
- };
+ let body_owner = owner.as_def_with_body()?;
let (_, source_map) = db.body_with_source_map(body_owner);
let ast @ InFile { file_id, value } = source_map.expr_syntax(expr_id).ok()?;
let root = db.parse_or_expand(file_id);