mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
simplify
This commit is contained in:
parent
c5049bdcda
commit
3eddda6f4c
@ -781,12 +781,10 @@ fn attr_macro_as_call_id(
|
||||
macro_attr: &Attr,
|
||||
db: &dyn db::DefDatabase,
|
||||
krate: CrateId,
|
||||
def: Option<MacroDefId>,
|
||||
) -> Result<MacroCallId, UnresolvedMacro> {
|
||||
def: MacroDefId,
|
||||
) -> MacroCallId {
|
||||
let attr_path = &item_attr.path;
|
||||
let def = def.ok_or_else(|| UnresolvedMacro { path: attr_path.clone() })?;
|
||||
let last_segment =
|
||||
attr_path.segments().last().ok_or_else(|| UnresolvedMacro { path: attr_path.clone() })?;
|
||||
let last_segment = attr_path.segments().last().expect("empty attribute path");
|
||||
let mut arg = match macro_attr.input.as_deref() {
|
||||
Some(attr::AttrInput::TokenTree(tt, map)) => (tt.clone(), map.clone()),
|
||||
_ => Default::default(),
|
||||
@ -805,5 +803,5 @@ fn attr_macro_as_call_id(
|
||||
invoc_attr_index: macro_attr.id.ast_index,
|
||||
},
|
||||
);
|
||||
Ok(res)
|
||||
res
|
||||
}
|
||||
|
@ -1124,10 +1124,13 @@ impl DefCollector<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
let def = resolver(path.clone()).filter(MacroDefId::is_attribute);
|
||||
let def = match resolver(path.clone()) {
|
||||
Some(def) if def.is_attribute() => def,
|
||||
_ => return true,
|
||||
};
|
||||
if matches!(
|
||||
def,
|
||||
Some(MacroDefId { kind:MacroDefKind::BuiltInAttr(expander, _),.. })
|
||||
MacroDefId { kind:MacroDefKind::BuiltInAttr(expander, _),.. }
|
||||
if expander.is_derive()
|
||||
) {
|
||||
// Resolved to `#[derive]`
|
||||
@ -1184,10 +1187,9 @@ impl DefCollector<'_> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not resolved to a derive helper or the derive attribute, so try to resolve as a normal attribute.
|
||||
match attr_macro_as_call_id(file_ast_id, attr, self.db, self.def_map.krate, def)
|
||||
{
|
||||
Ok(call_id) => {
|
||||
// Not resolved to a derive helper or the derive attribute, so try to treat as a normal attribute.
|
||||
let call_id =
|
||||
attr_macro_as_call_id(file_ast_id, attr, self.db, self.def_map.krate, def);
|
||||
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call_id);
|
||||
|
||||
// Skip #[test]/#[bench] expansion, which would merely result in more memory usage
|
||||
@ -1204,12 +1206,10 @@ impl DefCollector<'_> {
|
||||
if exp.is_dummy() {
|
||||
// Proc macros that cannot be expanded are treated as not
|
||||
// resolved, in order to fall back later.
|
||||
self.def_map.diagnostics.push(
|
||||
DefDiagnostic::unresolved_proc_macro(
|
||||
self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
|
||||
directive.module_id,
|
||||
loc.kind,
|
||||
),
|
||||
);
|
||||
));
|
||||
|
||||
return recollect_without(self);
|
||||
}
|
||||
@ -1228,9 +1228,6 @@ impl DefCollector<'_> {
|
||||
res = ReachedFixedPoint::No;
|
||||
return false;
|
||||
}
|
||||
Err(UnresolvedMacro { .. }) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
|
Loading…
x
Reference in New Issue
Block a user