Skip to content

Commit

Permalink
add many tests
Browse files Browse the repository at this point in the history
Signed-off-by: TennyZhuang <zty0826@gmail.com>
  • Loading branch information
TennyZhuang committed Oct 16, 2022
1 parent b10882a commit c6b20ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
24 changes: 22 additions & 2 deletions tests/ui/partial_pub_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#![warn(clippy::partial_pub_fields)]

fn main() {
// test code goes here

use std::collections::HashMap;

#[derive(Default)]
Expand All @@ -17,4 +15,26 @@ fn main() {
pub g: u8,
b: u8,
}

pub struct Point(i32, pub i32);

pub struct Visibility {
r#pub: bool,
pub pos: u32,
}

// Don't lint on empty structs;
pub struct Empty1;
pub struct Empty2();
pub struct Empty3 {};

// Don't lint on structs with one field.
pub struct Single1(i32);
pub struct Single2(pub i32);
pub struct Single3 {
v1: i32,
}
pub struct Single3 {
pub v1: i32,
}
}
34 changes: 31 additions & 3 deletions tests/ui/partial_pub_fields.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
error[E0428]: the name `Single3` is defined multiple times
--> $DIR/partial_pub_fields.rs:37:5
|
LL | pub struct Single3 {
| ------------------ previous definition of the type `Single3` here
...
LL | pub struct Single3 {
| ^^^^^^^^^^^^^^^^^^ `Single3` redefined here
|
= note: `Single3` must be defined only once in the type namespace of this block

error: mixed usage of pub and non-pub fields
--> $DIR/partial_pub_fields.rs:12:9
--> $DIR/partial_pub_fields.rs:10:9
|
LL | pub paths: HashMap<u32, String>,
| ^^^
Expand All @@ -8,12 +19,29 @@ LL | pub paths: HashMap<u32, String>,
= note: `-D clippy::partial-pub-fields` implied by `-D warnings`

error: mixed usage of pub and non-pub fields
--> $DIR/partial_pub_fields.rs:18:9
--> $DIR/partial_pub_fields.rs:16:9
|
LL | b: u8,
| ^
|
= help: consider using public field here

error: aborting due to 2 previous errors
error: mixed usage of pub and non-pub fields
--> $DIR/partial_pub_fields.rs:19:27
|
LL | pub struct Point(i32, pub i32);
| ^^^
|
= help: consider using private field here

error: mixed usage of pub and non-pub fields
--> $DIR/partial_pub_fields.rs:23:9
|
LL | pub pos: u32,
| ^^^
|
= help: consider using private field here

error: aborting due to 5 previous errors

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

0 comments on commit c6b20ad

Please sign in to comment.