Skip to content

Commit c6b20ad

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

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-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 Single3 {
38+
pub v1: i32,
39+
}
2040
}

tests/ui/partial_pub_fields.stderr

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
error[E0428]: the name `Single3` is defined multiple times
2+
--> $DIR/partial_pub_fields.rs:37:5
3+
|
4+
LL | pub struct Single3 {
5+
| ------------------ previous definition of the type `Single3` here
6+
...
7+
LL | pub struct Single3 {
8+
| ^^^^^^^^^^^^^^^^^^ `Single3` redefined here
9+
|
10+
= note: `Single3` must be defined only once in the type namespace of this block
11+
112
error: mixed usage of pub and non-pub fields
2-
--> $DIR/partial_pub_fields.rs:12:9
13+
--> $DIR/partial_pub_fields.rs:10:9
314
|
415
LL | pub paths: HashMap<u32, String>,
516
| ^^^
@@ -8,12 +19,29 @@ LL | pub paths: HashMap<u32, String>,
819
= note: `-D clippy::partial-pub-fields` implied by `-D warnings`
920

1021
error: mixed usage of pub and non-pub fields
11-
--> $DIR/partial_pub_fields.rs:18:9
22+
--> $DIR/partial_pub_fields.rs:16:9
1223
|
1324
LL | b: u8,
1425
| ^
1526
|
1627
= help: consider using public field here
1728

18-
error: aborting due to 2 previous errors
29+
error: mixed usage of pub and non-pub fields
30+
--> $DIR/partial_pub_fields.rs:19:27
31+
|
32+
LL | pub struct Point(i32, pub i32);
33+
| ^^^
34+
|
35+
= help: consider using private field here
36+
37+
error: mixed usage of pub and non-pub fields
38+
--> $DIR/partial_pub_fields.rs:23:9
39+
|
40+
LL | pub pos: u32,
41+
| ^^^
42+
|
43+
= help: consider using private field here
44+
45+
error: aborting due to 5 previous errors
1946

47+
For more information about this error, try `rustc --explain E0428`.

0 commit comments

Comments
 (0)