diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed')
-rw-r--r-- | src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed b/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed new file mode 100644 index 000000000..dcef63403 --- /dev/null +++ b/src/tools/clippy/tests/ui/explicit_into_iter_loop.fixed @@ -0,0 +1,69 @@ +//@run-rustfix +#![warn(clippy::explicit_into_iter_loop)] + +fn main() { + // Issue #4958 + fn _takes_iterator<T>(iterator: &T) + where + for<'a> &'a T: IntoIterator<Item = &'a String>, + { + for _ in iterator {} + } + + struct T; + impl IntoIterator for &T { + type Item = (); + type IntoIter = std::vec::IntoIter<Self::Item>; + fn into_iter(self) -> Self::IntoIter { + unimplemented!() + } + } + + let mut t = T; + for _ in &t {} + + let r = &t; + for _ in r {} + + // No suggestion for this. + // We'd have to suggest `for _ in *rr {}` which is less clear. + let rr = &&t; + for _ in rr.into_iter() {} + + let mr = &mut t; + for _ in &*mr {} + + struct U; + impl IntoIterator for &mut U { + type Item = (); + type IntoIter = std::vec::IntoIter<Self::Item>; + fn into_iter(self) -> Self::IntoIter { + unimplemented!() + } + } + + let mut u = U; + for _ in &mut u {} + + let mr = &mut u; + for _ in &mut *mr {} + + // Issue #6900 + struct S; + impl S { + #[allow(clippy::should_implement_trait)] + pub fn into_iter<T>(self) -> I<T> { + unimplemented!() + } + } + + struct I<T>(T); + impl<T> Iterator for I<T> { + type Item = T; + fn next(&mut self) -> Option<Self::Item> { + unimplemented!() + } + } + + for _ in S.into_iter::<u32>() {} +} |