about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTennyZhuang <zty0826@gmail.com>2022-10-16 16:57:31 +0800
committerTennyZhuang <zty0826@gmail.com>2022-10-16 16:59:04 +0800
commitabd5db332173a5ef76a56f4fd18af421cf551c17 (patch)
tree3aa788053e8578063cf6e5f2bb2477088345ab8f
parentb10882ab9153733249f95d63150724aa5f50ce59 (diff)
downloadrust-abd5db332173a5ef76a56f4fd18af421cf551c17.tar.gz
rust-abd5db332173a5ef76a56f4fd18af421cf551c17.zip
add many tests
Signed-off-by: TennyZhuang <zty0826@gmail.com>
-rw-r--r--tests/ui/partial_pub_fields.rs24
-rw-r--r--tests/ui/partial_pub_fields.stderr22
2 files changed, 41 insertions, 5 deletions
diff --git a/tests/ui/partial_pub_fields.rs b/tests/ui/partial_pub_fields.rs
index e1a4b482799..668545da844 100644
--- a/tests/ui/partial_pub_fields.rs
+++ b/tests/ui/partial_pub_fields.rs
@@ -2,8 +2,6 @@
 #![warn(clippy::partial_pub_fields)]
 
 fn main() {
-    // test code goes here
-
     use std::collections::HashMap;
 
     #[derive(Default)]
@@ -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 Single4 {
+        pub v1: i32,
+    }
 }
diff --git a/tests/ui/partial_pub_fields.stderr b/tests/ui/partial_pub_fields.stderr
index f7f23c85a67..84cfc1a9194 100644
--- a/tests/ui/partial_pub_fields.stderr
+++ b/tests/ui/partial_pub_fields.stderr
@@ -1,5 +1,5 @@
 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>,
    |         ^^^
@@ -8,12 +8,28 @@ 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 4 previous errors