Add ui test for map_unit_fn
lint
This commit is contained in:
parent
a914f37409
commit
ddd7d10879
11
tests/ui/lint/lint_map_unit_fn.rs
Normal file
11
tests/ui/lint/lint_map_unit_fn.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![deny(map_unit_fn)]
|
||||
|
||||
fn foo(items: &mut Vec<u8>) {
|
||||
items.sort();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut x: Vec<Vec<u8>> = vec![vec![0, 2, 1], vec![5, 4, 3]];
|
||||
x.iter_mut().map(foo);
|
||||
//~^ ERROR `Iterator::map` call that discard the iterator's values
|
||||
}
|
25
tests/ui/lint/lint_map_unit_fn.stderr
Normal file
25
tests/ui/lint/lint_map_unit_fn.stderr
Normal file
@ -0,0 +1,25 @@
|
||||
error: `Iterator::map` call that discard the iterator's values
|
||||
--> $DIR/lint_map_unit_fn.rs:9:18
|
||||
|
|
||||
LL | fn foo(items: &mut Vec<u8>) {
|
||||
| --------------------------- this function returns `()`, which is likely not what you wanted
|
||||
...
|
||||
LL | x.iter_mut().map(foo);
|
||||
| ^^^^---^
|
||||
| | |
|
||||
| | called `Iterator::map` with callable that returns `()`
|
||||
| after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
|
||||
|
|
||||
= note: `Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint_map_unit_fn.rs:1:9
|
||||
|
|
||||
LL | #![deny(map_unit_fn)]
|
||||
| ^^^^^^^^^^^
|
||||
help: you might have meant to use `Iterator::for_each`
|
||||
|
|
||||
LL | x.iter_mut().for_each(foo);
|
||||
| ~~~~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user