From 2ec337c19336845b371dcd6bc1369e6b34124afd Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 1 Apr 2024 23:53:17 +0200 Subject: [PATCH] turn all_nested_unused into used_childs --- compiler/rustc_resolve/src/check_unused.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index 613709b0cb68..e054847fe5e7 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -299,12 +299,12 @@ fn calc_unused_spans( let mut unused_spans = Vec::new(); let mut to_remove = Vec::new(); - let mut all_nested_unused = true; + let mut used_childs = 0; let mut previous_unused = false; for (pos, (use_tree, use_tree_id)) in nested.iter().enumerate() { let remove = match calc_unused_spans(unused_import, use_tree, *use_tree_id) { UnusedSpanResult::Used => { - all_nested_unused = false; + used_childs += 1; None } UnusedSpanResult::Unused { mut spans, remove } => { @@ -312,7 +312,7 @@ fn calc_unused_spans( Some(remove) } UnusedSpanResult::PartialUnused { mut spans, remove: mut to_remove_extra } => { - all_nested_unused = false; + used_childs += 1; unused_spans.append(&mut spans); to_remove.append(&mut to_remove_extra); None @@ -321,7 +321,7 @@ fn calc_unused_spans( if let Some(remove) = remove { let remove_span = if nested.len() == 1 { remove - } else if pos == nested.len() - 1 || !all_nested_unused { + } else if pos == nested.len() - 1 || used_childs > 0 { // Delete everything from the end of the last import, to delete the // previous comma nested[pos - 1].0.span.shrink_to_hi().to(use_tree.span) @@ -343,7 +343,7 @@ fn calc_unused_spans( } if unused_spans.is_empty() { UnusedSpanResult::Used - } else if all_nested_unused { + } else if used_childs == 0 { UnusedSpanResult::Unused { spans: unused_spans, remove: full_span } } else { UnusedSpanResult::PartialUnused { spans: unused_spans, remove: to_remove }