mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Store crate info in MacroDefId
This commit is contained in:
parent
128dc5355b
commit
8cd23a4fb8
@ -119,7 +119,7 @@ impl HasSource for TypeAlias {
|
||||
impl HasSource for MacroDef {
|
||||
type Ast = ast::MacroCall;
|
||||
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::MacroCall> {
|
||||
Source { file_id: self.id.0.file_id(), ast: self.id.0.to_node(db) }
|
||||
Source { file_id: self.id.ast_id.file_id(), ast: self.id.ast_id.to_node(db) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use ra_syntax::{ast, AstNode, Parse, SyntaxNode};
|
||||
|
||||
use crate::{
|
||||
db::{AstDatabase, DefDatabase, InternDatabase},
|
||||
AstId, FileAstId, Module, Source,
|
||||
AstId, Crate, FileAstId, Module, Source,
|
||||
};
|
||||
|
||||
/// hir makes heavy use of ids: integer (u32) handlers to various things. You
|
||||
@ -121,10 +121,13 @@ impl From<FileId> for HirFileId {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct MacroDefId(pub(crate) AstId<ast::MacroCall>);
|
||||
pub struct MacroDefId {
|
||||
pub(crate) ast_id: AstId<ast::MacroCall>,
|
||||
pub(crate) krate: Crate,
|
||||
}
|
||||
|
||||
pub(crate) fn macro_def_query(db: &impl AstDatabase, id: MacroDefId) -> Option<Arc<MacroRules>> {
|
||||
let macro_call = id.0.to_node(db);
|
||||
let macro_call = id.ast_id.to_node(db);
|
||||
let arg = macro_call.token_tree()?;
|
||||
let (tt, _) = mbe::ast_to_token_tree(&arg).or_else(|| {
|
||||
log::warn!("fail on macro_def to token tree: {:#?}", arg);
|
||||
|
@ -662,7 +662,10 @@ where
|
||||
// Case 1: macro rules, define a macro in crate-global mutable scope
|
||||
if is_macro_rules(&mac.path) {
|
||||
if let Some(name) = &mac.name {
|
||||
let macro_id = MacroDefId(mac.ast_id.with_file_id(self.file_id));
|
||||
let macro_id = MacroDefId {
|
||||
ast_id: mac.ast_id.with_file_id(self.file_id),
|
||||
krate: self.def_collector.def_map.krate,
|
||||
};
|
||||
let macro_ = MacroDef { id: macro_id };
|
||||
self.def_collector.define_macro(self.module_id, name.clone(), macro_, mac.export);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user