-
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
New lint: iter_count
#6791
New lint: iter_count
#6791
Conversation
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
41814ed
to
53cc66c
Compare
Should this also lint for |
@matthewjasper |
@flip1995 @matthewjasper @Y-Nak |
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.
Seems there is a false positive with code inside the cargo repo.
Reduced:
needs a cargo.toml with
[dependencies]
im-rc = "*"
main.rs:
fn main() {
let mut g: Graph<i32, i32> = Graph::new();
g.iter().count();
}
impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
pub fn new() -> Graph<N, E> {
Graph {
nodes: im_rc::OrdMap::new(),
}
}
pub fn iter(&self) -> impl Iterator<Item = &N> {
self.nodes.keys()
}
}
pub struct Graph<N: Clone, E: Clone> {
nodes: im_rc::OrdMap<N, im_rc::OrdMap<N, E>>,
}
Your lint warns
warning: called `.iter().count()` on a `std::iter::Iterator`
--> src/main.rs:3:5
|
3 | g.iter().count();
| ^^^^^^^^^^^^^^^^ help: try: `g.len()`
but there is no corresponding .len()
method
error[E0599]: no method named `len` found for struct `Graph<i32, i32>` in the current scope
--> src/main.rs:3:7
|
3 | g.len();
| ^^^ method not found in `Graph<i32, i32>`
...
18 | pub struct Graph<N: Clone, E: Clone> {
| ------------------------------------ method `len` not found for this
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item `len`, perhaps you need to implement one of them:
candidate #1: `std::iter::ExactSizeIterator`
candidate #2: `typenum::type_operators::Len`
candidate #3: `bitmaps::types::BitOps`
@matthewjasper |
☔ The latest upstream changes (presumably #6730) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
Thanks!
@bors r+ |
📌 Commit 6041365 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This pull request adds a new lint named
iter_count
.closes #6262
changelog: new lint
iter_count