]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/redundant_allocation.rs
Auto merge of #86336 - camsteffen:char-array-pattern, r=joshtriplett
[rust.git] / src / tools / clippy / tests / ui / redundant_allocation.rs
1 #![warn(clippy::all)]
2 #![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
3 #![allow(clippy::blacklisted_name, unused_variables, dead_code)]
4 #![allow(unused_imports)]
5
6 pub struct MyStruct {}
7
8 pub struct SubT<T> {
9     foo: T,
10 }
11
12 pub enum MyEnum {
13     One,
14     Two,
15 }
16
17 mod outer_box {
18     use crate::MyEnum;
19     use crate::MyStruct;
20     use crate::SubT;
21     use std::boxed::Box;
22     use std::rc::Rc;
23     use std::sync::Arc;
24
25     pub fn box_test6<T>(foo: Box<Rc<T>>) {}
26
27     pub fn box_test7<T>(foo: Box<Arc<T>>) {}
28
29     pub fn box_test8() -> Box<Rc<SubT<usize>>> {
30         unimplemented!();
31     }
32
33     pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
34         unimplemented!();
35     }
36 }
37
38 mod outer_rc {
39     use crate::MyEnum;
40     use crate::MyStruct;
41     use crate::SubT;
42     use std::boxed::Box;
43     use std::rc::Rc;
44     use std::sync::Arc;
45
46     pub fn rc_test5(a: Rc<Box<bool>>) {}
47
48     pub fn rc_test7(a: Rc<Arc<bool>>) {}
49
50     pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
51         unimplemented!();
52     }
53
54     pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
55         unimplemented!();
56     }
57 }
58
59 mod outer_arc {
60     use crate::MyEnum;
61     use crate::MyStruct;
62     use crate::SubT;
63     use std::boxed::Box;
64     use std::rc::Rc;
65     use std::sync::Arc;
66
67     pub fn arc_test5(a: Arc<Box<bool>>) {}
68
69     pub fn arc_test6(a: Arc<Rc<bool>>) {}
70
71     pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
72         unimplemented!();
73     }
74
75     pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
76         unimplemented!();
77     }
78 }
79
80 // https://github.com/rust-lang/rust-clippy/issues/7487
81 mod box_dyn {
82     use std::boxed::Box;
83     use std::rc::Rc;
84     use std::sync::Arc;
85
86     pub trait T {}
87
88     struct S {
89         a: Box<Box<dyn T>>,
90         b: Rc<Box<dyn T>>,
91         c: Arc<Box<dyn T>>,
92     }
93
94     pub fn test_box(_: Box<Box<dyn T>>) {}
95     pub fn test_rc(_: Rc<Box<dyn T>>) {}
96     pub fn test_arc(_: Arc<Box<dyn T>>) {}
97     pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {}
98 }
99
100 fn main() {}