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