Skip to content

Add new lint: manual_assert_matches#17118

Open
lcian wants to merge 5 commits into
rust-lang:masterfrom
lcian:feat/manual-assert-matches
Open

Add new lint: manual_assert_matches#17118
lcian wants to merge 5 commits into
rust-lang:masterfrom
lcian:feat/manual-assert-matches

Conversation

@lcian

@lcian lcian commented May 30, 2026

Copy link
Copy Markdown

Close #17111

changelog: [manual_assert_matches]: Add new lint: manual_assert_matches

@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label May 30, 2026
Comment thread clippy_lints/src/lib.rs
@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown

Lintcheck changes for 1f8fa37

Lint Added Removed Changed
clippy::manual_assert_matches 2 0 0

This comment will be updated if you push new changes

Comment thread clippy_lints/src/manual_assert_matches.rs

@samueltardieu samueltardieu left a comment

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.

I am not sure you need an early collector pass.

When you check an expression, if it comes from expansion, you can use first_node_macro_backtrace() from clippy_utils::macros to get the succession of macro calls. You can then match them against one of the *assert! macros (see is_assert_macro()), then against matches!() (by checking it is the right diagnostic item). This is much more robust than comparing strings.

View changes since this review

@rustbot

rustbot commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label May 30, 2026
@lcian

lcian commented May 30, 2026

Copy link
Copy Markdown
Author

Thank you @samueltardieu!
I wrongly assumed that not enough of the pre-expansion information would be contained in the HIR.
That's why I was pretty surprised to read that pre-expansion passes are considered deprecated (https://github.com/rust-lang/rust/blob/f8a08b688cbe60acc386ed1fbd1b7cbaaf5576b1/compiler/rustc_lint/src/context.rs#L175).
I'm now rewriting this using only a late pass, it seems that will be sufficient indeed.

@rustbot

This comment has been minimized.

@lcian lcian force-pushed the feat/manual-assert-matches branch from 00ca9c0 to 4de4469 Compare June 7, 2026 21:49
@lcian lcian force-pushed the feat/manual-assert-matches branch from 4de4469 to 17bd309 Compare June 7, 2026 21:55
@lcian

lcian commented Jun 8, 2026

Copy link
Copy Markdown
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 8, 2026
@lcian lcian marked this pull request as ready for review June 8, 2026 07:10
@rustbot

rustbot commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @samueltardieu (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

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

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New lint proposal: manual_assert_matches

3 participants