mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add tests for from_iter_instead_of_collect
This commit is contained in:
parent
9d6eedf5f2
commit
1b117f4629
15
tests/ui/from_iter_instead_of_collect.rs
Normal file
15
tests/ui/from_iter_instead_of_collect.rs
Normal file
@ -0,0 +1,15 @@
|
||||
#![warn(clippy::from_iter_instead_of_collect)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
fn main() {
|
||||
{
|
||||
let iter_expr = std::iter::repeat(5).take(5);
|
||||
|
||||
Vec::from_iter(iter_expr);
|
||||
HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
||||
//let v: Vec<i32> = iter_expr.collect();
|
||||
let a: Vec<i32> = Vec::new();
|
||||
}
|
||||
}
|
19
tests/ui/from_iter_instead_of_collect.stderr
Normal file
19
tests/ui/from_iter_instead_of_collect.stderr
Normal file
@ -0,0 +1,19 @@
|
||||
error: use `.collect()` instead of `::from_iter()`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:10:5
|
||||
|
|
||||
LL | Vec::from_iter(iter_expr);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::from-iter-instead-of-collect` implied by `-D warnings`
|
||||
= help: consider using `iter_expr.collect()`
|
||||
|
||||
error: use `.collect()` instead of `::from_iter()`
|
||||
--> $DIR/from_iter_instead_of_collect.rs:11:5
|
||||
|
|
||||
LL | HashMap::<usize, &i8>::from_iter(vec![5,5,5,5].iter().enumerate());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using `vec![5,5,5,5].iter().enumerate().collect()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
0
tests/ui/from_iter_instead_of_collect.stdout
Normal file
0
tests/ui/from_iter_instead_of_collect.stdout
Normal file
Loading…
Reference in New Issue
Block a user