Skip to content

Commit e9c264d

Browse files
committed
unify tests
1 parent 7812fb2 commit e9c264d

16 files changed

+125
-141
lines changed

tests/ui/rc_clone_in_vec_init/arc.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_complex_case() {
11+
let v = vec![
12+
std::sync::Arc::new(Mutex::new({
13+
let x = 1;
14+
dbg!(x);
15+
x
16+
}));
17+
2
18+
];
19+
}
20+
21+
fn should_not_warn_custom_arc() {
22+
#[derive(Clone)]
23+
struct Arc;
24+
25+
impl Arc {
26+
fn new() -> Self {
27+
Arc
28+
}
29+
}
30+
31+
let v = vec![Arc::new(); 2];
32+
}
33+
34+
fn should_not_warn_vec_from_elem_but_not_arc() {
35+
let v = vec![String::new(); 2];
36+
let v1 = vec![1; 2];
37+
let v2 = vec![
38+
Box::new(std::sync::Arc::new({
39+
let y = 3;
40+
dbg!(y);
41+
y
42+
}));
43+
2
44+
];
45+
}
46+
47+
fn should_not_warn_vec_macro_but_not_from_elem() {
48+
let v = vec![Arc::new("x".to_string())];
49+
}

tests/ui/rc_clone_in_vec_init/arc/complex_case.stderr renamed to tests/ui/rc_clone_in_vec_init/arc.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
error: calling `Arc::new` in `vec![elem; len]`
2-
--> $DIR/complex_case.rs:5:13
2+
--> $DIR/arc.rs:7:13
3+
|
4+
LL | let v = vec![Arc::new("x".to_string()); 2];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
8+
= note: each element will point to the same `Arc` instance
9+
= help: if this is intentional, consider extracting the `Arc` initialization to a variable
10+
= help: or if not, initilaize each element individually
11+
12+
error: calling `Arc::new` in `vec![elem; len]`
13+
--> $DIR/arc.rs:11:13
314
|
415
LL | let v = vec![
516
| _____________^
@@ -11,10 +22,9 @@ LL | | 2
1122
LL | | ];
1223
| |_____^
1324
|
14-
= note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
1525
= note: each element will point to the same `Arc` instance
1626
= help: if this is intentional, consider extracting the `Arc` initialization to a variable
1727
= help: or if not, initilaize each element individually
1828

19-
error: aborting due to previous error
29+
error: aborting due to 2 previous errors
2030

tests/ui/rc_clone_in_vec_init/arc/complex_case.rs

-13
This file was deleted.

tests/ui/rc_clone_in_vec_init/arc/custom_arc.rs

-14
This file was deleted.

tests/ui/rc_clone_in_vec_init/arc/simple_case.rs

-6
This file was deleted.

tests/ui/rc_clone_in_vec_init/arc/simple_case.stderr

-13
This file was deleted.

tests/ui/rc_clone_in_vec_init/arc/vec_from_elem_but_not_arc.rs

-15
This file was deleted.

tests/ui/rc_clone_in_vec_init/arc/vec_macro_but_not_from_elem.rs

-6
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_complex_case() {
12+
let v = vec![
13+
std::rc::Rc::new(Mutex::new({
14+
let x = 1;
15+
dbg!(x);
16+
x
17+
}));
18+
2
19+
];
20+
}
21+
22+
fn should_not_warn_custom_arc() {
23+
#[derive(Clone)]
24+
struct Rc;
25+
26+
impl Rc {
27+
fn new() -> Self {
28+
Rc
29+
}
30+
}
31+
32+
let v = vec![Rc::new(); 2];
33+
}
34+
35+
fn should_not_warn_vec_from_elem_but_not_rc() {
36+
let v = vec![String::new(); 2];
37+
let v1 = vec![1; 2];
38+
let v2 = vec![
39+
Box::new(std::rc::Rc::new({
40+
let y = 3;
41+
dbg!(y);
42+
y
43+
}));
44+
2
45+
];
46+
}
47+
48+
fn should_not_warn_vec_macro_but_not_from_elem() {
49+
let v = vec![Rc::new("x".to_string())];
50+
}

tests/ui/rc_clone_in_vec_init/rc/complex_case.stderr renamed to tests/ui/rc_clone_in_vec_init/rc.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
error: calling `Rc::new` in `vec![elem; len]`
2-
--> $DIR/complex_case.rs:5:13
2+
--> $DIR/rc.rs:9:13
3+
|
4+
LL | let v = vec![Rc::new("x".to_string()); 2];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
8+
= note: each element will point to the same `Rc` instance
9+
= help: if this is intentional, consider extracting the `Rc` initialization to a variable
10+
= help: or if not, initilaize each element individually
11+
12+
error: calling `Rc::new` in `vec![elem; len]`
13+
--> $DIR/rc.rs:13:13
314
|
415
LL | let v = vec![
516
| _____________^
@@ -11,10 +22,9 @@ LL | | 2
1122
LL | | ];
1223
| |_____^
1324
|
14-
= note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
1525
= note: each element will point to the same `Rc` instance
1626
= help: if this is intentional, consider extracting the `Rc` initialization to a variable
1727
= help: or if not, initilaize each element individually
1828

19-
error: aborting due to previous error
29+
error: aborting due to 2 previous errors
2030

tests/ui/rc_clone_in_vec_init/rc/complex_case.rs

-13
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc/custom_rc.rs

-14
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc/simple_case.rs

-6
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc/simple_case.stderr

-13
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc/vec_from_elem_but_not_arc.rs

-16
This file was deleted.

tests/ui/rc_clone_in_vec_init/rc/vec_macro_but_not_from_elem.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)