mun_hir/ty/infer/
place_expr.rs

1use crate::resolve::ValueNs;
2use crate::{ty::infer::InferenceResultBuilder, Expr, ExprId, Path, Resolver};
3
4impl<'a> InferenceResultBuilder<'a> {
5    /// Checks if the specified expression is a place-expression. A place expression represents a
6    /// memory location.
7    pub(super) fn check_place_expression(&mut self, resolver: &Resolver, expr: ExprId) -> bool {
8        match &self.body[expr] {
9            Expr::Path(p) => self.check_place_path(resolver, p),
10            Expr::Index { base, .. } => self.check_place_expression(resolver, *base),
11            Expr::Field { .. } | Expr::Array(_) => true,
12            _ => false,
13        }
14    }
15
16    /// Checks if the specified path references a memory location.
17    fn check_place_path(&mut self, resolver: &Resolver, path: &Path) -> bool {
18        match resolver.resolve_path_as_value_fully(self.db.upcast(), path) {
19            Some((ValueNs::LocalBinding(_), _)) => true,
20            Some((ValueNs::FunctionId(_), _)) | Some((ValueNs::StructId(_), _)) | None => false,
21        }
22    }
23}