Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
new lint:
unnecessary_indexing
#12464base: master
Are you sure you want to change the base?
new lint:
unnecessary_indexing
#12464Changes from 7 commits
d3e174a
bc4ce99
cfa97d5
e8efc1a
b54aaa3
672eba5
299bcfd
4109424
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use
if let Some(ident) = first_local.pat.simple_ident()
we can useident.name
later instead of getting a snippet from the pat's spanThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should push all the suggestions into one vec and use
multipart_suggestion
at the end for all the changes, multiple span suggestions are presented as alternatives rather than something to combine in e.g. rust-analyzerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be confident that our suggestion won't require dereferencing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a callback to #12464 (comment) we could make this a bool and check it before returning to ditch the field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will false negative for any code that mutates unrelated things
Something like
would narrow it down to only things that mutate our input, it should also let us remove this check and lint when the type is
&mut [T]
/&mut Vec<T>
(assuming it works)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A step further would be to not break immediately but store a
bool
that we've seen a mutation and break in theif let ExprKind::Index(receiver, index, _)
if it'strue
This would be since it doesn't matter if the code is mutating the input as long as it comes after all the indexes we're modifying: