store the span of the nested part of the use tree in the ast

This commit is contained in:
Pietro Albini 2024-04-02 00:26:10 +02:00
parent 2e989dc280
commit f0f392781f
4 changed files with 9 additions and 9 deletions

View File

@ -201,8 +201,8 @@ fn track_uses(
if segments.is_empty() { if segments.is_empty() {
// keep track of `use {some_module, some_other_module};` usages // keep track of `use {some_module, some_other_module};` usages
if let UseTreeKind::Nested(trees) = &use_tree.kind { if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
for tree in trees { for tree in items {
let segments = &tree.0.prefix.segments; let segments = &tree.0.prefix.segments;
if segments.len() == 1 { if segments.len() == 1 {
if let UseTreeKind::Simple(None) = tree.0.kind { if let UseTreeKind::Simple(None) = tree.0.kind {
@ -229,8 +229,8 @@ fn track_uses(
} }
// nested case such as `use self::{module1::Struct1, module2::Struct2}` // nested case such as `use self::{module1::Struct1, module2::Struct2}`
if let UseTreeKind::Nested(trees) = &use_tree.kind { if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
for tree in trees { for tree in items {
let segments = &tree.0.prefix.segments; let segments = &tree.0.prefix.segments;
if !segments.is_empty() { if !segments.is_empty() {
imports_reused_with_self.push(segments[0].ident.name); imports_reused_with_self.push(segments[0].ident.name);

View File

@ -36,8 +36,8 @@
impl EarlyLintPass for UnnecessarySelfImports { impl EarlyLintPass for UnnecessarySelfImports {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if let ItemKind::Use(use_tree) = &item.kind if let ItemKind::Use(use_tree) = &item.kind
&& let UseTreeKind::Nested(nodes) = &use_tree.kind && let UseTreeKind::Nested { items, .. } = &use_tree.kind
&& let [(self_tree, _)] = &**nodes && let [(self_tree, _)] = &**items
&& let [self_seg] = &*self_tree.prefix.segments && let [self_seg] = &*self_tree.prefix.segments
&& self_seg.ident.name == kw::SelfLower && self_seg.ident.name == kw::SelfLower
&& let Some(last_segment) = use_tree.prefix.segments.last() && let Some(last_segment) = use_tree.prefix.segments.last()

View File

@ -49,8 +49,8 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
unsafe_to_safe_check(old_name, new_name, cx, span); unsafe_to_safe_check(old_name, new_name, cx, span);
}, },
UseTreeKind::Simple(None) | UseTreeKind::Glob => {}, UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
UseTreeKind::Nested(ref nested_use_tree) => { UseTreeKind::Nested { ref items, .. } => {
for (use_tree, _) in nested_use_tree { for (use_tree, _) in items {
check_use_tree(use_tree, cx, span); check_use_tree(use_tree, cx, span);
} }
}, },

View File

@ -637,7 +637,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
match (l, r) { match (l, r) {
(Glob, Glob) => true, (Glob, Glob) => true,
(Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)), (Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)),
(Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), (Nested { items: l, .. }, Nested { items: r, .. }) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
_ => false, _ => false,
} }
} }