add new lint iter_not_returning_iterator
This commit is contained in:
parent
17294b8161
commit
8f88acdbfa
5 changed files with 132 additions and 0 deletions
47
tests/ui/iter_not_returning_iterator.rs
Normal file
47
tests/ui/iter_not_returning_iterator.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#![warn(clippy::iter_not_returning_iterator)]
|
||||
|
||||
struct Data {
|
||||
begin: u32,
|
||||
}
|
||||
|
||||
struct Counter {
|
||||
count: u32,
|
||||
}
|
||||
|
||||
impl Data {
|
||||
fn iter(&self) -> Counter {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn iter_mut(&self) -> Counter {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Data2 {
|
||||
begin: u32,
|
||||
}
|
||||
|
||||
struct Counter2 {
|
||||
count: u32,
|
||||
}
|
||||
|
||||
impl Data2 {
|
||||
fn iter(&self) -> Counter2 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn iter_mut(&self) -> Counter2 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for Counter {
|
||||
type Item = u32;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
16
tests/ui/iter_not_returning_iterator.stderr
Normal file
16
tests/ui/iter_not_returning_iterator.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error: this method is named `iter` but its return type does not implement `Iterator`
|
||||
--> $DIR/iter_not_returning_iterator.rs:30:5
|
||||
|
|
||||
LL | fn iter(&self) -> Counter2 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::iter-not-returning-iterator` implied by `-D warnings`
|
||||
|
||||
error: this method is named `iter_mut` but its return type does not implement `Iterator`
|
||||
--> $DIR/iter_not_returning_iterator.rs:34:5
|
||||
|
|
||||
LL | fn iter_mut(&self) -> Counter2 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue