]> git.lizzy.rs Git - rust.git/blob - tests/ui/redundant_allocation.rs
Merge branch 'master' into doc_link_with_quotes
[rust.git] / 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 // https://github.com/rust-lang/rust-clippy/issues/8604
101 mod box_fat_ptr {
102     use std::boxed::Box;
103     use std::path::Path;
104     use std::rc::Rc;
105     use std::sync::Arc;
106
107     pub struct DynSized {
108         foo: [usize],
109     }
110
111     struct S {
112         a: Box<Box<str>>,
113         b: Rc<Box<str>>,
114         c: Arc<Box<str>>,
115
116         e: Box<Box<[usize]>>,
117         f: Box<Box<Path>>,
118         g: Box<Box<DynSized>>,
119     }
120
121     pub fn test_box_str(_: Box<Box<str>>) {}
122     pub fn test_rc_str(_: Rc<Box<str>>) {}
123     pub fn test_arc_str(_: Arc<Box<str>>) {}
124
125     pub fn test_box_slice(_: Box<Box<[usize]>>) {}
126     pub fn test_box_path(_: Box<Box<Path>>) {}
127     pub fn test_box_custom(_: Box<Box<DynSized>>) {}
128
129     pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
130     pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
131     pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
132     pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
133 }
134
135 fn main() {}