Skip to content

Commit 2a8b4a2

Browse files
committed
Auto merge of rust-lang#17611 - Veykril:macro-arg-no-call, r=Veykril
fix: Don't call macro_arg directly in `ExpandDatabase::syntax_context`
2 parents 216bef3 + 811ce15 commit 2a8b4a2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/tools/rust-analyzer/crates/hir-expand/src/db.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::{
2121
span_map::{RealSpanMap, SpanMap, SpanMapRef},
2222
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander,
2323
CustomProcMacroExpander, EagerCallInfo, ExpandError, ExpandResult, ExpandTo, ExpansionSpanMap,
24-
HirFileId, HirFileIdRepr, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId, MacroDefKind,
25-
MacroFileId,
24+
HirFileId, HirFileIdRepr, Lookup, MacroCallId, MacroCallKind, MacroCallLoc, MacroDefId,
25+
MacroDefKind, MacroFileId,
2626
};
2727
/// This is just to ensure the types of smart_macro_arg and macro_arg are the same
2828
type MacroArgResult = (Arc<tt::Subtree>, SyntaxFixupUndoInfo, Span);
@@ -99,6 +99,7 @@ pub trait ExpandDatabase: SourceDatabase {
9999
/// Lowers syntactic macro call to a token tree representation. That's a firewall
100100
/// query, only typing in the macro call itself changes the returned
101101
/// subtree.
102+
#[deprecated = "calling this is incorrect, call `macro_arg_considering_derives` instead"]
102103
fn macro_arg(&self, id: MacroCallId) -> MacroArgResult;
103104
#[salsa::transparent]
104105
fn macro_arg_considering_derives(
@@ -140,7 +141,11 @@ pub trait ExpandDatabase: SourceDatabase {
140141
fn syntax_context(db: &dyn ExpandDatabase, file: HirFileId) -> SyntaxContextId {
141142
match file.repr() {
142143
HirFileIdRepr::FileId(_) => SyntaxContextId::ROOT,
143-
HirFileIdRepr::MacroFile(m) => db.macro_arg(m.macro_call_id).2.ctx,
144+
HirFileIdRepr::MacroFile(m) => {
145+
db.macro_arg_considering_derives(m.macro_call_id, &m.macro_call_id.lookup(db).kind)
146+
.2
147+
.ctx
148+
}
144149
}
145150
}
146151

@@ -393,6 +398,7 @@ pub(crate) fn parse_with_map(
393398
/// Other wise return the [macro_arg] for the macro_call_id.
394399
///
395400
/// This is not connected to the database so it does not cached the result. However, the inner [macro_arg] query is
401+
#[allow(deprecated)] // we are macro_arg_considering_derives
396402
fn macro_arg_considering_derives(
397403
db: &dyn ExpandDatabase,
398404
id: MacroCallId,

src/tools/rust-analyzer/crates/hir-expand/src/eager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn expand_eager_macro_input(
5454
ctxt: call_site,
5555
}
5656
.intern(db);
57+
#[allow(deprecated)] // builtin eager macros are never derives
5758
let (_, _, span) = db.macro_arg(arg_id);
5859
let ExpandResult { value: (arg_exp, arg_exp_map), err: parse_err } =
5960
db.parse_macro_expansion(arg_id.as_macro_file());

0 commit comments

Comments
 (0)