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 {
|
enum UnusedSpanResult {
|
||||||
Used,
|
Used,
|
||||||
FlatUnused { span: Span, remove: Span },
|
Unused { spans: Vec<Span>, remove: Span },
|
||||||
NestedFullUnused { spans: Vec<Span>, remove: Span },
|
PartialUnused { spans: Vec<Span>, remove: Vec<Span> },
|
||||||
NestedPartialUnused { spans: Vec<Span>, remove: Vec<Span> },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calc_unused_spans(
|
fn calc_unused_spans(
|
||||||
@ -288,14 +287,14 @@ fn calc_unused_spans(
|
|||||||
match use_tree.kind {
|
match use_tree.kind {
|
||||||
ast::UseTreeKind::Simple(..) | ast::UseTreeKind::Glob => {
|
ast::UseTreeKind::Simple(..) | ast::UseTreeKind::Glob => {
|
||||||
if unused_import.unused.contains(&use_tree_id) {
|
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 {
|
} else {
|
||||||
UnusedSpanResult::Used
|
UnusedSpanResult::Used
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::UseTreeKind::Nested(ref nested) => {
|
ast::UseTreeKind::Nested(ref nested) => {
|
||||||
if nested.is_empty() {
|
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();
|
let mut unused_spans = Vec::new();
|
||||||
@ -308,15 +307,11 @@ fn calc_unused_spans(
|
|||||||
all_nested_unused = false;
|
all_nested_unused = false;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
UnusedSpanResult::FlatUnused { span, remove } => {
|
UnusedSpanResult::Unused { mut spans, remove } => {
|
||||||
unused_spans.push(span);
|
|
||||||
Some(remove)
|
|
||||||
}
|
|
||||||
UnusedSpanResult::NestedFullUnused { mut spans, remove } => {
|
|
||||||
unused_spans.append(&mut spans);
|
unused_spans.append(&mut spans);
|
||||||
Some(remove)
|
Some(remove)
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedPartialUnused { mut spans, remove: mut to_remove_extra } => {
|
UnusedSpanResult::PartialUnused { mut spans, remove: mut to_remove_extra } => {
|
||||||
all_nested_unused = false;
|
all_nested_unused = false;
|
||||||
unused_spans.append(&mut spans);
|
unused_spans.append(&mut spans);
|
||||||
to_remove.append(&mut to_remove_extra);
|
to_remove.append(&mut to_remove_extra);
|
||||||
@ -349,9 +344,9 @@ fn calc_unused_spans(
|
|||||||
if unused_spans.is_empty() {
|
if unused_spans.is_empty() {
|
||||||
UnusedSpanResult::Used
|
UnusedSpanResult::Used
|
||||||
} else if all_nested_unused {
|
} else if all_nested_unused {
|
||||||
UnusedSpanResult::NestedFullUnused { spans: unused_spans, remove: full_span }
|
UnusedSpanResult::Unused { spans: unused_spans, remove: full_span }
|
||||||
} else {
|
} 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 mut fixes = Vec::new();
|
||||||
let spans = match calc_unused_spans(unused, &unused.use_tree, unused.use_tree_id) {
|
let spans = match calc_unused_spans(unused, &unused.use_tree, unused.use_tree_id) {
|
||||||
UnusedSpanResult::Used => continue,
|
UnusedSpanResult::Used => continue,
|
||||||
UnusedSpanResult::FlatUnused { span, remove } => {
|
UnusedSpanResult::Unused { spans, remove } => {
|
||||||
fixes.push((remove, String::new()));
|
|
||||||
vec![span]
|
|
||||||
}
|
|
||||||
UnusedSpanResult::NestedFullUnused { spans, remove } => {
|
|
||||||
fixes.push((remove, String::new()));
|
fixes.push((remove, String::new()));
|
||||||
spans
|
spans
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedPartialUnused { spans, remove } => {
|
UnusedSpanResult::PartialUnused { spans, remove } => {
|
||||||
for fix in &remove {
|
for fix in &remove {
|
||||||
fixes.push((*fix, String::new()));
|
fixes.push((*fix, String::new()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user