Skip to content

Commit 7aa4624

Browse files
Extend struct_field_names lint ui test
1 parent 9e4e8ef commit 7aa4624

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

tests/ui/struct_fields.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@ struct DataStruct {
3939
struct DoublePrefix {
4040
//~^ ERROR: all fields have the same prefix: `some_data`
4141
some_data_a: bool,
42-
some_data_b: bool,
42+
some_data_b: i8,
4343
some_data_c: bool,
4444
}
4545

4646
struct DoublePostfix {
4747
//~^ ERROR: all fields have the same postfix: `some_data`
4848
a_some_data: bool,
49-
b_some_data: bool,
49+
b_some_data: i8,
5050
c_some_data: bool,
5151
}
5252

5353
#[allow(non_snake_case)]
5454
struct NotSnakeCase {
5555
//~^ ERROR: all fields have the same postfix: `someData`
5656
a_someData: bool,
57-
b_someData: bool,
57+
b_someData: i8,
5858
c_someData: bool,
5959
}
6060
#[allow(non_snake_case)]
6161
struct NotSnakeCase2 {
6262
//~^ ERROR: all fields have the same prefix: `someData`
6363
someData_c: bool,
64-
someData_b: bool,
64+
someData_b: i8,
6565
someData_a_b: bool,
6666
}
6767

@@ -328,4 +328,18 @@ external! {
328328

329329
}
330330

331+
// Should not warn
332+
struct Config {
333+
use_foo: bool,
334+
use_bar: bool,
335+
use_baz: bool,
336+
}
337+
338+
struct Use {
339+
use_foo: bool,
340+
//~^ ERROR: field name starts with the struct's name
341+
use_bar: bool,
342+
use_baz: bool,
343+
}
344+
331345
fn main() {}

tests/ui/struct_fields.stderr

+23-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ error: all fields have the same prefix: `some_data`
4545
LL | / struct DoublePrefix {
4646
LL | |
4747
LL | | some_data_a: bool,
48-
LL | | some_data_b: bool,
48+
LL | | some_data_b: i8,
4949
LL | | some_data_c: bool,
5050
LL | | }
5151
| |_^
@@ -58,7 +58,7 @@ error: all fields have the same postfix: `some_data`
5858
LL | / struct DoublePostfix {
5959
LL | |
6060
LL | | a_some_data: bool,
61-
LL | | b_some_data: bool,
61+
LL | | b_some_data: i8,
6262
LL | | c_some_data: bool,
6363
LL | | }
6464
| |_^
@@ -71,7 +71,7 @@ error: all fields have the same postfix: `someData`
7171
LL | / struct NotSnakeCase {
7272
LL | |
7373
LL | | a_someData: bool,
74-
LL | | b_someData: bool,
74+
LL | | b_someData: i8,
7575
LL | | c_someData: bool,
7676
LL | | }
7777
| |_^
@@ -84,7 +84,7 @@ error: all fields have the same prefix: `someData`
8484
LL | / struct NotSnakeCase2 {
8585
LL | |
8686
LL | | someData_c: bool,
87-
LL | | someData_b: bool,
87+
LL | | someData_b: i8,
8888
LL | | someData_a_b: bool,
8989
LL | | }
9090
| |_^
@@ -261,5 +261,23 @@ LL | mk_struct_full_def!(PrefixData, some_data, some_meta, some_other);
261261
= help: remove the prefixes
262262
= note: this error originates in the macro `mk_struct_full_def` (in Nightly builds, run with -Z macro-backtrace for more info)
263263

264-
error: aborting due to 21 previous errors
264+
error: field name starts with the struct's name
265+
--> $DIR/struct_fields.rs:339:5
266+
|
267+
LL | use_foo: bool,
268+
| ^^^^^^^^^^^^^
269+
270+
error: field name starts with the struct's name
271+
--> $DIR/struct_fields.rs:341:5
272+
|
273+
LL | use_bar: bool,
274+
| ^^^^^^^^^^^^^
275+
276+
error: field name starts with the struct's name
277+
--> $DIR/struct_fields.rs:342:5
278+
|
279+
LL | use_baz: bool,
280+
| ^^^^^^^^^^^^^
281+
282+
error: aborting due to 24 previous errors
265283

0 commit comments

Comments
 (0)