Skip to content

Commit abd5db3

Browse files
committed
add many tests
Signed-off-by: TennyZhuang <zty0826@gmail.com>
1 parent b10882a commit abd5db3

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

tests/ui/partial_pub_fields.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#![warn(clippy::partial_pub_fields)]
33

44
fn main() {
5-
// test code goes here
6-
75
use std::collections::HashMap;
86

97
#[derive(Default)]
@@ -17,4 +15,26 @@ fn main() {
1715
pub g: u8,
1816
b: u8,
1917
}
18+
19+
pub struct Point(i32, pub i32);
20+
21+
pub struct Visibility {
22+
r#pub: bool,
23+
pub pos: u32,
24+
}
25+
26+
// Don't lint on empty structs;
27+
pub struct Empty1;
28+
pub struct Empty2();
29+
pub struct Empty3 {};
30+
31+
// Don't lint on structs with one field.
32+
pub struct Single1(i32);
33+
pub struct Single2(pub i32);
34+
pub struct Single3 {
35+
v1: i32,
36+
}
37+
pub struct Single4 {
38+
pub v1: i32,
39+
}
2040
}

tests/ui/partial_pub_fields.stderr

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: mixed usage of pub and non-pub fields
2-
--> $DIR/partial_pub_fields.rs:12:9
2+
--> $DIR/partial_pub_fields.rs:10:9
33
|
44
LL | pub paths: HashMap<u32, String>,
55
| ^^^
@@ -8,12 +8,28 @@ LL | pub paths: HashMap<u32, String>,
88
= note: `-D clippy::partial-pub-fields` implied by `-D warnings`
99

1010
error: mixed usage of pub and non-pub fields
11-
--> $DIR/partial_pub_fields.rs:18:9
11+
--> $DIR/partial_pub_fields.rs:16:9
1212
|
1313
LL | b: u8,
1414
| ^
1515
|
1616
= help: consider using public field here
1717

18-
error: aborting due to 2 previous errors
18+
error: mixed usage of pub and non-pub fields
19+
--> $DIR/partial_pub_fields.rs:19:27
20+
|
21+
LL | pub struct Point(i32, pub i32);
22+
| ^^^
23+
|
24+
= help: consider using private field here
25+
26+
error: mixed usage of pub and non-pub fields
27+
--> $DIR/partial_pub_fields.rs:23:9
28+
|
29+
LL | pub pos: u32,
30+
| ^^^
31+
|
32+
= help: consider using private field here
33+
34+
error: aborting due to 4 previous errors
1935

0 commit comments

Comments
 (0)