Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/base-db/src/lib.rs1
-rw-r--r--crates/hir-def/src/db.rs7
-rw-r--r--crates/hir-def/src/nameres.rs2
-rw-r--r--crates/hir-def/src/nameres/assoc.rs4
-rw-r--r--crates/hir-expand/src/db.rs12
-rw-r--r--crates/hir-expand/src/lib.rs63
-rw-r--r--crates/hir-ty/src/opaques.rs2
-rw-r--r--crates/hir/src/lib.rs4
-rw-r--r--crates/hir/src/semantics.rs4
-rw-r--r--crates/ide/src/navigation_target.rs2
10 files changed, 54 insertions, 47 deletions
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index a209a0e631..fd47403ec4 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -49,6 +49,7 @@ macro_rules! impl_intern_key {
#[salsa_macros::interned(no_lifetime, revisions = usize::MAX)]
#[derive(PartialOrd, Ord)]
pub struct $id {
+ #[returns(ref)]
pub loc: $loc,
}
diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs
index 11e5c54246..6301eb7901 100644
--- a/crates/hir-def/src/db.rs
+++ b/crates/hir-def/src/db.rs
@@ -7,8 +7,7 @@ use hir_expand::{
use triomphe::Arc;
use crate::{
- AssocItemId, AttrDefId, Macro2Loc, MacroExpander, MacroId, MacroRulesLoc, MacroRulesLocFlags,
- TraitId,
+ AssocItemId, AttrDefId, MacroExpander, MacroId, MacroRulesLocFlags, TraitId,
attrs::AttrFlags,
item_tree::{ItemTree, file_item_tree},
nameres::crate_def_map,
@@ -81,7 +80,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
match id {
MacroId::Macro2Id(it) => {
- let loc: Macro2Loc = it.lookup(db);
+ let loc = it.lookup(db);
MacroDefId {
krate: loc.container.krate(db),
@@ -92,7 +91,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
}
}
MacroId::MacroRulesId(it) => {
- let loc: MacroRulesLoc = it.lookup(db);
+ let loc = it.lookup(db);
MacroDefId {
krate: loc.container.krate(db),
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index 88e3408a33..ef7fb0888f 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -427,7 +427,7 @@ pub(crate) fn crate_local_def_map(db: &dyn DefDatabase, crate_id: Crate) -> DefM
#[salsa_macros::tracked(returns(ref))]
pub fn block_def_map(db: &dyn DefDatabase, block_id: BlockId) -> DefMap {
- let BlockLoc { ast_id, module } = block_id.lookup(db);
+ let BlockLoc { ast_id, module } = *block_id.lookup(db);
let visibility = Visibility::Module(module, VisibilityExplicitness::Implicit);
let module_data =
diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs
index b1d554738f..7b5b39cb08 100644
--- a/crates/hir-def/src/nameres/assoc.rs
+++ b/crates/hir-def/src/nameres/assoc.rs
@@ -50,7 +50,7 @@ impl TraitItems {
db: &dyn DefDatabase,
tr: TraitId,
) -> (TraitItems, DefDiagnostics) {
- let ItemLoc { container: module_id, id: ast_id } = tr.lookup(db);
+ let ItemLoc { container: module_id, id: ast_id } = *tr.lookup(db);
let ast_id_map = db.ast_id_map(ast_id.file_id);
let source = ast_id.with_value(ast_id_map.get(ast_id.value)).to_node(db);
if source.eq_token().is_some() {
@@ -115,7 +115,7 @@ impl ImplItems {
#[salsa::tracked(returns(ref))]
pub fn of(db: &dyn DefDatabase, id: ImplId) -> (ImplItems, DefDiagnostics) {
let _p = tracing::info_span!("impl_items_with_diagnostics_query").entered();
- let ItemLoc { container: module_id, id: ast_id } = id.lookup(db);
+ let ItemLoc { container: module_id, id: ast_id } = *id.lookup(db);
let collector =
AssocItemCollector::new(db, module_id, ItemContainerId::ImplId(id), ast_id.file_id);
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index beae6e843e..b09f69a295 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -149,8 +149,8 @@ fn syntax_context(db: &dyn ExpandDatabase, file: HirFileId, edition: Edition) ->
match file {
HirFileId::FileId(_) => SyntaxContext::root(edition),
HirFileId::MacroFile(m) => {
- let kind = m.loc(db).kind;
- db.macro_arg_considering_derives(m, &kind).2.ctx
+ let kind = &m.loc(db).kind;
+ db.macro_arg_considering_derives(m, kind).2.ctx
}
}
}
@@ -542,11 +542,11 @@ impl<'db> TokenExpander<'db> {
}
}
-fn macro_expand(
- db: &dyn ExpandDatabase,
+fn macro_expand<'db>(
+ db: &'db dyn ExpandDatabase,
macro_call_id: MacroCallId,
- loc: MacroCallLoc,
-) -> ExpandResult<(Cow<'_, tt::TopSubtree>, MatchedArmIndex)> {
+ loc: &MacroCallLoc,
+) -> ExpandResult<(Cow<'db, tt::TopSubtree>, MatchedArmIndex)> {
let _p = tracing::info_span!("macro_expand").entered();
let (ExpandResult { value: (tt, matched_arm), err }, span) = match loc.def.kind {
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index 0850d6156d..c98d072784 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -81,7 +81,7 @@ macro_rules! impl_intern_lookup {
impl $crate::Lookup for $id {
type Database = dyn $db;
type Data = $loc;
- fn lookup(&self, db: &Self::Database) -> Self::Data {
+ fn lookup<'db>(&self, db: &'db Self::Database) -> &'db Self::Data {
self.loc(db)
}
}
@@ -98,7 +98,7 @@ pub trait Intern {
pub trait Lookup {
type Database: ?Sized;
type Data;
- fn lookup(&self, db: &Self::Database) -> Self::Data;
+ fn lookup<'db>(&self, db: &'db Self::Database) -> &'db Self::Data;
}
impl_intern_lookup!(ExpandDatabase, MacroCallId, MacroCallLoc);
@@ -714,24 +714,27 @@ impl MacroCallKind {
/// - fn_like! {}, it spans the path and token tree
/// - #\[derive], it spans the `#[derive(...)]` attribute and the annotated item
/// - #\[attr], it spans the `#[attr(...)]` attribute and the annotated item
- pub fn original_call_range_with_input(self, db: &dyn ExpandDatabase) -> FileRange {
- let mut kind = self;
+ pub fn original_call_range_with_input(&self, db: &dyn ExpandDatabase) -> FileRange {
+ let get_range = |kind: &_| match kind {
+ MacroCallKind::FnLike { ast_id, .. } => ast_id.erase(),
+ MacroCallKind::Derive { ast_id, .. } => ast_id.erase(),
+ MacroCallKind::Attr { ast_id, .. } => ast_id.erase(),
+ };
+
+ let mut ast_id = get_range(self);
+ let mut file_id = self.file_id();
let file_id = loop {
- match kind.file_id() {
+ match file_id {
HirFileId::MacroFile(file) => {
- kind = file.loc(db).kind;
+ let kind = &file.loc(db).kind;
+ ast_id = get_range(kind);
+ file_id = kind.file_id();
}
HirFileId::FileId(file_id) => break file_id,
}
};
- let range = match kind {
- MacroCallKind::FnLike { ast_id, .. } => ast_id.to_ptr(db).text_range(),
- MacroCallKind::Derive { ast_id, .. } => ast_id.to_ptr(db).text_range(),
- MacroCallKind::Attr { ast_id, .. } => ast_id.to_ptr(db).text_range(),
- };
-
- FileRange { range, file_id }
+ FileRange { range: ast_id.to_ptr(db).text_range(), file_id }
}
/// Returns the original file range that best describes the location of this macro call.
@@ -739,18 +742,8 @@ impl MacroCallKind {
/// Here we try to roughly match what rustc does to improve diagnostics: fn-like macros
/// get the macro path (rustc shows the whole `ast::MacroCall`), attribute macros get the
/// attribute's range, and derives get only the specific derive that is being referred to.
- pub fn original_call_range(self, db: &dyn ExpandDatabase, krate: Crate) -> FileRange {
- let mut kind = self;
- let file_id = loop {
- match kind.file_id() {
- HirFileId::MacroFile(file) => {
- kind = file.loc(db).kind;
- }
- HirFileId::FileId(file_id) => break file_id,
- }
- };
-
- let range = match kind {
+ pub fn original_call_range(&self, db: &dyn ExpandDatabase, krate: Crate) -> FileRange {
+ let get_range = |kind: &_| match kind {
MacroCallKind::FnLike { ast_id, .. } => {
let node = ast_id.to_node(db);
node.path()
@@ -761,11 +754,24 @@ impl MacroCallKind {
}
MacroCallKind::Derive { ast_id, derive_attr_index, .. } => {
// FIXME: should be the range of the macro name, not the whole derive
- derive_attr_index.find_attr_range(db, krate, ast_id).1.syntax().text_range()
+ derive_attr_index.find_attr_range(db, krate, *ast_id).1.syntax().text_range()
}
// FIXME: handle `cfg_attr`
MacroCallKind::Attr { ast_id, censored_attr_ids: attr_ids, .. } => {
- attr_ids.invoc_attr().find_attr_range(db, krate, ast_id).1.syntax().text_range()
+ attr_ids.invoc_attr().find_attr_range(db, krate, *ast_id).1.syntax().text_range()
+ }
+ };
+
+ let mut range = get_range(self);
+ let mut file_id = self.file_id();
+ let file_id = loop {
+ match file_id {
+ HirFileId::MacroFile(file) => {
+ let kind = &file.loc(db).kind;
+ range = get_range(kind);
+ file_id = kind.file_id();
+ }
+ HirFileId::FileId(file_id) => break file_id,
}
};
@@ -797,7 +803,7 @@ pub struct ExpansionInfo<'db> {
arg: InFile<Option<SyntaxNode>>,
exp_map: &'db ExpansionSpanMap,
arg_map: SpanMap<'db>,
- loc: MacroCallLoc,
+ loc: &'db MacroCallLoc,
}
impl<'db> ExpansionInfo<'db> {
@@ -1056,6 +1062,7 @@ intern::impl_internable!(ModPath);
#[salsa_macros::interned(no_lifetime, debug, revisions = usize::MAX)]
#[doc(alias = "MacroFileId")]
pub struct MacroCallId {
+ #[returns(ref)]
pub loc: MacroCallLoc,
}
diff --git a/crates/hir-ty/src/opaques.rs b/crates/hir-ty/src/opaques.rs
index 4244b1bac4..79d2fa0c2d 100644
--- a/crates/hir-ty/src/opaques.rs
+++ b/crates/hir-ty/src/opaques.rs
@@ -132,7 +132,7 @@ pub(crate) fn tait_hidden_types(
let param_env =
db.trait_environment(ExpressionStoreOwnerId::from(GenericDefId::from(type_alias)));
- let defining_bodies = tait_defining_bodies(db, &loc);
+ let defining_bodies = tait_defining_bodies(db, loc);
let mut result = ArenaMap::with_capacity(taits_count);
for defining_body in defining_bodies {
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index ac9adf592d..894bfe91b5 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -7467,11 +7467,11 @@ fn body_param_env_from_has_crate<'db>(
// FIXME: We probably don't want to expose this.
pub trait MacroCallIdExt {
- fn loc(self, db: &dyn HirDatabase) -> hir_expand::MacroCallLoc;
+ fn loc(self, db: &dyn HirDatabase) -> &hir_expand::MacroCallLoc;
}
impl MacroCallIdExt for span::MacroCallId {
#[inline]
- fn loc(self, db: &dyn HirDatabase) -> hir_expand::MacroCallLoc {
+ fn loc(self, db: &dyn HirDatabase) -> &hir_expand::MacroCallLoc {
hir_expand::MacroCallId::from(self).loc(db)
}
}
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index a1bbe47188..d0202c1054 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -1323,7 +1323,7 @@ impl<'db> SemanticsImpl<'db> {
.map(|(call_id, item)| {
let item_range = item.syntax().text_range();
let loc = call_id.loc(db);
- let text_range = match loc.kind {
+ let text_range = match &loc.kind {
hir_expand::MacroCallKind::Attr {
censored_attr_ids: attr_ids,
..
@@ -2436,7 +2436,7 @@ impl<'db> SemanticsImpl<'db> {
AnyImplId::ImplId(id) => id,
AnyImplId::BuiltinDeriveImplId(id) => return Some(id.loc(self.db).adt.into()),
};
- let source = hir_def::src::HasSource::ast_ptr(&id.loc(self.db), self.db);
+ let source = hir_def::src::HasSource::ast_ptr(id.loc(self.db), self.db);
let mut file_id = source.file_id;
let adt_ast_id = loop {
let macro_call = file_id.macro_file()?;
diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs
index f70bb3353f..b8c14dc09f 100644
--- a/crates/ide/src/navigation_target.rs
+++ b/crates/ide/src/navigation_target.rs
@@ -964,7 +964,7 @@ pub(crate) fn orig_range_with_focus_r(
// *should* contain the name
_ => {
let call = call();
- let kind = call.kind;
+ let kind = &call.kind;
let range = kind.clone().original_call_range_with_input(db);
//If the focus range is in the attribute/derive body, we
// need to point the call site to the entire body, if not, fall back