Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/declarative.rs')
-rw-r--r--crates/hir-expand/src/declarative.rs36
1 files changed, 20 insertions, 16 deletions
diff --git a/crates/hir-expand/src/declarative.rs b/crates/hir-expand/src/declarative.rs
index fef77acb7b..1fa682ce3a 100644
--- a/crates/hir-expand/src/declarative.rs
+++ b/crates/hir-expand/src/declarative.rs
@@ -1,18 +1,19 @@
//! Compiled declarative macro expanders (`macro_rules!` and `macro`)
-use base_db::CrateId;
+use base_db::Crate;
use intern::sym;
-use span::{Edition, HirFileIdRepr, MacroCallId, Span, SyntaxContextId};
+use span::{Edition, Span, SyntaxContext};
use stdx::TupleExt;
-use syntax::{ast, AstNode};
+use syntax::{AstNode, ast};
use syntax_bridge::DocCommentDesugarMode;
use triomphe::Arc;
use crate::{
+ AstId, ExpandError, ExpandErrorKind, ExpandResult, HirFileId, Lookup, MacroCallId,
attrs::RawAttrs,
db::ExpandDatabase,
- hygiene::{apply_mark, Transparency},
- tt, AstId, ExpandError, ExpandErrorKind, ExpandResult, Lookup,
+ hygiene::{Transparency, apply_mark},
+ tt,
};
/// Old-style `macro_rules` or the new macros 2.0
@@ -41,7 +42,10 @@ impl DeclarativeMacroExpander {
.mac
.expand(
&tt,
- |s| s.ctx = apply_mark(db, s.ctx, call_id, self.transparency, self.edition),
+ |s| {
+ s.ctx =
+ apply_mark(db, s.ctx, call_id.into(), self.transparency, self.edition)
+ },
span,
loc.def.edition,
)
@@ -70,7 +74,7 @@ impl DeclarativeMacroExpander {
pub(crate) fn expander(
db: &dyn ExpandDatabase,
- def_crate: CrateId,
+ def_crate: Crate,
id: AstId<ast::Macro>,
) -> Arc<DeclarativeMacroExpander> {
let (root, map) = crate::db::parse_with_map(db, id.file_id);
@@ -84,7 +88,7 @@ impl DeclarativeMacroExpander {
.find(|it| {
it.path
.as_ident()
- .map(|it| *it == sym::rustc_macro_transparency.clone())
+ .map(|it| *it == sym::rustc_macro_transparency)
.unwrap_or(false)
})?
.token_tree_value()?
@@ -100,14 +104,14 @@ impl DeclarativeMacroExpander {
_ => None,
}
};
- let ctx_edition = |ctx: SyntaxContextId| {
- let crate_graph = db.crate_graph();
+ let ctx_edition = |ctx: SyntaxContext| {
if ctx.is_root() {
- crate_graph[def_crate].edition
+ def_crate.data(db).edition
} else {
- let data = db.lookup_intern_syntax_context(ctx);
// UNWRAP-SAFETY: Only the root context has no outer expansion
- crate_graph[data.outer_expn.unwrap().lookup(db).def.krate].edition
+ let krate =
+ db.lookup_intern_macro_call(ctx.outer_expn(db).unwrap().into()).def.krate;
+ krate.data(db).edition
}
};
let (mac, transparency) = match id.to_ptr(db).to_node(&root) {
@@ -160,9 +164,9 @@ impl DeclarativeMacroExpander {
transparency(&macro_def).unwrap_or(Transparency::Opaque),
),
};
- let edition = ctx_edition(match id.file_id.repr() {
- HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id.lookup(db).ctxt,
- HirFileIdRepr::FileId(file) => SyntaxContextId::root(file.edition()),
+ let edition = ctx_edition(match id.file_id {
+ HirFileId::MacroFile(macro_file) => macro_file.lookup(db).ctxt,
+ HirFileId::FileId(file) => SyntaxContext::root(file.edition(db)),
});
Arc::new(DeclarativeMacroExpander { mac, transparency, edition })
}