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

Suppress iter_on_empty_collections if the iterator's concrete type is relied upon #12823

Merged
merged 5 commits into from
May 27, 2024

Conversation

its-the-shrimp
Copy link
Contributor

changelog: fixed #12807

@rustbot
Copy link
Collaborator

rustbot commented May 19, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 19, 2024
@its-the-shrimp
Copy link
Contributor Author

its-the-shrimp commented May 19, 2024

ice-11065 test failing? But I didn't touch anything outside of the lint in question, what do I do?..

@Alexendoo
Copy link
Member

r? @y21

@rustbot rustbot assigned y21 and unassigned Alexendoo May 20, 2024
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

There are still lots of similar-ish false positives with the type unification checks in this lint (for example, this won't suppress the lint for mem::replace(&mut /* Iter<()> */, [].iter()), or /* Option<Iter<()>> */.unwrap_or([].iter())).

But they seem orthogonal to this change (and have existed before) so I don't really consider them a blocker for this PR. Small improvements are always great.

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

LGTM, can you squash the commits (or at least the "fix fmt"/"initial fix" ones)?

let arg_id_in_args = args.into_iter().position(|e| e.hir_id == arg_id).unwrap();
let arg_ty_in_args = fn_sig.input(arg_id_in_args);

cx.tcx.predicates_of(fn_id).predicates.iter().any(|(clause, _)| {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe an interesting followup (in addition to looking through predicates, doesn't need to be done in this PR) would be to run a type visitor through each parameter type and check if the argument type is in there. I.e. when we have fn<T>(&mut T, T) and the argument maps to T, figure out that it unifies with the &mut T parameter. That would catch both of the false positives I mentioned before (mem::replace & unwrap_or).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added that as well & added a use of std::mem::replace to the tests, seems to be fine, not linted

@its-the-shrimp its-the-shrimp requested a review from y21 May 27, 2024 13:48
@y21
Copy link
Member

y21 commented May 27, 2024

Sorry for the delay, forgot about this one.

Nice to see even those two false positives fixed. Thanks! @bors r+

@bors
Copy link
Collaborator

bors commented May 27, 2024

📌 Commit 7439ecb has been approved by y21

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 27, 2024

⌛ Testing commit 7439ecb with merge 76eee82...

@bors
Copy link
Collaborator

bors commented May 27, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: y21
Pushing 76eee82 to master...

@bors bors merged commit 76eee82 into rust-lang:master May 27, 2024
5 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.

iter_on_empty_collections's suggestion causes a compilation error
5 participants