Skip to content

Add new lint: manual_assert_matches - #17118

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

Add new lint: manual_assert_matches#17118
lcian wants to merge 6 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 89f7a41

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 2 times, most recently 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

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 11, 2026
@lcian
lcian force-pushed the feat/manual-assert-matches branch from 43b81cc to d708cdf Compare June 11, 2026 17:10
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 11, 2026
@rustbot

This comment has been minimized.

@lcian
lcian force-pushed the feat/manual-assert-matches branch from d708cdf to 0522992 Compare June 16, 2026 16:24
@rustbot

This comment has been minimized.

@lcian
lcian requested a review from samueltardieu June 16, 2026 16:24
@rustbot

This comment has been minimized.

@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 6, 2026
@lcian
lcian force-pushed the feat/manual-assert-matches branch from af2c00f to ea37ee5 Compare July 6, 2026 07:17
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jul 6, 2026
@lcian
lcian marked this pull request as draft July 6, 2026 07:42
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 6, 2026
@rustbot

This comment has been minimized.

@lcian
lcian force-pushed the feat/manual-assert-matches branch from b628ebb to 89f7a41 Compare July 7, 2026 19:20
@lcian
lcian marked this pull request as ready for review July 7, 2026 19:43
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 7, 2026
@rustbot

rustbot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #15000) made this pull request unmergeable. Please resolve the merge conflicts.

@lcian
lcian marked this pull request as draft July 13, 2026 11:56
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 13, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New lint proposal: manual_assert_matches

3 participants