Skip to content

Split assert - #16677

Open
jcarey9149 wants to merge 6 commits into
rust-lang:masterfrom
jcarey9149:split_assert
Open

Split assert#16677
jcarey9149 wants to merge 6 commits into
rust-lang:masterfrom
jcarey9149:split_assert

Conversation

@jcarey9149

@jcarey9149 jcarey9149 commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

View all comments

Closes #1810

changelog: [assert_multiple]: Add a lint for asserts with multiple boolean tests

@rustbot rustbot added the needs-fcp PRs that add, remove, or rename lints and need an FCP label Mar 6, 2026
@jcarey9149

Copy link
Copy Markdown
Contributor Author

Sadly, I accidentally deleted the branch connected to my previous PR, causing it to close. @ada4a

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown

Lintcheck changes for 054f2c8

Lint Added Removed Changed
clippy::assert_multiple 51 0 0

This comment will be updated if you push new changes

@ada4a

ada4a commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Sadly, I accidentally deleted the branch connected to my previous PR, causing it to close.

Happens to the best of us, don't worry...

Looking at Lintcheck, there seem to be some classes of cases where we don't really want to lint:

  • the assertion has a message – it usually presents information about everything that is asserted, so we shouldn't be splitting that up; and even if it didn't, we wouldn't know which of the newly assert we should move the message into
  • assertions of the form n < x && x < m – splitting these would look unnatural imo, but I guess that's the whole premise of the lint... not sure, let me know what you think

@ada4a ada4a left a comment

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.

A bit more review.. I hope this will resolve the mystery of the missing suggestions

View changes since this review

Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
@jcarey9149

Copy link
Copy Markdown
Contributor Author

Sadly, I accidentally deleted the branch connected to my previous PR, causing it to close.

Happens to the best of us, don't worry...

Looking at Lintcheck, there seem to be some classes of cases where we don't really want to lint:

  • the assertion has a message – it usually presents information about everything that is asserted, so we shouldn't be splitting that up; and even if it didn't, we wouldn't know which of the newly assert we should move the message into
  • assertions of the form n < x && x < m – splitting these would look unnatural imo, but I guess that's the whole premise of the lint... not sure, let me know what you think

I'm not sure I understand the comment about lintcheck. can you clarify please?

This is based on issue 1810.

@ada4a

ada4a commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Ah, sorry. Lintcheck is a thing where the PR is run on a bunch of popular crates, in order to see if the lint is doing the right thing, and catch false positives. You can see its results in #16677 (comment) by clicking on the clippy::assert_multiple thing

Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
@ada4a

ada4a commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

in the changelog message, the lint name should be in backticks (`), not in quotes (')

@jcarey9149

Copy link
Copy Markdown
Contributor Author

My latest update passes most tests, but the clippy test complains about collapsing my span_lint_and_then call into one (?) line. cargo dev fmt has a different idea.

How does this get resolved?

On the other front, it now supports debug_assert!() as well as assert!(). I also improved the handling of Or.

@ada4a

ada4a commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

the clippy test complains about collapsing my span_lint_and_then call into one (?) line

Ah no, it also suggests switching to span_lint_and_sugg (instead of span_lint_and_then). The reason it fires is because the then closure only contains one operation. This is an internal lint I personally dislike, but that's a topic for another time. For now, you can copy its suggestion:

span_lint_and_sugg(cx, ASSERT_MULTIPLE, e.span, "multiple asserts combined into one", "consider writing", am_visitor.suggests.join("\n"), Applicability::MaybeIncorrect)

Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
@ada4a

ada4a commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Also, I'm not sure how you ended up putting a bunch of other people's commits onto your branch?.. Try git pull --rebase && git rebase master or something

@jcarey9149

Copy link
Copy Markdown
Contributor Author

@ada4a Any comments?

@ada4a

ada4a commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Sorry, hadn't had the time to look at this yet, I'll probably do so tomorrow

Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread tests/ui/assert_multiple.rs
Comment thread clippy_lints/src/assert_multiple.rs Outdated
@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 Mar 14, 2026
@rustbot

rustbot commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator

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

@jcarey9149
jcarey9149 marked this pull request as ready for review March 16, 2026 15:09
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 16, 2026
@rustbot

rustbot commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

r? @samueltardieu

rustbot has assigned @samueltardieu.
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: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Mar 16, 2026
@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Mar 16, 2026
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread clippy_lints/src/lib.rs Outdated
ManualNoopWaker: manual_noop_waker::ManualNoopWaker = manual_noop_waker::ManualNoopWaker::new(conf),
ByteCharSlice: byte_char_slices::ByteCharSlice = byte_char_slices::ByteCharSlice,
ManualAssertEq: manual_assert_eq::ManualAssertEq = manual_assert_eq::ManualAssertEq,
AssertMultiple: assert_multiple::AssertMultiple = assert_multiple::AssertMultiple,

@samueltardieu samueltardieu Jun 1, 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.

Indentation level is incorrect

View changes since the review

@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.

Also, it looks like assert!() with a message will loose the message when split. See lintcheck output for examples. Please include tests where there is an extra message.

View changes since this review

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@jcarey9149

Copy link
Copy Markdown
Contributor Author

Also, it looks like assert!() with a message will loose the message when split. See lintcheck output for examples. Please include tests where there is an extra message.

Thanks for pointing this out. I'll look into it.

@ada4a

ada4a commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Sorry for all the waiting Jim, I seem to not have the energy to bring this to completion. Let me reroll..

@rustbot reroll

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@llogiq llogiq left a comment

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.

I left a few comments.

View changes since this review

Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
Comment thread clippy_lints/src/assert_multiple.rs Outdated
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@jcarey9149

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

jcarey9149 and others added 2 commits July 25, 2026 15:24
Apply suggestions from code review
Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

jcarey9149 and others added 2 commits July 26, 2026 13:30
Apply suggestions from code review
Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
@rustbot

rustbot commented Jul 26, 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

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust-clippy.git master
    $ git push --force-with-lease
    

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

Labels

has-merge-commits PR has merge commits, merge with caution. needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) 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.

Extensions to should_assert_eq

5 participants