-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Don't trigger while_let_on_iterator when the iterator is recreated every iteration #5525
Conversation
if_chain! { | ||
if let ExprKind::MethodCall(..) | ExprKind::Call(..) = iter_expr.kind; | ||
if let Some(iter_def_id) = get_trait_def_id(cx, &paths::ITERATOR); | ||
if implements_trait(cx, cx.tables.expr_ty(iter_expr), iter_def_id, &[]); |
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.
Just to make sure I understand correctly: this is checking that the scrutinee is not a call to an iter
method, right?
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.
It is checking, that a (method) call before the next
call does not return a type, that implements Iterator
. Should I add a comment?
This does not cover this:
#[derive(Debug, Clone)]
struct S<'a> {
chars: std::str::CharIndices<'a>,
}
while let Some(_) = s.clone().chars.next() {
break;
}
But then again, if the struct is clonable, every field is clonable (in general), and this should be changed to s.chars.clone().next()
, which prevents the lint from triggering.
@bors r+ |
📌 Commit a182622 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1, this pull request will be tested once the tree is reopened |
@bors treeclosed- |
💔 Test failed - checks-action_test |
@bors retry |
💔 Test failed - checks-action_test |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
r? @phansch
Fixes #1654
changelog: Fix false positive in [
while_let_on_iterator
]