style: remove unnecessary macro

This commit is contained in:
davidsemakula 2024-01-30 16:15:15 +03:00
parent 84e13145ff
commit dba3fc4425

View file

@ -256,23 +256,14 @@ pub fn try_normalize_use_tree(
Some(use_tree) Some(use_tree)
} }
macro_rules! call_and_track_result {
($call:expr, $tracker: ident) => {
let result = $call;
if !$tracker && result.is_some() {
$tracker = true;
}
};
}
pub fn try_normalize_use_tree_mut( pub fn try_normalize_use_tree_mut(
use_tree: &ast::UseTree, use_tree: &ast::UseTree,
style: NormalizationStyle, style: NormalizationStyle,
) -> Option<()> { ) -> Option<()> {
if style == NormalizationStyle::One { if style == NormalizationStyle::One {
let mut modified = false; let mut modified = false;
call_and_track_result!(use_tree.wrap_in_tree_list(), modified); modified |= use_tree.wrap_in_tree_list().is_some();
call_and_track_result!(recursive_normalize(use_tree, style), modified); modified |= recursive_normalize(use_tree, style).is_some();
if !modified { if !modified {
// Either the use tree was already normalized or its semantically empty. // Either the use tree was already normalized or its semantically empty.
return None; return None;
@ -374,10 +365,9 @@ fn recursive_normalize(use_tree: &ast::UseTree, style: NormalizationStyle) -> Op
if let Some(sub_one_tree_list) = one_style_tree_list(&sub_sub_tree) { if let Some(sub_one_tree_list) = one_style_tree_list(&sub_sub_tree) {
curr_skipped.extend(sub_one_tree_list.use_trees()); curr_skipped.extend(sub_one_tree_list.use_trees());
} else { } else {
call_and_track_result!( modified |=
recursive_normalize(&sub_sub_tree, NormalizationStyle::Default), recursive_normalize(&sub_sub_tree, NormalizationStyle::Default)
modified .is_some();
);
add_element_to_list( add_element_to_list(
sub_sub_tree.syntax().clone().into(), sub_sub_tree.syntax().clone().into(),
&mut elements, &mut elements,
@ -401,10 +391,7 @@ fn recursive_normalize(use_tree: &ast::UseTree, style: NormalizationStyle) -> Op
} }
modified = true; modified = true;
} else { } else {
call_and_track_result!( modified |= recursive_normalize(&subtree, NormalizationStyle::Default).is_some();
recursive_normalize(&subtree, NormalizationStyle::Default),
modified
);
} }
} }
@ -451,7 +438,7 @@ fn recursive_normalize(use_tree: &ast::UseTree, style: NormalizationStyle) -> Op
// Merge the remaining subtree into its parent, if its only one and // Merge the remaining subtree into its parent, if its only one and
// the normalization style is not "one". // the normalization style is not "one".
if subtrees.len() == 1 && style != NormalizationStyle::One { if subtrees.len() == 1 && style != NormalizationStyle::One {
call_and_track_result!(merge_subtree_into_parent_tree(&subtrees[0]), modified); modified |= merge_subtree_into_parent_tree(&subtrees[0]).is_some();
} }
// Order the remaining subtrees (if necessary). // Order the remaining subtrees (if necessary).
if subtrees.len() > 1 { if subtrees.len() > 1 {