Skip to content

fix(diagnostics): exclude table header bracket from unused dependency underline - #17618

Closed
NUAAwqy wants to merge 1 commit into
rust-lang:masterfrom
NUAAwqy:fix/unused-dep-span-trailing-bracket
Closed

NUAAwqy wants to merge 1 commit into
rust-lang:masterfrom
NUAAwqy:fix/unused-dep-span-trailing-bracket

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 21, 2026

Copy link
Copy Markdown

What does this PR try to resolve?

Fixes #17609

For dependencies defined with table header syntax (e.g. [dependencies.foo]), the value span returned by get_key_value covers the whole table header, including its closing ]. The unused-dependency diagnostic underlined key.start..value.end, so the underline dragged the stray ] into the diagnostic:

warning: unused dependency `sp1-zkvm`
  --> Cargo.toml:14:15
   |
14 | [dependencies.sp1-zkvm]
   |               ^^^^^^^^^

With this change, header-defined tables underline only the dependency key:

warning: unused dependency `sp1-zkvm`
  --> Cargo.toml:14:15
   |
14 | [dependencies.sp1-zkvm]
   |               ^^^^^^^^

Inline tables (foo = { .. }) and plain key-value entries (foo = "1.0") are unaffected and keep the full key..value span. The same fix is applied to both the normal-dependency and build-dependency call sites in unused_dependencies.rs.

Notes to reviewers

The probe that motivated the detection rule: for a header-defined table the value span starts with [ (it covers the entire header), while for an inline table it starts with {. dep_underline_span keys off that distinction.

Verified locally:

  • cargo test --test testsuite lints::unused_dependencies — all 25 tests pass, including the new unused_dep_table_header_syntax.
  • The new test fails on master (underline includes ]) and passes with the fix.

🤖 LLM involvement: An LLM assistant (Claude) was used to investigate the issue, draft the fix and the regression test, and prepare this PR. All code was reviewed and the tests were run locally by the author.

… underline

For dependencies defined with table header syntax (e.g.
`[dependencies.foo]`), the value span of the table covers the whole
header including its closing `]`. The unused-dependency diagnostic
underlined `key.start..value.end`, so the underline included a stray
`]` (and, for non-empty tables, spanned the header bracket as well).

Underline only the dependency key for header-defined tables; inline
tables and plain key-value entries keep the full `key..value` span.

Fixes rust-lang#17609

Signed-off-by: wqyuan <wqyuan@users.noreply.github.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2026
@rustbot

rustbot commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @epage (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage, weihanglo

@weihanglo

Copy link
Copy Markdown
Member

This PR, as disclosed, was created with LLM assistance, but has no pre-arranged reviewers for LLM generated changes, so closing.

@weihanglo weihanglo closed this Oct 21, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2026
@weihanglo

Copy link
Copy Markdown
Member

Also your PR activity seems to be LLM automation. This is not allowed in any repositories under rust-lang organization per our policies. We are thus restricting you from creating pull requests and comments.

Thanks for your understanding.

Weihang in the name of the mod team

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minor off-by-one error in the span underlnie of "unused dependency" warning

5 participants