Skip to content

missing_asserts_for_indexing: consider assert_eq!() as well #14258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Feb 20, 2025

assert_eq!() and assert_ne!() are not expanded the same way as assert!() (they use a match instead of a if). This makes them being recognized as well.

Fix #14255

changelog: [missing_asserts_for_indexing]: consider assert_eq!() as well

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

r? @llogiq

rustbot has assigned @llogiq.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 20, 2025
} else if let Some((macro_call, bin_op)) =
first_node_macro_backtrace(cx, expr).find_map(|macro_call| match cx.tcx.item_name(macro_call.def_id).as_str() {
"assert_eq" => Some((macro_call, BinOpKind::Eq)),
"assert_ne" => Some((macro_call, BinOpKind::Ne)),
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use the symbols directly here (for example https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/sym/constant.assert_ne_macro.html) instead of matching on strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Updated.

@rustbot

This comment has been minimized.

`assert_eq!()` and `assert_ne!()` are not expanded the same way as
`assert!()` (they use a `match` instead of a `if`). This makes them
being recognized as well.
@samueltardieu
Copy link
Contributor Author

Rebased

@samueltardieu samueltardieu deleted the push-oonokpytsqrp branch April 10, 2025 10:58
@samueltardieu samueltardieu restored the push-oonokpytsqrp branch April 15, 2025 17:55
@samueltardieu samueltardieu reopened this Apr 15, 2025
@samueltardieu
Copy link
Contributor Author

Looks like it was closed by mistake, reopening.

@samueltardieu
Copy link
Contributor Author

r? clippy

@rustbot rustbot assigned Centri3 and unassigned llogiq Apr 15, 2025
@samueltardieu
Copy link
Contributor Author

r? clippy

@rustbot rustbot assigned Manishearth and unassigned Centri3 Apr 15, 2025
@Manishearth Manishearth added this pull request to the merge queue Apr 15, 2025
Merged via the queue into rust-lang:master with commit 459897b Apr 15, 2025
22 of 24 checks passed
@samueltardieu samueltardieu deleted the push-oonokpytsqrp branch April 15, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

missing_asserts_for_indexing understands assert!(x.len()==2) but not assert_eq!(x.len(), 2)
6 participants