Skip to content
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

Fixes for missing_asserts_for_indexing #14108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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
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.
3 participants