Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/lower.rs')
-rw-r--r--crates/hir-def/src/expr_store/lower.rs44
1 files changed, 15 insertions, 29 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 29871f5e04..03683ec920 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -7,12 +7,14 @@ mod path;
use std::mem;
+use base_db::FxIndexSet;
use cfg::CfgOptions;
use either::Either;
use hir_expand::{
- HirFileId, InFile, Lookup, MacroDefId,
+ HirFileId, InFile, Intern, MacroDefId,
mod_path::tool_path,
name::{AsName, Name},
+ span_map::SpanMapRef,
};
use intern::{Symbol, sym};
use rustc_hash::FxHashMap;
@@ -30,8 +32,8 @@ use triomphe::Arc;
use tt::TextRange;
use crate::{
- AdtId, BlockId, BlockLoc, DefWithBodyId, FunctionId, GenericDefId, ImplId, ItemTreeLoc,
- MacroId, ModuleDefId, ModuleId, TraitAliasId, TraitId, TypeAliasId, UnresolvedMacro,
+ AdtId, BlockId, BlockLoc, DefWithBodyId, FunctionId, GenericDefId, ImplId, MacroId,
+ ModuleDefId, ModuleId, TraitAliasId, TraitId, TypeAliasId, UnresolvedMacro,
builtin_type::BuiltinUint,
db::DefDatabase,
expr_store::{
@@ -65,8 +67,6 @@ use crate::{
pub use self::path::hir_segment_to_ast_segment;
-type FxIndexSet<K> = indexmap::IndexSet<K, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
-
pub(super) fn lower_body(
db: &dyn DefDatabase,
owner: DefWithBodyId,
@@ -564,6 +564,11 @@ impl ExprCollector<'_> {
}
}
+ #[inline]
+ pub(crate) fn span_map(&self) -> SpanMapRef<'_> {
+ self.expander.span_map()
+ }
+
pub fn lower_lifetime_ref(&mut self, lifetime: ast::Lifetime) -> LifetimeRefId {
// FIXME: Keyword check?
let lifetime_ref = match &*lifetime.text() {
@@ -2141,26 +2146,10 @@ impl ExprCollector<'_> {
block: ast::BlockExpr,
mk_block: impl FnOnce(Option<BlockId>, Box<[Statement]>, Option<ExprId>) -> Expr,
) -> ExprId {
- let block_has_items = {
- let statement_has_item = block.statements().any(|stmt| match stmt {
- ast::Stmt::Item(_) => true,
- // Macro calls can be both items and expressions. The syntax library always treats
- // them as expressions here, so we undo that.
- ast::Stmt::ExprStmt(es) => matches!(es.expr(), Some(ast::Expr::MacroExpr(_))),
- _ => false,
- });
- statement_has_item
- || matches!(block.tail_expr(), Some(ast::Expr::MacroExpr(_)))
- || (block.may_carry_attributes() && block.attrs().next().is_some())
- };
-
- let block_id = if block_has_items {
- let file_local_id = self.expander.ast_id_map().ast_id(&block);
+ let block_id = self.expander.ast_id_map().ast_id_for_block(&block).map(|file_local_id| {
let ast_id = self.expander.in_file(file_local_id);
- Some(self.db.intern_block(BlockLoc { ast_id, module: self.module }))
- } else {
- None
- };
+ BlockLoc { ast_id, module: self.module }.intern(self.db)
+ });
let (module, def_map) =
match block_id.map(|block_id| (block_def_map(self.db, block_id), block_id)) {
@@ -2260,11 +2249,8 @@ impl ExprCollector<'_> {
match resolved.take_values() {
Some(ModuleDefId::ConstId(_)) => (None, Pat::Path(name.into())),
Some(ModuleDefId::EnumVariantId(variant))
- if {
- let loc = variant.lookup(self.db);
- let tree = loc.item_tree_id().item_tree(self.db);
- tree[loc.id.value].shape != FieldsShape::Record
- } =>
+ // FIXME: This can cause a cycle if the user is writing invalid code
+ if self.db.variant_fields(variant.into()).shape != FieldsShape::Record =>
{
(None, Pat::Path(name.into()))
}