1
1
#![ deny( warnings) ]
2
+ #![ allow( clippy:: match_like_matches_macro) ]
2
3
3
4
use std:: fs:: File ;
4
5
use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
@@ -50,23 +51,23 @@ fn do_cc() {
50
51
51
52
fn do_ctest ( ) {
52
53
match & env:: var ( "TARGET" ) . unwrap ( ) {
53
- t if t. contains ( "android" ) => return test_android ( t) ,
54
- t if t. contains ( "apple" ) => return test_apple ( t) ,
55
- t if t. contains ( "dragonfly" ) => return test_dragonflybsd ( t) ,
56
- t if t. contains ( "emscripten" ) => return test_emscripten ( t) ,
57
- t if t. contains ( "freebsd" ) => return test_freebsd ( t) ,
58
- t if t. contains ( "haiku" ) => return test_haiku ( t) ,
59
- t if t. contains ( "linux" ) => return test_linux ( t) ,
60
- t if t. contains ( "netbsd" ) => return test_netbsd ( t) ,
61
- t if t. contains ( "openbsd" ) => return test_openbsd ( t) ,
62
- t if t. contains ( "cygwin" ) => return test_cygwin ( t) ,
63
- t if t. contains ( "redox" ) => return test_redox ( t) ,
64
- t if t. contains ( "solaris" ) => return test_solarish ( t) ,
65
- t if t. contains ( "illumos" ) => return test_solarish ( t) ,
66
- t if t. contains ( "wasi" ) => return test_wasi ( t) ,
67
- t if t. contains ( "windows" ) => return test_windows ( t) ,
68
- t if t. contains ( "vxworks" ) => return test_vxworks ( t) ,
69
- t if t. contains ( "nto-qnx" ) => return test_neutrino ( t) ,
54
+ t if t. contains ( "android" ) => test_android ( t) ,
55
+ t if t. contains ( "apple" ) => test_apple ( t) ,
56
+ t if t. contains ( "dragonfly" ) => test_dragonflybsd ( t) ,
57
+ t if t. contains ( "emscripten" ) => test_emscripten ( t) ,
58
+ t if t. contains ( "freebsd" ) => test_freebsd ( t) ,
59
+ t if t. contains ( "haiku" ) => test_haiku ( t) ,
60
+ t if t. contains ( "linux" ) => test_linux ( t) ,
61
+ t if t. contains ( "netbsd" ) => test_netbsd ( t) ,
62
+ t if t. contains ( "openbsd" ) => test_openbsd ( t) ,
63
+ t if t. contains ( "cygwin" ) => test_cygwin ( t) ,
64
+ t if t. contains ( "redox" ) => test_redox ( t) ,
65
+ t if t. contains ( "solaris" ) => test_solarish ( t) ,
66
+ t if t. contains ( "illumos" ) => test_solarish ( t) ,
67
+ t if t. contains ( "wasi" ) => test_wasi ( t) ,
68
+ t if t. contains ( "windows" ) => test_windows ( t) ,
69
+ t if t. contains ( "vxworks" ) => test_vxworks ( t) ,
70
+ t if t. contains ( "nto-qnx" ) => test_neutrino ( t) ,
70
71
t => panic ! ( "unknown target {t}" ) ,
71
72
}
72
73
}
@@ -104,7 +105,7 @@ fn do_semver() {
104
105
process_semver_file ( & mut output, & mut semver_root, & os) ;
105
106
let os_arch = format ! ( "{os}-{arch}" ) ;
106
107
process_semver_file ( & mut output, & mut semver_root, & os_arch) ;
107
- if target_env != "" {
108
+ if !target_env . is_empty ( ) {
108
109
let os_env = format ! ( "{os}-{target_env}" ) ;
109
110
process_semver_file ( & mut output, & mut semver_root, & os_env) ;
110
111
@@ -129,21 +130,21 @@ fn process_semver_file<W: Write, P: AsRef<Path>>(output: &mut W, path: &mut Path
129
130
} ;
130
131
let input = BufReader :: new ( input_file) ;
131
132
132
- write ! ( output, "// Source: {}.\n " , path. display( ) ) . unwrap ( ) ;
133
- output. write ( b"use libc::{\n " ) . unwrap ( ) ;
133
+ writeln ! ( output, "// Source: {}." , path. display( ) ) . unwrap ( ) ;
134
+ output. write_all ( b"use libc::{\n " ) . unwrap ( ) ;
134
135
for line in input. lines ( ) {
135
136
let line = line. unwrap ( ) . into_bytes ( ) ;
136
137
match line. first ( ) {
137
138
// Ignore comments and empty lines.
138
139
Some ( b'#' ) | None => continue ,
139
140
_ => {
140
- output. write ( b" " ) . unwrap ( ) ;
141
- output. write ( & line) . unwrap ( ) ;
142
- output. write ( b",\n " ) . unwrap ( ) ;
141
+ output. write_all ( b" " ) . unwrap ( ) ;
142
+ output. write_all ( & line) . unwrap ( ) ;
143
+ output. write_all ( b",\n " ) . unwrap ( ) ;
143
144
}
144
145
}
145
146
}
146
- output. write ( b"};\n \n " ) . unwrap ( ) ;
147
+ output. write_all ( b"};\n \n " ) . unwrap ( ) ;
147
148
path. pop ( ) ;
148
149
}
149
150
@@ -165,8 +166,10 @@ fn main() {
165
166
do_semver ( ) ;
166
167
}
167
168
169
+ // FIXME(clippy): removing `replace` somehow fails the `Test tier1 (x86_64-pc-windows-msvc, windows-2022)` CI job
170
+ #[ allow( clippy:: only_used_in_recursion) ]
168
171
fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex , replace : & [ u8 ] ) {
169
- std:: fs:: create_dir ( & dst) . unwrap ( ) ;
172
+ std:: fs:: create_dir ( dst) . unwrap ( ) ;
170
173
for entry in src. read_dir ( ) . unwrap ( ) {
171
174
let entry = entry. unwrap ( ) ;
172
175
let src_path = entry. path ( ) ;
@@ -712,7 +715,7 @@ fn test_cygwin(target: &str) {
712
715
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
713
716
714
717
// sigval is a struct in Rust, but a union in C:
715
- "sigval" => format ! ( "union sigval" ) ,
718
+ "sigval" => "union sigval" . to_string ( ) ,
716
719
717
720
// put `struct` in front of all structs:.
718
721
t if is_struct => format ! ( "struct {t}" ) ,
@@ -1449,6 +1452,7 @@ fn test_netbsd(target: &str) {
1449
1452
} ) ;
1450
1453
1451
1454
cfg. skip_fn ( move |name| {
1455
+ #[ expect( clippy:: wildcard_in_or_patterns) ]
1452
1456
match name {
1453
1457
// FIXME(netbsd): netbsd 10 minimum
1454
1458
"getentropy" | "getrandom" => true ,
@@ -1597,7 +1601,7 @@ fn test_dragonflybsd(target: &str) {
1597
1601
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1598
1602
1599
1603
// sigval is a struct in Rust, but a union in C:
1600
- "sigval" => format ! ( "union sigval" ) ,
1604
+ "sigval" => "union sigval" . to_string ( ) ,
1601
1605
1602
1606
// put `struct` in front of all structs:.
1603
1607
t if is_struct => format ! ( "struct {t}" ) ,
@@ -1984,7 +1988,7 @@ fn test_android(target: &str) {
1984
1988
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1985
1989
1986
1990
// sigval is a struct in Rust, but a union in C:
1987
- "sigval" => format ! ( "union sigval" ) ,
1991
+ "sigval" => "union sigval" . to_string ( ) ,
1988
1992
1989
1993
// put `struct` in front of all structs:.
1990
1994
t if is_struct => format ! ( "struct {t}" ) ,
@@ -2346,18 +2350,9 @@ fn test_freebsd(target: &str) {
2346
2350
// Required for making freebsd11_stat available in the headers
2347
2351
cfg. define ( "_WANT_FREEBSD11_STAT" , None ) ;
2348
2352
2349
- let freebsd13 = match freebsd_ver {
2350
- Some ( n) if n >= 13 => true ,
2351
- _ => false ,
2352
- } ;
2353
- let freebsd14 = match freebsd_ver {
2354
- Some ( n) if n >= 14 => true ,
2355
- _ => false ,
2356
- } ;
2357
- let freebsd15 = match freebsd_ver {
2358
- Some ( n) if n >= 15 => true ,
2359
- _ => false ,
2360
- } ;
2353
+ let freebsd13 = matches ! ( freebsd_ver, Some ( n) if n >= 13 ) ;
2354
+ let freebsd14 = matches ! ( freebsd_ver, Some ( n) if n >= 14 ) ;
2355
+ let freebsd15 = matches ! ( freebsd_ver, Some ( n) if n >= 15 ) ;
2361
2356
2362
2357
headers ! { cfg:
2363
2358
"aio.h" ,
@@ -2500,7 +2495,7 @@ fn test_freebsd(target: &str) {
2500
2495
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
2501
2496
2502
2497
// sigval is a struct in Rust, but a union in C:
2503
- "sigval" => format ! ( "union sigval" ) ,
2498
+ "sigval" => "union sigval" . to_string ( ) ,
2504
2499
2505
2500
// put `struct` in front of all structs:.
2506
2501
t if is_struct => format ! ( "struct {t}" ) ,
@@ -3237,7 +3232,7 @@ fn test_neutrino(target: &str) {
3237
3232
3238
3233
let mut cfg = ctest_cfg ( ) ;
3239
3234
if target. ends_with ( "_iosock" ) {
3240
- let qnx_target_val = std :: env:: var ( "QNX_TARGET" )
3235
+ let qnx_target_val = env:: var ( "QNX_TARGET" )
3241
3236
. unwrap_or_else ( |_| "QNX_TARGET_not_set_please_source_qnxsdp" . into ( ) ) ;
3242
3237
3243
3238
cfg. include ( qnx_target_val + "/usr/include/io-sock" ) ;
@@ -3484,17 +3479,17 @@ fn test_neutrino(target: &str) {
3484
3479
struct_ == "_idle_hook" && field == "time"
3485
3480
} ) ;
3486
3481
3487
- cfg. skip_field ( move |struct_, field| {
3488
- ( struct_ == "__sched_param" && field == "reserved" ) ||
3489
- ( struct_ == "sched_param" && field == "reserved" ) ||
3490
- ( struct_ == "sigevent" && field == "__padding1" ) || // ensure alignment
3491
- ( struct_ == "sigevent" && field == "__padding2" ) || // union
3492
- ( struct_ == "sigevent" && field == "__sigev_un2 ") || // union
3493
- // sighandler_t type is super weird
3494
- ( struct_ == "sigaction" && field == "sa_sigaction ") ||
3495
- // does not exist
3496
- ( struct_ == "syspage_entry" && field == "__reserved" ) ||
3497
- false // keep me for smaller diffs when something is added above
3482
+ cfg. skip_field ( |struct_, field| {
3483
+ matches ! (
3484
+ ( struct_ , field ) ,
3485
+ ( "__sched_param" , "reserved" )
3486
+ | ( "sched_param" , "reserved" )
3487
+ | ( "sigevent" , "__padding1 ") // ensure alignment
3488
+ | ( "sigevent" , "__padding2" ) // union
3489
+ | ( "sigevent" , "__sigev_un2 ") // union
3490
+ | ( "sigaction" , "sa_sigaction" ) // sighandler_t type is super weird
3491
+ | ( "syspage_entry" , "__reserved" ) // does not exist
3492
+ )
3498
3493
} ) ;
3499
3494
3500
3495
cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
@@ -3584,9 +3579,7 @@ fn test_vxworks(target: &str) {
3584
3579
_ => false ,
3585
3580
} ) ;
3586
3581
3587
- cfg. skip_roundtrip ( move |s| match s {
3588
- _ => false ,
3589
- } ) ;
3582
+ cfg. skip_roundtrip ( |_| false ) ;
3590
3583
3591
3584
cfg. type_name ( move |ty, is_struct, is_union| match ty {
3592
3585
"DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty. to_string ( ) ,
@@ -4846,8 +4839,8 @@ fn test_linux_like_apis(target: &str) {
4846
4839
"strerror_r" => false ,
4847
4840
_ => true ,
4848
4841
} )
4849
- . skip_const ( |_| true )
4850
- . skip_struct ( |_| true ) ;
4842
+ . skip_const ( |_| true )
4843
+ . skip_struct ( |_| true ) ;
4851
4844
cfg. generate ( src_hotfix_dir ( ) . join ( "lib.rs" ) , "linux_strerror_r.rs" ) ;
4852
4845
}
4853
4846
@@ -4921,10 +4914,10 @@ fn test_linux_like_apis(target: &str) {
4921
4914
. skip_const ( |_| true )
4922
4915
. skip_struct ( |_| true )
4923
4916
. skip_const ( move |name| match name {
4924
- "IPV6_FLOWINFO"
4925
- | "IPV6_FLOWLABEL_MGR"
4926
- | "IPV6_FLOWINFO_SEND"
4927
- | "IPV6_FLOWINFO_FLOWLABEL"
4917
+ "IPV6_FLOWINFO"
4918
+ | "IPV6_FLOWLABEL_MGR"
4919
+ | "IPV6_FLOWINFO_SEND"
4920
+ | "IPV6_FLOWINFO_FLOWLABEL"
4928
4921
| "IPV6_FLOWINFO_PRIORITY" => false ,
4929
4922
_ => true ,
4930
4923
} )
@@ -5314,7 +5307,7 @@ fn test_haiku(target: &str) {
5314
5307
}
5315
5308
5316
5309
// is actually a union
5317
- "sigval" => format ! ( "union sigval" ) ,
5310
+ "sigval" => "union sigval" . to_string ( ) ,
5318
5311
t if is_union => format ! ( "union {t}" ) ,
5319
5312
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
5320
5313
t if is_struct => format ! ( "struct {t}" ) ,
0 commit comments