add enum variant field names to make the code clearer
This commit is contained in:
parent
a8a88fe524
commit
829338a640
@ -268,9 +268,9 @@ fn visit_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId, nested
|
|||||||
|
|
||||||
enum UnusedSpanResult {
|
enum UnusedSpanResult {
|
||||||
Used,
|
Used,
|
||||||
FlatUnused(Span, Span),
|
FlatUnused { span: Span, remove: Span },
|
||||||
NestedFullUnused(Vec<Span>, Span),
|
NestedFullUnused { spans: Vec<Span>, remove: Span },
|
||||||
NestedPartialUnused(Vec<Span>, Vec<Span>),
|
NestedPartialUnused { spans: Vec<Span>, remove: Vec<Span> },
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calc_unused_spans(
|
fn calc_unused_spans(
|
||||||
@ -288,14 +288,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(use_tree.span, full_span)
|
UnusedSpanResult::FlatUnused { span: 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(use_tree.span, full_span);
|
return UnusedSpanResult::FlatUnused { span: use_tree.span, remove: full_span };
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut unused_spans = Vec::new();
|
let mut unused_spans = Vec::new();
|
||||||
@ -308,15 +308,15 @@ fn calc_unused_spans(
|
|||||||
all_nested_unused = false;
|
all_nested_unused = false;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
UnusedSpanResult::FlatUnused(span, remove) => {
|
UnusedSpanResult::FlatUnused { span, remove } => {
|
||||||
unused_spans.push(span);
|
unused_spans.push(span);
|
||||||
Some(remove)
|
Some(remove)
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedFullUnused(mut spans, remove) => {
|
UnusedSpanResult::NestedFullUnused { mut spans, remove } => {
|
||||||
unused_spans.append(&mut spans);
|
unused_spans.append(&mut spans);
|
||||||
Some(remove)
|
Some(remove)
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedPartialUnused(mut spans, mut to_remove_extra) => {
|
UnusedSpanResult::NestedPartialUnused { 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 +349,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(unused_spans, full_span)
|
UnusedSpanResult::NestedFullUnused { spans: unused_spans, remove: full_span }
|
||||||
} else {
|
} else {
|
||||||
UnusedSpanResult::NestedPartialUnused(unused_spans, to_remove)
|
UnusedSpanResult::NestedPartialUnused { spans: unused_spans, remove: to_remove }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -417,15 +417,15 @@ 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::FlatUnused { span, remove } => {
|
||||||
fixes.push((remove, String::new()));
|
fixes.push((remove, String::new()));
|
||||||
vec![span]
|
vec![span]
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedFullUnused(spans, remove) => {
|
UnusedSpanResult::NestedFullUnused { spans, remove } => {
|
||||||
fixes.push((remove, String::new()));
|
fixes.push((remove, String::new()));
|
||||||
spans
|
spans
|
||||||
}
|
}
|
||||||
UnusedSpanResult::NestedPartialUnused(spans, remove) => {
|
UnusedSpanResult::NestedPartialUnused { 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