Auto merge of #15357 - Veykril:mismatched-macro-def-call, r=Veykril
fix: Do not create fn macro calls with non-fn expanders Fixes https://github.com/rust-lang/rust-analyzer/issues/15327
This commit is contained in:
commit
ebcd25d46c
@ -1155,18 +1155,22 @@ fn macro_call_as_call_id_(
|
|||||||
let def =
|
let def =
|
||||||
resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?;
|
resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?;
|
||||||
|
|
||||||
let res = if let MacroDefKind::BuiltInEager(..) = def.kind {
|
let res = match def.kind {
|
||||||
let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db));
|
MacroDefKind::BuiltInEager(..) => {
|
||||||
expand_eager_macro_input(db, krate, macro_call, def, &resolver)?
|
let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db));
|
||||||
} else {
|
expand_eager_macro_input(db, krate, macro_call, def, &|path| {
|
||||||
ExpandResult {
|
resolver(path).filter(MacroDefId::is_fn_like)
|
||||||
|
})?
|
||||||
|
}
|
||||||
|
_ if def.is_fn_like() => ExpandResult {
|
||||||
value: Some(def.as_lazy_macro(
|
value: Some(def.as_lazy_macro(
|
||||||
db,
|
db,
|
||||||
krate,
|
krate,
|
||||||
MacroCallKind::FnLike { ast_id: call.ast_id, expand_to },
|
MacroCallKind::FnLike { ast_id: call.ast_id, expand_to },
|
||||||
)),
|
)),
|
||||||
err: None,
|
err: None,
|
||||||
}
|
},
|
||||||
|
_ => return Err(UnresolvedMacro { path: call.path.clone() }),
|
||||||
};
|
};
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
@ -1251,6 +1255,7 @@ fn derive_macro_as_call_id(
|
|||||||
resolver: impl Fn(path::ModPath) -> Option<(MacroId, MacroDefId)>,
|
resolver: impl Fn(path::ModPath) -> Option<(MacroId, MacroDefId)>,
|
||||||
) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> {
|
) -> Result<(MacroId, MacroDefId, MacroCallId), UnresolvedMacro> {
|
||||||
let (macro_id, def_id) = resolver(item_attr.path.clone())
|
let (macro_id, def_id) = resolver(item_attr.path.clone())
|
||||||
|
.filter(|(_, def_id)| def_id.is_derive())
|
||||||
.ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
|
.ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
|
||||||
let call_id = def_id.as_lazy_macro(
|
let call_id = def_id.as_lazy_macro(
|
||||||
db.upcast(),
|
db.upcast(),
|
||||||
|
@ -415,6 +415,24 @@ impl MacroDefId {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_derive(&self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self.kind,
|
||||||
|
MacroDefKind::BuiltInDerive(..)
|
||||||
|
| MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_fn_like(&self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self.kind,
|
||||||
|
MacroDefKind::BuiltIn(..)
|
||||||
|
| MacroDefKind::ProcMacro(_, ProcMacroKind::FuncLike, _)
|
||||||
|
| MacroDefKind::BuiltInEager(..)
|
||||||
|
| MacroDefKind::Declarative(..)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_attribute_derive(&self) -> bool {
|
pub fn is_attribute_derive(&self) -> bool {
|
||||||
matches!(self.kind, MacroDefKind::BuiltInAttr(expander, ..) if expander.is_derive())
|
matches!(self.kind, MacroDefKind::BuiltInAttr(expander, ..) if expander.is_derive())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user