summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unnecessary_lazy_eval_unfixable.rs
blob: 412d4aaafb4a146404e7927f0bbed9ecd82c1ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::unnecessary_literal_unwrap)]
//@no-rustfix
struct Deep(Option<usize>);

#[derive(Copy, Clone)]
struct SomeStruct {
    some_field: usize,
}

fn main() {
    // fix will break type inference
    let _ = Ok(1).unwrap_or_else(|()| 2);
    //~^ ERROR: unnecessary closure used to substitute value for `Result::Err`
    //~| NOTE: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
    mod e {
        pub struct E;
    }
    let _ = Ok(1).unwrap_or_else(|e::E| 2);
    //~^ ERROR: unnecessary closure used to substitute value for `Result::Err`
    let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
    //~^ ERROR: unnecessary closure used to substitute value for `Result::Err`

    // Fix #6343
    let arr = [(Some(1),)];
    Some(&0).and_then(|&i| arr[i].0);
}

fn issue11672() {
    // Return type annotation helps type inference and removing it can break code
    let _ = true.then(|| -> &[u8] { &[] });
}