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