minor: dedup
This commit is contained in:
parent
726da9884b
commit
56b51852c2
@ -10,7 +10,7 @@
|
||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||
AsMacroCall, FunctionId, TraitId, VariantId,
|
||||
};
|
||||
use hir_expand::{name::AsName, ExpansionInfo, MacroCallLoc};
|
||||
use hir_expand::{name::AsName, ExpansionInfo, MacroCallId, MacroCallLoc};
|
||||
use hir_ty::{associated_type_shorthand_candidates, Interner};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
@ -448,13 +448,7 @@ fn expand_attr_macro(&self, item: &ast::Item) -> Option<SyntaxNode> {
|
||||
}
|
||||
|
||||
fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<MacroDef>> {
|
||||
let item = attr.syntax().parent().and_then(ast::Item::cast)?;
|
||||
let file_id = self.find_file(item.syntax()).file_id;
|
||||
let item = InFile::new(file_id, &item);
|
||||
let src = InFile::new(file_id, attr.clone());
|
||||
self.with_ctx(|ctx| {
|
||||
let macro_call_ids = ctx.attr_to_derive_macro_call(item, src)?;
|
||||
|
||||
let macro_call_ids = self.derive_macro_calls(attr)?;
|
||||
let res = macro_call_ids
|
||||
.iter()
|
||||
.map(|&call| {
|
||||
@ -463,16 +457,10 @@ fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<MacroDef>> {
|
||||
})
|
||||
.collect();
|
||||
Some(res)
|
||||
})
|
||||
}
|
||||
|
||||
fn expand_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<SyntaxNode>> {
|
||||
let item = attr.syntax().parent().and_then(ast::Item::cast)?;
|
||||
let file_id = self.find_file(item.syntax()).file_id;
|
||||
let item = InFile::new(file_id, &item);
|
||||
let src = InFile::new(file_id, attr.clone());
|
||||
self.with_ctx(|ctx| {
|
||||
let macro_call_ids = ctx.attr_to_derive_macro_call(item, src)?;
|
||||
let macro_call_ids = self.derive_macro_calls(attr)?;
|
||||
|
||||
let expansions: Vec<_> = macro_call_ids
|
||||
.iter()
|
||||
@ -483,11 +471,22 @@ fn expand_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<SyntaxNode>> {
|
||||
Some(node)
|
||||
})
|
||||
.collect();
|
||||
|
||||
if expansions.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(expansions)
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_macro_calls(&self, attr: &ast::Attr) -> Option<Vec<MacroCallId>> {
|
||||
let item = attr.syntax().parent().and_then(ast::Item::cast)?;
|
||||
let file_id = self.find_file(item.syntax()).file_id;
|
||||
let item = InFile::new(file_id, &item);
|
||||
let src = InFile::new(file_id, attr.clone());
|
||||
self.with_ctx(|ctx| {
|
||||
let res = ctx.attr_to_derive_macro_call(item, src)?;
|
||||
Some(res.to_vec())
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user