Skip to content

Commit

Permalink
rustfmt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Apr 28, 2019
1 parent f3f168e commit ccdf8f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions tests/ui/filter_map_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
fn main() {
let a = ["1", "lol", "3", "NaN", "5"];

let element : Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
assert_eq!(element, Some(1));
}
}
6 changes: 3 additions & 3 deletions tests/ui/filter_map_next.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(p)` instead.
--> $DIR/filter_map_next.rs:6:33
--> $DIR/filter_map_next.rs:6:32
|
LL | let element : Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::filter-map-next` implied by `-D warnings`
= note: replace `filter_map(|s| s.parse().ok()).next()` with `find_map(|s| s.parse().ok())`
Expand Down
34 changes: 14 additions & 20 deletions tests/ui/find_map.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
#![warn(clippy::all, clippy::pedantic)]

#[derive(Debug,Copy,Clone)]
#[derive(Debug, Copy, Clone)]
enum Flavor {
Chocolate,
}

#[derive(Debug,Copy,Clone)]
#[derive(Debug, Copy, Clone)]
enum Dessert {
Banana,
Pudding,
Cake(Flavor)
Cake(Flavor),
}

fn main() {
let desserts_of_the_week = vec![
Dessert::Banana,
Dessert::Cake(Flavor::Chocolate),
Dessert::Pudding,
];
let desserts_of_the_week = vec![Dessert::Banana, Dessert::Cake(Flavor::Chocolate), Dessert::Pudding];

let a = ["lol", "NaN", "2", "5", "Xunda"];

let _ : Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok())
.map(|s| s.parse().unwrap());
let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s| s.parse().unwrap());

let _ : Option<Flavor> = desserts_of_the_week.iter().find(|dessert|{
match *dessert {
let _: Option<Flavor> = desserts_of_the_week
.iter()
.find(|dessert| match *dessert {
Dessert::Cake(_) => true,
_ => false
}
}).map(|dessert|{
match *dessert {
_ => false,
})
.map(|dessert| match *dessert {
Dessert::Cake(ref flavor) => *flavor,
_ => unreachable!()
}
});
}
_ => unreachable!(),
});
}
24 changes: 11 additions & 13 deletions tests/ui/find_map.stderr
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
error: called `find(p).map(q)` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
--> $DIR/find_map.rs:24:27
--> $DIR/find_map.rs:20:26
|
LL | let _ : Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok())
| ___________________________^
LL | | .map(|s| s.parse().unwrap());
| |______________________________________________________________^
LL | let _: Option<i32> = a.iter().find(|s| s.parse::<i32>().is_ok()).map(|s| s.parse().unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::find-map` implied by `-D warnings`

error: called `find(p).map(q)` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
--> $DIR/find_map.rs:27:30
--> $DIR/find_map.rs:22:29
|
LL | let _ : Option<Flavor> = desserts_of_the_week.iter().find(|dessert|{
| ______________________________^
LL | | match *dessert {
LL | let _: Option<Flavor> = desserts_of_the_week
| _____________________________^
LL | | .iter()
LL | | .find(|dessert| match *dessert {
LL | | Dessert::Cake(_) => true,
LL | | _ => false
... |
LL | | }
LL | | });
| |______^
LL | | _ => unreachable!(),
LL | | });
| |__________^

error: aborting due to 2 previous errors

0 comments on commit ccdf8f0

Please sign in to comment.