summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/box_default.fixed
blob: 7e9f074fdcabd24f9e97019139ebedc60e7b36a0 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// run-rustfix
#![warn(clippy::box_default)]

#[derive(Default)]
struct ImplementsDefault;

struct OwnDefault;

impl OwnDefault {
    fn default() -> Self {
        Self
    }
}

macro_rules! outer {
    ($e: expr) => {
        $e
    };
}

fn main() {
    let _string: Box<String> = Box::default();
    let _byte = Box::<u8>::default();
    let _vec = Box::<Vec<u8>>::default();
    let _impl = Box::<ImplementsDefault>::default();
    let _impl2 = Box::<ImplementsDefault>::default();
    let _impl3: Box<ImplementsDefault> = Box::default();
    let _own = Box::new(OwnDefault::default()); // should not lint
    let _in_macro = outer!(Box::<String>::default());
    let _string_default = outer!(Box::<String>::default());
    let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
    let _vec3: Box<Vec<bool>> = Box::default();
    let _vec4: Box<_> = Box::<Vec<bool>>::default();
    let _more = ret_ty_fn();
    call_ty_fn(Box::default());
}

fn ret_ty_fn() -> Box<bool> {
    Box::<bool>::default()
}

#[allow(clippy::boxed_local)]
fn call_ty_fn(_b: Box<u8>) {
    issue_9621_dyn_trait();
}

use std::io::{Read, Result};

impl Read for ImplementsDefault {
    fn read(&mut self, _: &mut [u8]) -> Result<usize> {
        Ok(0)
    }
}

fn issue_9621_dyn_trait() {
    let _: Box<dyn Read> = Box::<ImplementsDefault>::default();
    issue_10089();
}

fn issue_10089() {
    let _closure = || {
        #[derive(Default)]
        struct WeirdPathed;

        let _ = Box::<WeirdPathed>::default();
    };
}