Skip to content

Use fine grained component-wise span tracking in use trees#153838

Open
oli-obk wants to merge 2 commits intorust-lang:mainfrom
oli-obk:use-tree-span
Open

Use fine grained component-wise span tracking in use trees#153838
oli-obk wants to merge 2 commits intorust-lang:mainfrom
oli-obk:use-tree-span

Conversation

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 13, 2026

This often produces nicer spans and even doesn't need a Span field anymore (not that I expect the unused field to affect any perf, but still neat).

@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2026

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 13, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

|
LL - with_crate!{$crate input TokenItem}
LL + with_crate!{token_site_span::TokenItem as _ input TokenItem}
LL + with_crate!{token_site_span::TokenItem as _}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These suggestions are now even more broken than before, but considering it was broken before, I think we should just leave it

@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[TIMING:end] tool::ToolBuild { build_compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, tool: "tidy", path: "src/tools/tidy", mode: ToolBootstrap, source_type: InTree, extra_features: [], allow_features: "", cargo_args: [], artifact_kind: Binary } -- 12.641
[TIMING:end] tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_ast/src/ast.rs:3358:
             _ => panic!("`UseTree::ident` can only be used on a simple import"),
         }
     }
-    
+
     pub fn span(&self) -> Span {
         self.prefix.span.to(self.hi_span())
     }
Diff in /checkout/compiler/rustc_ast/src/ast.rs:3365:
-    
+
     pub fn hi_span(&self) -> Span {
         match self.kind {
             UseTreeKind::Simple(None) => self.prefix.span,
Diff in /checkout/compiler/rustc_resolve/src/check_unused.rs:309:
         }
         ast::UseTreeKind::Nested { items: ref nested, span: tree_span } => {
             if nested.is_empty() {
-                return UnusedSpanResult::Unused { spans: vec![use_tree.span()], remove: full_span };
+                return UnusedSpanResult::Unused {
+                    spans: vec![use_tree.span()],
+                    remove: full_span,
+                };
             }
 
             let mut unused_spans = Vec::new();
Diff in /checkout/compiler/rustc_resolve/src/check_unused.rs:379:
                 if used_children == 1 && !contains_self {
                     // Left brace, from the start of the nested group to the first item.
                     to_remove.push(
-                        tree_span.shrink_to_lo().to(nested.first().unwrap().0.prefix.span.shrink_to_lo()),
+                        tree_span.shrink_to_lo().to(nested
+                            .first()
+                            .unwrap()
+                            .0
+                            .prefix
+                            .span
+                            .shrink_to_lo()),
                     );
                     // Right brace, from the end of the last item to the end of the nested group.
                     to_remove.push(
Diff in /checkout/compiler/rustc_resolve/src/check_unused.rs:386:
-                        nested.last().unwrap().0.hi_span().shrink_to_hi().to(tree_span.shrink_to_hi()),
+                        nested
+                            .last()
+                            .unwrap()
+                            .0
+                            .hi_span()
+                            .shrink_to_hi()
+                            .to(tree_span.shrink_to_hi()),
                     );
                 }
 
Diff in /checkout/compiler/rustc_resolve/src/build_reduced_graph.rs:606:
             Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.is_rust_2015() => {
                 Some(seg.ident.span.ctxt())
             }
-            None if let ast::UseTreeKind::Glob(span) = use_tree.kind && span.is_rust_2015() => Some(span.ctxt()),
+            None if let ast::UseTreeKind::Glob(span) = use_tree.kind
+                && span.is_rust_2015() =>
+            {
+                Some(span.ctxt())
+            }
             _ => None,
         }
         .map(|ctxt| {
fmt: checked 6742 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:00:45
  local time: Fri Mar 13 21:05:13 UTC 2026
  network time: Fri, 13 Mar 2026 21:05:13 GMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants