-
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
Add new lint iter_not_returning_iterator
#7610
Conversation
r? @camsteffen (rust-highfive has picked a reviewer for you, use r? to override) |
let parameters = fn_sig.decl.inputs; | ||
if parameters.is_empty() || parameters.len() > 1 { | ||
return; | ||
} |
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.
Why check for number of parameters?
Shouldn't this lint work for an iter that takes parameters other than self?
Or maybe this is covered by another lint?
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.
I think it should only detect fn iter(&self) -> _
before, because I think if it has more parameters it may have a different meaning, so this lint may not suit it.
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.
You can use if let [param] = fn_sig.decl.inputs
. The if_chain
s can be collapsed. Can you also check that the parameter is &self
?
if parameters.is_empty() || parameters.len() > 1 { | ||
return; | ||
} | ||
let iter_trait_id = get_trait_def_id(cx, &paths::ITERATOR).unwrap(); |
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 crash on any no_std
crate or maybe even when linting the standard library itself. You should just return when this trait can't be found.
@Labelray Thanks for the PR. This is a good idea. I do have one concern though... When GAT arrives (coming soon according to this blog post), iterators that are not |
Shouldn't this be covered by |
I think not. [ |
☔ The latest upstream changes (presumably #7604) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I think it's fine to have this lint until GATs arrive; the streaming iter trait might end up using a different signature, or we can check for both. Bit concerned the lint name is too long though. |
Will it be a good idea to name it as |
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.
For the lint name I'd suggest iter_not_returning_iterator
.
let parameters = fn_sig.decl.inputs; | ||
if parameters.is_empty() || parameters.len() > 1 { | ||
return; | ||
} |
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.
You can use if let [param] = fn_sig.decl.inputs
. The if_chain
s can be collapsed. Can you also check that the parameter is &self
?
Can you do a rebase, not a merge? |
returned_iter_not_implementing_iterator
iter_not_returning_iterator
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 lint can be in the pedantic group. Otherwise this is ready!
Thanks! @bors r+ |
📌 Commit 8f88acd has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Add new lint [
iter_not_returning_iterator
] to detect methoditer()
oriter_mut()
returning a type not implementingIterator
changelog: Add new lint [
iter_not_returning_iterator
]