fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.0 KiB63 linesraw
1#![warn(clippy::all, clippy::pedantic)]
2#![allow(clippy::let_underscore_untyped)]
3#![allow(clippy::missing_docs_in_private_items)]
4#![allow(clippy::map_identity)]
5#![allow(clippy::redundant_closure)]
6#![allow(clippy::unnecessary_wraps)]
7#![feature(result_flattening)]
8
9fn main() {
10    // mapping to Option on Iterator
11    fn option_id(x: i8) -> Option<i8> {
12        Some(x)
13    }
14    let option_id_ref: fn(i8) -> Option<i8> = option_id;
15    let option_id_closure = |x| Some(x);
16    let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id).collect();
17    let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_ref).collect();
18    let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(option_id_closure).collect();
19    let _: Vec<_> = vec![5_i8; 6].into_iter().filter_map(|x| x.checked_add(1)).collect();
20
21    // mapping to Iterator on Iterator
22    let _: Vec<_> = vec![5_i8; 6].into_iter().flat_map(|x| 0..x).collect();
23
24    // mapping to Option on Option
25    let _: Option<_> = (Some(Some(1))).and_then(|x| x);
26
27    // mapping to Result on Result
28    let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x);
29
30    issue8734();
31    issue8878();
32}
33
34fn issue8734() {
35    let _ = [0u8, 1, 2, 3]
36        .into_iter()
37        .flat_map(|n| match n {
38            1 => [n
39                .saturating_add(1)
40                .saturating_add(1)
41                .saturating_add(1)
42                .saturating_add(1)
43                .saturating_add(1)
44                .saturating_add(1)
45                .saturating_add(1)
46                .saturating_add(1)],
47            n => [n],
48        });
49}
50
51#[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
52#[rustfmt::skip] // whitespace is important for this one
53fn issue8878() {
54    std::collections::HashMap::<u32, u32>::new()
55        .get(&0)
56        .and_then(|_| {
57// we need some newlines
58// so that the span is big enough
59// for a split output of the diagnostic
60            Some("")
61 // whitespace beforehand is important as well
62        });
63}