Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
829338a
add enum variant field names to make the code clearer
pietroalbini Apr 1, 2024
2c26072
remove redundant flat vs nested distinction to simplify enum
pietroalbini Apr 1, 2024
2ec337c
turn all_nested_unused into used_childs
pietroalbini Apr 1, 2024
13f7623
store the span of the nested part of the use tree in the ast
pietroalbini Apr 1, 2024
2d3a9a5
remove braces when fixing a nested use tree into a single use
pietroalbini Apr 14, 2024
397a35d
crashes: add lastest batch of crash tests
matthiaskrgr May 5, 2024
1d9d671
Make sure we don't deny macro vars w keyword names
compiler-errors May 7, 2024
b68b920
Simplify `use crate::rustc_foo::bar` occurrences.
nnethercote May 8, 2024
fbc2abd
Update cc crate to v1.0.97
jfgoog May 8, 2024
767711b
Use generic `NonZero` in examples.
reitermarkus Apr 23, 2024
3fe0be9
Simplify `clippy` lint.
reitermarkus Apr 23, 2024
7531eaf
Simplify suggestion.
reitermarkus Apr 23, 2024
bd8e565
Use generic `NonZero`.
reitermarkus Apr 21, 2024
14bdce1
Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb
matthiaskrgr May 8, 2024
d174a49
Rollup merge of #124587 - reitermarkus:use-generic-nonzero, r=dtolnay
matthiaskrgr May 8, 2024
6b92d9a
Rollup merge of #124775 - matthiaskrgr:boom, r=jieyouxu
matthiaskrgr May 8, 2024
cae0a91
Rollup merge of #124869 - compiler-errors:keyword, r=Nilstrieb
matthiaskrgr May 8, 2024
a12aff2
Rollup merge of #124876 - nnethercote:rm-use-crate-rustc_foo, r=compi…
matthiaskrgr May 8, 2024
dcf1c57
Rollup merge of #124892 - jfgoog:update-cc, r=workingjubilee
matthiaskrgr May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add enum variant field names to make the code clearer
  • Loading branch information
pietroalbini committed Apr 14, 2024
commit 829338a64016cd50fc766649d53cf5ea0b27284f
26 changes: 13 additions & 13 deletions compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ impl<'a, 'b, 'tcx> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {

enum UnusedSpanResult {
Used,
FlatUnused(Span, Span),
NestedFullUnused(Vec<Span>, Span),
NestedPartialUnused(Vec<Span>, Vec<Span>),
FlatUnused { span: Span, remove: Span },
NestedFullUnused { spans: Vec<Span>, remove: Span },
NestedPartialUnused { spans: Vec<Span>, remove: Vec<Span> },
}

fn calc_unused_spans(
Expand All @@ -288,14 +288,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(use_tree.span, full_span)
UnusedSpanResult::FlatUnused { span: use_tree.span, remove: full_span }
} else {
UnusedSpanResult::Used
}
}
ast::UseTreeKind::Nested(ref nested) => {
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();
Expand All @@ -308,15 +308,15 @@ fn calc_unused_spans(
all_nested_unused = false;
None
}
UnusedSpanResult::FlatUnused(span, remove) => {
UnusedSpanResult::FlatUnused { span, remove } => {
unused_spans.push(span);
Some(remove)
}
UnusedSpanResult::NestedFullUnused(mut spans, remove) => {
UnusedSpanResult::NestedFullUnused { mut spans, remove } => {
unused_spans.append(&mut spans);
Some(remove)
}
UnusedSpanResult::NestedPartialUnused(mut spans, mut to_remove_extra) => {
UnusedSpanResult::NestedPartialUnused { mut spans, remove: mut to_remove_extra } => {
all_nested_unused = false;
unused_spans.append(&mut spans);
to_remove.append(&mut to_remove_extra);
Expand Down Expand Up @@ -349,9 +349,9 @@ fn calc_unused_spans(
if unused_spans.is_empty() {
UnusedSpanResult::Used
} else if all_nested_unused {
UnusedSpanResult::NestedFullUnused(unused_spans, full_span)
UnusedSpanResult::NestedFullUnused { spans: unused_spans, remove: full_span }
} else {
UnusedSpanResult::NestedPartialUnused(unused_spans, to_remove)
UnusedSpanResult::NestedPartialUnused { spans: unused_spans, remove: to_remove }
}
}
}
Expand Down Expand Up @@ -417,15 +417,15 @@ impl Resolver<'_, '_> {
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) => {
UnusedSpanResult::FlatUnused { span, remove } => {
fixes.push((remove, String::new()));
vec![span]
}
UnusedSpanResult::NestedFullUnused(spans, remove) => {
UnusedSpanResult::NestedFullUnused { spans, remove } => {
fixes.push((remove, String::new()));
spans
}
UnusedSpanResult::NestedPartialUnused(spans, remove) => {
UnusedSpanResult::NestedPartialUnused { spans, remove } => {
for fix in &remove {
fixes.push((*fix, String::new()));
}
Expand Down