]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/redundant_allocation.rs
Rollup merge of #100200 - petrochenkov:zgccld2, r=lqd,Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / redundant_allocation.rs
1 #![warn(clippy::all)]
2 #![allow(clippy::boxed_local, clippy::disallowed_names)]
3
4 pub struct MyStruct;
5
6 pub struct SubT<T> {
7     foo: T,
8 }
9
10 mod outer_box {
11     use crate::MyStruct;
12     use crate::SubT;
13     use std::boxed::Box;
14     use std::rc::Rc;
15     use std::sync::Arc;
16
17     pub fn box_test6<T>(foo: Box<Rc<T>>) {}
18
19     pub fn box_test7<T>(foo: Box<Arc<T>>) {}
20
21     pub fn box_test8() -> Box<Rc<SubT<usize>>> {
22         unimplemented!();
23     }
24
25     pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
26         unimplemented!();
27     }
28 }
29
30 mod outer_rc {
31     use crate::MyStruct;
32     use crate::SubT;
33     use std::boxed::Box;
34     use std::rc::Rc;
35     use std::sync::Arc;
36
37     pub fn rc_test5(a: Rc<Box<bool>>) {}
38
39     pub fn rc_test7(a: Rc<Arc<bool>>) {}
40
41     pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
42         unimplemented!();
43     }
44
45     pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
46         unimplemented!();
47     }
48 }
49
50 mod outer_arc {
51     use crate::MyStruct;
52     use crate::SubT;
53     use std::boxed::Box;
54     use std::rc::Rc;
55     use std::sync::Arc;
56
57     pub fn arc_test5(a: Arc<Box<bool>>) {}
58
59     pub fn arc_test6(a: Arc<Rc<bool>>) {}
60
61     pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
62         unimplemented!();
63     }
64
65     pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
66         unimplemented!();
67     }
68 }
69
70 // https://github.com/rust-lang/rust-clippy/issues/7487
71 mod box_dyn {
72     use std::boxed::Box;
73     use std::rc::Rc;
74     use std::sync::Arc;
75
76     pub trait T {}
77
78     struct S {
79         a: Box<Box<dyn T>>,
80         b: Rc<Box<dyn T>>,
81         c: Arc<Box<dyn T>>,
82     }
83
84     pub fn test_box(_: Box<Box<dyn T>>) {}
85     pub fn test_rc(_: Rc<Box<dyn T>>) {}
86     pub fn test_arc(_: Arc<Box<dyn T>>) {}
87     pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {}
88 }
89
90 // https://github.com/rust-lang/rust-clippy/issues/8604
91 mod box_fat_ptr {
92     use std::boxed::Box;
93     use std::path::Path;
94     use std::rc::Rc;
95     use std::sync::Arc;
96
97     pub struct DynSized {
98         foo: [usize],
99     }
100
101     struct S {
102         a: Box<Box<str>>,
103         b: Rc<Box<str>>,
104         c: Arc<Box<str>>,
105
106         e: Box<Box<[usize]>>,
107         f: Box<Box<Path>>,
108         g: Box<Box<DynSized>>,
109     }
110
111     pub fn test_box_str(_: Box<Box<str>>) {}
112     pub fn test_rc_str(_: Rc<Box<str>>) {}
113     pub fn test_arc_str(_: Arc<Box<str>>) {}
114
115     pub fn test_box_slice(_: Box<Box<[usize]>>) {}
116     pub fn test_box_path(_: Box<Box<Path>>) {}
117     pub fn test_box_custom(_: Box<Box<DynSized>>) {}
118
119     pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
120     pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
121     pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
122     pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
123 }
124
125 fn main() {}