Skip to content

feat(hints): extract mostly-unused diagnostics - #17457

Draft
0xPoe wants to merge 2 commits into
rust-lang:masterfrom
0xPoe:hint-mostly-unused-report
Draft

0xPoe wants to merge 2 commits into
rust-lang:masterfrom
0xPoe:hint-mostly-unused-report

Conversation

@0xPoe

@0xPoe 0xPoe commented Sep 8, 2026

Copy link
Copy Markdown
Member

What does this PR try to resolve?

Try to use annotate-snippets to report mostly unused warnings. Inspired by #17368 (comment).

How to test and review this PR?

Check the unit tests and review each commit individually.

r?@ghost

LLM disclosure: The unit tests were generated by AI.

@rustbot rustbot added the A-build-execution Area: anything dealing with executing the compiler label Sep 8, 2026
@0xPoe 0xPoe changed the title refactor(hints): extract mostly-unused diagnostics NOT READY FOR REVIEW: refactor(hints): extract mostly-unused diagnostics Sep 8, 2026
@0xPoe
0xPoe force-pushed the hint-mostly-unused-report branch from edcff6f to 930da71 Compare September 9, 2026 07:04

@0xPoe 0xPoe left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🔢 Self-check (PR reviewed by myself and ready for feedback)

  • Code compiles successfully

  • Unit tests added

  • No AI-generated elegant nonsense in PR.

  • Comments added where necessary

  • PR title and description updated

  • Documentation PR created (or confirmed not needed)

  • PR size is reasonable

r? @epage

View changes since this review

}

let bcx = create_bcx(ws, options, &interner, logger.as_ref())?;
crate::diagnostics::rules::mostly_unused_hint::diagnose(&bcx)?;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: The change moved diagnostics before compilation, so the same check now reports warnings even without rebuilding.

@0xPoe 0xPoe Sep 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe we already have some warnings reported even without rebuilding, so I guess this seems fine.

if gctx.cli_unstable().profile_hint_mostly_unused {
continue;
}
let profile_hint = unit.profile.hint_mostly_unused;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried to find its source, but doing so here is too complex. It would almost require us to reimplement the precedence resolution.

@0xPoe
0xPoe marked this pull request as ready for review September 9, 2026 07:15
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 9, 2026
@0xPoe 0xPoe changed the title NOT READY FOR REVIEW: refactor(hints): extract mostly-unused diagnostics refactor(hints): extract mostly-unused diagnostics Sep 9, 2026
Comment thread src/compiler/mod.rs
Comment thread src/compiler/mod.rs Outdated
Comment thread src/diagnostics/rules/mostly_unused_hint.rs Outdated
// Profile options come from the workspace itself, so they are reported even for
// non-local packages.
let title = format!(
"ignoring `hint-mostly-unused` profile option for `{}@{}`",

@epage epage Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we showing a package spec, rather than having an Origin element?

View changes since the review

@0xPoe 0xPoe Sep 13, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See #17457 (comment)

If we want to find the exact original element, we have to mirror its precedence resolution here. I tried it, but it seemed too complex, so I abandoned it. So I decided to simply hint that this package has a profile option that has been ignored.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But I’ll try to do it in the parse pass. I guess that would make it easier.

}

let bcx = create_bcx(ws, options, &interner, logger.as_ref())?;
crate::diagnostics::rules::mostly_unused_hint::diagnose(&bcx)?;

@epage epage Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should these be in the parse pass?

View changes since the review

mod manual_readme;
mod missing_lints_features;
mod missing_lints_inheritance;
pub mod mostly_unused_hint;

@weihanglo weihanglo Sep 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a bit weird being publibc. Should we give it a lint pass instead, or should we make a new lint pass for it?

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another diagnostic does this as we still work out what the diagnostic pass should look like. We only created a formal pass for parsing once we understood it.

@0xPoe
0xPoe force-pushed the hint-mostly-unused-report branch from 930da71 to 74fda82 Compare September 13, 2026 09:50
@0xPoe 0xPoe changed the title refactor(hints): extract mostly-unused diagnostics feat(hints): extract mostly-unused diagnostics Sep 13, 2026
@0xPoe
0xPoe force-pushed the hint-mostly-unused-report branch from 74fda82 to be89b18 Compare September 13, 2026 09:55
@0xPoe
0xPoe force-pushed the hint-mostly-unused-report branch from be89b18 to 9c72948 Compare September 13, 2026 10:05
@0xPoe
0xPoe marked this pull request as draft September 13, 2026 16:52
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants