diff options
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/tests/ui/iter_not_returning_iterator.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs b/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs new file mode 100644 index 000000000..cce216fc6 --- /dev/null +++ b/src/tools/clippy/tests/ui/iter_not_returning_iterator.rs @@ -0,0 +1,74 @@ +#![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!() + } +} + +// Issue #8225 +trait Iter { + type I; + fn iter(&self) -> Self::I; +} + +impl Iter for () { + type I = core::slice::Iter<'static, ()>; + fn iter(&self) -> Self::I { + [].iter() + } +} + +struct S; +impl S { + fn iter(&self) -> <() as Iter>::I { + ().iter() + } +} + +struct S2([u8]); +impl S2 { + fn iter(&self) -> core::slice::Iter<u8> { + self.0.iter() + } +} + +fn main() {} |