remove redundant flat vs nested distinction to simplify enum
This commit is contained in:
parent
829338a640
commit
2c26072d8c
@ -268,9 +268,8 @@ fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId, nested
|
||||
|
||||
enum UnusedSpanResult {
|
||||
Used,
|
||||
FlatUnused { span: Span, remove: Span },
|
||||
NestedFullUnused { spans: Vec<Span>, remove: Span },
|
||||
NestedPartialUnused { spans: Vec<Span>, remove: Vec<Span> },
|
||||
Unused { spans: Vec<Span>, remove: Span },
|
||||
PartialUnused { spans: Vec<Span>, remove: Vec<Span> },
|
||||
}
|
||||
|
||||
fn calc_unused_spans(
|
||||
@ -288,14 +287,14 @@ fn calc_unused_spans(
|
||||
match use_tree.kind {
|
||||
ast::UseTreeKind::Simple(..) | ast::UseTreeKind::Glob => {
|
||||
if unused_import.unused.contains(&use_tree_id) {
|
||||
UnusedSpanResult::FlatUnused { span: use_tree.span, remove: full_span }
|
||||
UnusedSpanResult::Unused { spans: vec![use_tree.span], remove: full_span }
|
||||
} else {
|
||||
UnusedSpanResult::Used
|
||||
}
|
||||
}
|
||||
ast::UseTreeKind::Nested(ref nested) => {
|
||||
if nested.is_empty() {
|
||||
return UnusedSpanResult::FlatUnused { span: use_tree.span, remove: full_span };
|
||||
return UnusedSpanResult::Unused { spans: vec![use_tree.span], remove: full_span };
|
||||
}
|
||||
|
||||
let mut unused_spans = Vec::new();
|
||||
@ -308,15 +307,11 @@ fn calc_unused_spans(
|
||||
all_nested_unused = false;
|
||||
None
|
||||
}
|
||||
UnusedSpanResult::FlatUnused { span, remove } => {
|
||||
unused_spans.push(span);
|
||||
Some(remove)
|
||||
}
|
||||
UnusedSpanResult::NestedFullUnused { mut spans, remove } => {
|
||||
UnusedSpanResult::Unused { mut spans, remove } => {
|
||||
unused_spans.append(&mut spans);
|
||||
Some(remove)
|
||||
}
|
||||
UnusedSpanResult::NestedPartialUnused { mut spans, remove: mut to_remove_extra } => {
|
||||
UnusedSpanResult::PartialUnused { mut spans, remove: mut to_remove_extra } => {
|
||||
all_nested_unused = false;
|
||||
unused_spans.append(&mut spans);
|
||||
to_remove.append(&mut to_remove_extra);
|
||||
@ -349,9 +344,9 @@ fn calc_unused_spans(
|
||||
if unused_spans.is_empty() {
|
||||
UnusedSpanResult::Used
|
||||
} else if all_nested_unused {
|
||||
UnusedSpanResult::NestedFullUnused { spans: unused_spans, remove: full_span }
|
||||
UnusedSpanResult::Unused { spans: unused_spans, remove: full_span }
|
||||
} else {
|
||||
UnusedSpanResult::NestedPartialUnused { spans: unused_spans, remove: to_remove }
|
||||
UnusedSpanResult::PartialUnused { spans: unused_spans, remove: to_remove }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -417,15 +412,11 @@ pub(crate) fn check_unused(&mut self, krate: &ast::Crate) {
|
||||
let mut fixes = Vec::new();
|
||||
let spans = match calc_unused_spans(unused, &unused.use_tree, unused.use_tree_id) {
|
||||
UnusedSpanResult::Used => continue,
|
||||
UnusedSpanResult::FlatUnused { span, remove } => {
|
||||
fixes.push((remove, String::new()));
|
||||
vec![span]
|
||||
}
|
||||
UnusedSpanResult::NestedFullUnused { spans, remove } => {
|
||||
UnusedSpanResult::Unused { spans, remove } => {
|
||||
fixes.push((remove, String::new()));
|
||||
spans
|
||||
}
|
||||
UnusedSpanResult::NestedPartialUnused { spans, remove } => {
|
||||
UnusedSpanResult::PartialUnused { spans, remove } => {
|
||||
for fix in &remove {
|
||||
fixes.push((*fix, String::new()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user