about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-01-05 16:44:41 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2024-01-05 16:44:41 +0100
commit7aa4624a8fe8ff2c4273e35457a7cee6100a8355 (patch)
tree5af2434ad5dacd91fd4e20b06b85707287b2339d
parent9e4e8ef1023d02367a8919f4d13df913f2232cb2 (diff)
downloadrust-7aa4624a8fe8ff2c4273e35457a7cee6100a8355.tar.gz
rust-7aa4624a8fe8ff2c4273e35457a7cee6100a8355.zip
Extend `struct_field_names` lint ui test
-rw-r--r--tests/ui/struct_fields.rs22
-rw-r--r--tests/ui/struct_fields.stderr28
2 files changed, 41 insertions, 9 deletions
diff --git a/tests/ui/struct_fields.rs b/tests/ui/struct_fields.rs
index a8b12c6dfe3..7c9e9d8ed26 100644
--- a/tests/ui/struct_fields.rs
+++ b/tests/ui/struct_fields.rs
@@ -39,14 +39,14 @@ struct DataStruct {
 struct DoublePrefix {
     //~^ ERROR: all fields have the same prefix: `some_data`
     some_data_a: bool,
-    some_data_b: bool,
+    some_data_b: i8,
     some_data_c: bool,
 }
 
 struct DoublePostfix {
     //~^ ERROR: all fields have the same postfix: `some_data`
     a_some_data: bool,
-    b_some_data: bool,
+    b_some_data: i8,
     c_some_data: bool,
 }
 
@@ -54,14 +54,14 @@ struct DoublePostfix {
 struct NotSnakeCase {
     //~^ ERROR: all fields have the same postfix: `someData`
     a_someData: bool,
-    b_someData: bool,
+    b_someData: i8,
     c_someData: bool,
 }
 #[allow(non_snake_case)]
 struct NotSnakeCase2 {
     //~^ ERROR: all fields have the same prefix: `someData`
     someData_c: bool,
-    someData_b: bool,
+    someData_b: i8,
     someData_a_b: bool,
 }
 
@@ -328,4 +328,18 @@ external! {
 
 }
 
+// Should not warn
+struct Config {
+    use_foo: bool,
+    use_bar: bool,
+    use_baz: bool,
+}
+
+struct Use {
+    use_foo: bool,
+    //~^ ERROR: field name starts with the struct's name
+    use_bar: bool,
+    use_baz: bool,
+}
+
 fn main() {}
diff --git a/tests/ui/struct_fields.stderr b/tests/ui/struct_fields.stderr
index 4ca57715b18..d2bdbd17d5c 100644
--- a/tests/ui/struct_fields.stderr
+++ b/tests/ui/struct_fields.stderr
@@ -45,7 +45,7 @@ error: all fields have the same prefix: `some_data`
 LL | / struct DoublePrefix {
 LL | |
 LL | |     some_data_a: bool,
-LL | |     some_data_b: bool,
+LL | |     some_data_b: i8,
 LL | |     some_data_c: bool,
 LL | | }
    | |_^
@@ -58,7 +58,7 @@ error: all fields have the same postfix: `some_data`
 LL | / struct DoublePostfix {
 LL | |
 LL | |     a_some_data: bool,
-LL | |     b_some_data: bool,
+LL | |     b_some_data: i8,
 LL | |     c_some_data: bool,
 LL | | }
    | |_^
@@ -71,7 +71,7 @@ error: all fields have the same postfix: `someData`
 LL | / struct NotSnakeCase {
 LL | |
 LL | |     a_someData: bool,
-LL | |     b_someData: bool,
+LL | |     b_someData: i8,
 LL | |     c_someData: bool,
 LL | | }
    | |_^
@@ -84,7 +84,7 @@ error: all fields have the same prefix: `someData`
 LL | / struct NotSnakeCase2 {
 LL | |
 LL | |     someData_c: bool,
-LL | |     someData_b: bool,
+LL | |     someData_b: i8,
 LL | |     someData_a_b: bool,
 LL | | }
    | |_^
@@ -261,5 +261,23 @@ LL |       mk_struct_full_def!(PrefixData, some_data, some_meta, some_other);
    = help: remove the prefixes
    = note: this error originates in the macro `mk_struct_full_def` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: aborting due to 21 previous errors
+error: field name starts with the struct's name
+  --> $DIR/struct_fields.rs:339:5
+   |
+LL |     use_foo: bool,
+   |     ^^^^^^^^^^^^^
+
+error: field name starts with the struct's name
+  --> $DIR/struct_fields.rs:341:5
+   |
+LL |     use_bar: bool,
+   |     ^^^^^^^^^^^^^
+
+error: field name starts with the struct's name
+  --> $DIR/struct_fields.rs:342:5
+   |
+LL |     use_baz: bool,
+   |     ^^^^^^^^^^^^^
+
+error: aborting due to 24 previous errors