Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/attr_resolution.rs')
-rw-r--r--crates/hir-def/src/nameres/attr_resolution.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/hir-def/src/nameres/attr_resolution.rs b/crates/hir-def/src/nameres/attr_resolution.rs
index 2f56d608fc..062b55fcef 100644
--- a/crates/hir-def/src/nameres/attr_resolution.rs
+++ b/crates/hir-def/src/nameres/attr_resolution.rs
@@ -2,7 +2,7 @@
use base_db::Crate;
use hir_expand::{
- MacroCallId, MacroCallKind, MacroDefId,
+ AttrMacroAttrIds, MacroCallId, MacroCallKind, MacroDefId,
attrs::{Attr, AttrId, AttrInput},
inert_attr_macro::find_builtin_attr_idx,
mod_path::{ModPath, PathKind},
@@ -12,7 +12,7 @@ use syntax::ast;
use triomphe::Arc;
use crate::{
- AstIdWithPath, LocalModuleId, MacroId, UnresolvedMacro,
+ AstIdWithPath, MacroId, ModuleId, UnresolvedMacro,
db::DefDatabase,
item_scope::BuiltinShadowMode,
nameres::{LocalDefMap, path_resolution::ResolveMode},
@@ -28,13 +28,15 @@ pub enum ResolvedAttr {
}
impl DefMap {
+ /// This cannot be used to resolve items that allow derives.
pub(crate) fn resolve_attr_macro(
&self,
local_def_map: &LocalDefMap,
db: &dyn DefDatabase,
- original_module: LocalModuleId,
+ original_module: ModuleId,
ast_id: AstIdWithPath<ast::Item>,
attr: &Attr,
+ attr_id: AttrId,
) -> Result<ResolvedAttr, UnresolvedMacro> {
// NB: does not currently work for derive helpers as they aren't recorded in the `DefMap`
@@ -61,13 +63,16 @@ impl DefMap {
return Ok(ResolvedAttr::Other);
}
}
- None => return Err(UnresolvedMacro { path: ast_id.path.as_ref().clone() }),
+ None => return Err(UnresolvedMacro { path: (*ast_id.path).clone() }),
};
Ok(ResolvedAttr::Macro(attr_macro_as_call_id(
db,
&ast_id,
attr,
+ // There aren't any active attributes before this one, because attribute macros
+ // replace their input, and derive macros are not allowed in this function.
+ AttrMacroAttrIds::from_one(attr_id),
self.krate,
db.macro_def(def),
)))
@@ -102,13 +107,14 @@ pub(super) fn attr_macro_as_call_id(
db: &dyn DefDatabase,
item_attr: &AstIdWithPath<ast::Item>,
macro_attr: &Attr,
+ censored_attr_ids: AttrMacroAttrIds,
krate: Crate,
def: MacroDefId,
) -> MacroCallId {
let arg = match macro_attr.input.as_deref() {
Some(AttrInput::TokenTree(tt)) => {
let mut tt = tt.clone();
- tt.top_subtree_delimiter_mut().kind = tt::DelimiterKind::Invisible;
+ tt.set_top_subtree_delimiter_kind(tt::DelimiterKind::Invisible);
Some(tt)
}
@@ -121,7 +127,7 @@ pub(super) fn attr_macro_as_call_id(
MacroCallKind::Attr {
ast_id: item_attr.ast_id,
attr_args: arg.map(Arc::new),
- invoc_attr_index: macro_attr.id,
+ censored_attr_ids,
},
macro_attr.ctxt,
)
@@ -139,7 +145,7 @@ pub(super) fn derive_macro_as_call_id(
) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> {
let (macro_id, def_id) = resolver(&item_attr.path)
.filter(|(_, def_id)| def_id.is_derive())
- .ok_or_else(|| UnresolvedMacro { path: item_attr.path.as_ref().clone() })?;
+ .ok_or_else(|| UnresolvedMacro { path: (*item_attr.path).clone() })?;
let call_id = def_id.make_call(
db,
krate,