mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Store #[derive]
attribute ID along macro invoc
This commit is contained in:
parent
546da15972
commit
c0dd36fd42
5 changed files with 22 additions and 12 deletions
|
@ -62,7 +62,7 @@ use hir_expand::{
|
||||||
ast_id_map::FileAstId,
|
ast_id_map::FileAstId,
|
||||||
eager::{expand_eager_macro, ErrorEmitted, ErrorSink},
|
eager::{expand_eager_macro, ErrorEmitted, ErrorSink},
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene,
|
||||||
AstId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
|
AstId, AttrId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
|
||||||
};
|
};
|
||||||
use la_arena::Idx;
|
use la_arena::Idx;
|
||||||
use nameres::DefMap;
|
use nameres::DefMap;
|
||||||
|
@ -699,6 +699,7 @@ fn macro_call_as_call_id(
|
||||||
|
|
||||||
fn derive_macro_as_call_id(
|
fn derive_macro_as_call_id(
|
||||||
item_attr: &AstIdWithPath<ast::Item>,
|
item_attr: &AstIdWithPath<ast::Item>,
|
||||||
|
derive_attr: AttrId,
|
||||||
db: &dyn db::DefDatabase,
|
db: &dyn db::DefDatabase,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
|
resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
|
||||||
|
@ -712,6 +713,7 @@ fn derive_macro_as_call_id(
|
||||||
MacroCallKind::Derive {
|
MacroCallKind::Derive {
|
||||||
ast_id: item_attr.ast_id,
|
ast_id: item_attr.ast_id,
|
||||||
derive_name: last_segment.to_string(),
|
derive_name: last_segment.to_string(),
|
||||||
|
derive_attr,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.into();
|
.into();
|
||||||
|
|
|
@ -617,7 +617,7 @@ mod diagnostics {
|
||||||
let node = ast_id.to_node(db.upcast());
|
let node = ast_id.to_node(db.upcast());
|
||||||
(ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
|
(ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
|
||||||
}
|
}
|
||||||
MacroCallKind::Derive { ast_id, derive_name } => {
|
MacroCallKind::Derive { ast_id, derive_name, .. } => {
|
||||||
let node = ast_id.to_node(db.upcast());
|
let node = ast_id.to_node(db.upcast());
|
||||||
|
|
||||||
// Compute the precise location of the macro name's token in the derive
|
// Compute the precise location of the macro name's token in the derive
|
||||||
|
|
|
@ -13,7 +13,7 @@ use hir_expand::{
|
||||||
builtin_macro::find_builtin_macro,
|
builtin_macro::find_builtin_macro,
|
||||||
name::{AsName, Name},
|
name::{AsName, Name},
|
||||||
proc_macro::ProcMacroExpander,
|
proc_macro::ProcMacroExpander,
|
||||||
HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
|
AttrId, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
|
||||||
};
|
};
|
||||||
use hir_expand::{InFile, MacroCallLoc};
|
use hir_expand::{InFile, MacroCallLoc};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
@ -216,7 +216,7 @@ struct MacroDirective {
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
enum MacroDirectiveKind {
|
enum MacroDirectiveKind {
|
||||||
FnLike { ast_id: AstIdWithPath<ast::MacroCall> },
|
FnLike { ast_id: AstIdWithPath<ast::MacroCall> },
|
||||||
Derive { ast_id: AstIdWithPath<ast::Item> },
|
Derive { ast_id: AstIdWithPath<ast::Item>, derive_attr: AttrId },
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DefData<'a> {
|
struct DefData<'a> {
|
||||||
|
@ -831,10 +831,14 @@ impl DefCollector<'_> {
|
||||||
Err(UnresolvedMacro) | Ok(Err(_)) => {}
|
Err(UnresolvedMacro) | Ok(Err(_)) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MacroDirectiveKind::Derive { ast_id } => {
|
MacroDirectiveKind::Derive { ast_id, derive_attr } => {
|
||||||
match derive_macro_as_call_id(ast_id, self.db, self.def_map.krate, |path| {
|
match derive_macro_as_call_id(
|
||||||
self.resolve_derive_macro(directive.module_id, &path)
|
ast_id,
|
||||||
}) {
|
*derive_attr,
|
||||||
|
self.db,
|
||||||
|
self.def_map.krate,
|
||||||
|
|path| self.resolve_derive_macro(directive.module_id, &path),
|
||||||
|
) {
|
||||||
Ok(call_id) => {
|
Ok(call_id) => {
|
||||||
resolved.push((directive.module_id, call_id, directive.depth));
|
resolved.push((directive.module_id, call_id, directive.depth));
|
||||||
res = ReachedFixedPoint::No;
|
res = ReachedFixedPoint::No;
|
||||||
|
@ -1368,7 +1372,7 @@ impl ModCollector<'_, '_> {
|
||||||
self.def_collector.unexpanded_macros.push(MacroDirective {
|
self.def_collector.unexpanded_macros.push(MacroDirective {
|
||||||
module_id: self.module_id,
|
module_id: self.module_id,
|
||||||
depth: self.macro_depth + 1,
|
depth: self.macro_depth + 1,
|
||||||
kind: MacroDirectiveKind::Derive { ast_id },
|
kind: MacroDirectiveKind::Derive { ast_id, derive_attr: derive.id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,7 @@ mod tests {
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
use name::AsName;
|
use name::AsName;
|
||||||
|
|
||||||
use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc};
|
use crate::{test_db::TestDB, AstId, AttrId, MacroCallId, MacroCallKind, MacroCallLoc};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -317,7 +317,11 @@ $0
|
||||||
local_inner: false,
|
local_inner: false,
|
||||||
},
|
},
|
||||||
krate: CrateId(0),
|
krate: CrateId(0),
|
||||||
kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() },
|
kind: MacroCallKind::Derive {
|
||||||
|
ast_id,
|
||||||
|
derive_name: name.to_string(),
|
||||||
|
derive_attr: AttrId(0),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let id: MacroCallId = db.intern_macro(loc).into();
|
let id: MacroCallId = db.intern_macro(loc).into();
|
||||||
|
|
|
@ -291,7 +291,7 @@ pub struct MacroCallLoc {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum MacroCallKind {
|
pub enum MacroCallKind {
|
||||||
FnLike { ast_id: AstId<ast::MacroCall> },
|
FnLike { ast_id: AstId<ast::MacroCall> },
|
||||||
Derive { ast_id: AstId<ast::Item>, derive_name: String },
|
Derive { ast_id: AstId<ast::Item>, derive_name: String, derive_attr: AttrId },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue