diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed new file mode 100644 index 000000000..48f809331 --- /dev/null +++ b/src/tools/clippy/tests/ui/from_iter_instead_of_collect.fixed @@ -0,0 +1,61 @@ +// run-rustfix + +#![warn(clippy::from_iter_instead_of_collect)] +#![allow(unused_imports, unused_tuple_struct_fields)] + +use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque}; + +struct Foo(Vec<bool>); + +impl FromIterator<bool> for Foo { + fn from_iter<T: IntoIterator<Item = bool>>(_: T) -> Self { + todo!() + } +} + +impl<'a> FromIterator<&'a bool> for Foo { + fn from_iter<T: IntoIterator<Item = &'a bool>>(iter: T) -> Self { + iter.into_iter().copied().collect::<Self>() + } +} + +fn main() { + let iter_expr = std::iter::repeat(5).take(5); + let _ = iter_expr.collect::<Vec<_>>(); + + let _ = vec![5, 5, 5, 5].iter().enumerate().collect::<HashMap<usize, &i8>>(); + + Vec::from_iter(vec![42u32]); + + let a = vec![0, 1, 2]; + assert_eq!(a, (0..3).collect::<Vec<_>>()); + assert_eq!(a, (0..3).collect::<Vec<i32>>()); + + let mut b = (0..3).collect::<VecDeque<_>>(); + b.push_back(4); + + let mut b = (0..3).collect::<VecDeque<i32>>(); + b.push_back(4); + + { + use std::collections; + let mut b = (0..3).collect::<collections::VecDeque<i32>>(); + b.push_back(4); + } + + let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]; + let bm = values.iter().cloned().collect::<BTreeMap<_, _>>(); + let mut bar = bm.range(0..2).collect::<BTreeMap<_, _>>(); + bar.insert(&4, &'e'); + + let mut bts = (0..3).collect::<BTreeSet<_>>(); + bts.insert(2); + { + use std::collections; + let _ = (0..3).collect::<collections::BTreeSet<_>>(); + let _ = (0..3).collect::<collections::BTreeSet<u32>>(); + } + + for _i in [1, 2, 3].iter().collect::<Vec<_>>() {} + for _i in [1, 2, 3].iter().collect::<Vec<&i32>>() {} +} |