]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / rc_clone_in_vec_init / rc.rs
1 #![warn(clippy::rc_clone_in_vec_init)]
2 use std::rc::Rc;
3 use std::sync::Mutex;
4
5 fn main() {}
6
7 fn should_warn_simple_case() {
8 let v = vec![Rc::new("x".to_string()); 2];
9 }
10
11 fn should_warn_simple_case_with_big_indentation() {
12 if true {
13 let k = 1;
14 dbg!(k);
15 if true {
16 let v = vec![Rc::new("x".to_string()); 2];
17 }
18 }
19 }
20
21 fn should_warn_complex_case() {
22 let v = vec![
23 std::rc::Rc::new(Mutex::new({
24 let x = 1;
25 dbg!(x);
26 x
27 }));
28 2
29 ];
30
31 let v1 = vec![
32 Rc::new(Mutex::new({
33 let x = 1;
34 dbg!(x);
35 x
36 }));
37 2
38 ];
39 }
40
41 fn should_not_warn_custom_arc() {
42 #[derive(Clone)]
43 struct Rc;
44
45 impl Rc {
46 fn new() -> Self {
47 Rc
48 }
49 }
50
51 let v = vec![Rc::new(); 2];
52 }
53
54 fn should_not_warn_vec_from_elem_but_not_rc() {
55 let v = vec![String::new(); 2];
56 let v1 = vec![1; 2];
57 let v2 = vec![
58 Box::new(std::rc::Rc::new({
59 let y = 3;
60 dbg!(y);
61 y
62 }));
63 2
64 ];
65 }
66
67 fn should_not_warn_vec_macro_but_not_from_elem() {
68 let v = vec![Rc::new("x".to_string())];
69 }