minor: simplify

This commit is contained in:
Aleksey Kladov 2021-12-28 16:51:17 +03:00
parent 56b51852c2
commit 177a183e85

View file

@ -448,8 +448,8 @@ impl<'db> SemanticsImpl<'db> {
} }
fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<MacroDef>> { fn resolve_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<MacroDef>> {
let macro_call_ids = self.derive_macro_calls(attr)?; let res = self
let res = macro_call_ids .derive_macro_calls(attr)?
.iter() .iter()
.map(|&call| { .map(|&call| {
let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call); let loc: MacroCallLoc = self.db.lookup_intern_macro_call(call);
@ -460,9 +460,8 @@ impl<'db> SemanticsImpl<'db> {
} }
fn expand_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<SyntaxNode>> { fn expand_derive_macro(&self, attr: &ast::Attr) -> Option<Vec<SyntaxNode>> {
let macro_call_ids = self.derive_macro_calls(attr)?; let res: Vec<_> = self
.derive_macro_calls(attr)?
let expansions: Vec<_> = macro_call_ids
.iter() .iter()
.map(|call| call.as_file()) .map(|call| call.as_file())
.flat_map(|file_id| { .flat_map(|file_id| {
@ -471,12 +470,7 @@ impl<'db> SemanticsImpl<'db> {
Some(node) Some(node)
}) })
.collect(); .collect();
Some(res)
if expansions.is_empty() {
None
} else {
Some(expansions)
}
} }
fn derive_macro_calls(&self, attr: &ast::Attr) -> Option<Vec<MacroCallId>> { fn derive_macro_calls(&self, attr: &ast::Attr) -> Option<Vec<MacroCallId>> {