Skip to content

Fixes for missing_asserts_for_indexing #14108

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

Conversation

vishruth-thimmaiah
Copy link
Contributor

This PR fixes issues with the missing_asserts_for_indexing lint.

  • false positive when the first index is the highest(or equal) value in a list of indexes:
pub fn foo(slice: &[i32]) -> i32{
	slice[1] * slice[0]
}
  • false negative when an assert statement if found after the indexing operation.
pub fn bar(slice: &[i32]) -> i32 {
	let product = slice[0] * slice[1];
	assert!(slice.len() > 1);
	product
}

examples: https://godbolt.org/z/s7Y47vKdE

closes: #14079

changelog: [missing_asserts_for_indexing]: ignore asserts found after indexing, and do not require asserts if the first index is highest.

@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 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 Jan 30, 2025
@llogiq
Copy link
Contributor

llogiq commented Mar 1, 2025

Thank you!

@llogiq llogiq added this pull request to the merge queue Mar 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 1, 2025
@samueltardieu samueltardieu added this pull request to the merge queue Apr 6, 2025
@samueltardieu
Copy link
Contributor

Requeued for merging, patch state is clean.

Merged via the queue into rust-lang:master with commit cf9cffa Apr 6, 2025
11 checks passed
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.

False positives and false negatives for clippy::missing_asserts_for_indexing.
4 participants