1
1
#![ deny( warnings) ]
2
+ #![ allow( clippy:: match_like_matches_macro) ]
2
3
3
4
extern crate ctest2 as ctest;
4
5
@@ -52,23 +53,23 @@ fn do_cc() {
52
53
53
54
fn do_ctest ( ) {
54
55
match & env:: var ( "TARGET" ) . unwrap ( ) {
55
- t if t. contains ( "android" ) => return test_android ( t) ,
56
- t if t. contains ( "apple" ) => return test_apple ( t) ,
57
- t if t. contains ( "dragonfly" ) => return test_dragonflybsd ( t) ,
58
- t if t. contains ( "emscripten" ) => return test_emscripten ( t) ,
59
- t if t. contains ( "freebsd" ) => return test_freebsd ( t) ,
60
- t if t. contains ( "haiku" ) => return test_haiku ( t) ,
61
- t if t. contains ( "linux" ) => return test_linux ( t) ,
62
- t if t. contains ( "netbsd" ) => return test_netbsd ( t) ,
63
- t if t. contains ( "openbsd" ) => return test_openbsd ( t) ,
64
- t if t. contains ( "cygwin" ) => return test_cygwin ( t) ,
65
- t if t. contains ( "redox" ) => return test_redox ( t) ,
66
- t if t. contains ( "solaris" ) => return test_solarish ( t) ,
67
- t if t. contains ( "illumos" ) => return test_solarish ( t) ,
68
- t if t. contains ( "wasi" ) => return test_wasi ( t) ,
69
- t if t. contains ( "windows" ) => return test_windows ( t) ,
70
- t if t. contains ( "vxworks" ) => return test_vxworks ( t) ,
71
- t if t. contains ( "nto-qnx" ) => return test_neutrino ( t) ,
56
+ t if t. contains ( "android" ) => test_android ( t) ,
57
+ t if t. contains ( "apple" ) => test_apple ( t) ,
58
+ t if t. contains ( "dragonfly" ) => test_dragonflybsd ( t) ,
59
+ t if t. contains ( "emscripten" ) => test_emscripten ( t) ,
60
+ t if t. contains ( "freebsd" ) => test_freebsd ( t) ,
61
+ t if t. contains ( "haiku" ) => test_haiku ( t) ,
62
+ t if t. contains ( "linux" ) => test_linux ( t) ,
63
+ t if t. contains ( "netbsd" ) => test_netbsd ( t) ,
64
+ t if t. contains ( "openbsd" ) => test_openbsd ( t) ,
65
+ t if t. contains ( "cygwin" ) => test_cygwin ( t) ,
66
+ t if t. contains ( "redox" ) => test_redox ( t) ,
67
+ t if t. contains ( "solaris" ) => test_solarish ( t) ,
68
+ t if t. contains ( "illumos" ) => test_solarish ( t) ,
69
+ t if t. contains ( "wasi" ) => test_wasi ( t) ,
70
+ t if t. contains ( "windows" ) => test_windows ( t) ,
71
+ t if t. contains ( "vxworks" ) => test_vxworks ( t) ,
72
+ t if t. contains ( "nto-qnx" ) => test_neutrino ( t) ,
72
73
t => panic ! ( "unknown target {t}" ) ,
73
74
}
74
75
}
@@ -111,7 +112,7 @@ fn do_semver() {
111
112
process_semver_file ( & mut output, & mut semver_root, & os) ;
112
113
let os_arch = format ! ( "{os}-{arch}" ) ;
113
114
process_semver_file ( & mut output, & mut semver_root, & os_arch) ;
114
- if target_env != "" {
115
+ if !target_env . is_empty ( ) {
115
116
let os_env = format ! ( "{os}-{target_env}" ) ;
116
117
process_semver_file ( & mut output, & mut semver_root, & os_env) ;
117
118
@@ -136,21 +137,21 @@ fn process_semver_file<W: Write, P: AsRef<Path>>(output: &mut W, path: &mut Path
136
137
} ;
137
138
let input = BufReader :: new ( input_file) ;
138
139
139
- write ! ( output, "// Source: {}.\n " , path. display( ) ) . unwrap ( ) ;
140
- output. write ( b"use libc::{\n " ) . unwrap ( ) ;
140
+ writeln ! ( output, "// Source: {}." , path. display( ) ) . unwrap ( ) ;
141
+ output. write_all ( b"use libc::{\n " ) . unwrap ( ) ;
141
142
for line in input. lines ( ) {
142
143
let line = line. unwrap ( ) . into_bytes ( ) ;
143
144
match line. first ( ) {
144
145
// Ignore comments and empty lines.
145
146
Some ( b'#' ) | None => continue ,
146
147
_ => {
147
- output. write ( b" " ) . unwrap ( ) ;
148
- output. write ( & line) . unwrap ( ) ;
149
- output. write ( b",\n " ) . unwrap ( ) ;
148
+ output. write_all ( b" " ) . unwrap ( ) ;
149
+ output. write_all ( & line) . unwrap ( ) ;
150
+ output. write_all ( b",\n " ) . unwrap ( ) ;
150
151
}
151
152
}
152
153
}
153
- output. write ( b"};\n \n " ) . unwrap ( ) ;
154
+ output. write_all ( b"};\n \n " ) . unwrap ( ) ;
154
155
path. pop ( ) ;
155
156
}
156
157
@@ -172,8 +173,10 @@ fn main() {
172
173
do_semver ( ) ;
173
174
}
174
175
176
+ // FIXME(clippy): removing `replace` somehow fails the `Test tier1 (x86_64-pc-windows-msvc, windows-2022)` CI job
177
+ #[ allow( clippy:: only_used_in_recursion) ]
175
178
fn copy_dir_hotfix ( src : & Path , dst : & Path , regex : & regex:: bytes:: Regex , replace : & [ u8 ] ) {
176
- std:: fs:: create_dir ( & dst) . unwrap ( ) ;
179
+ std:: fs:: create_dir ( dst) . unwrap ( ) ;
177
180
for entry in src. read_dir ( ) . unwrap ( ) {
178
181
let entry = entry. unwrap ( ) ;
179
182
let src_path = entry. path ( ) ;
@@ -758,7 +761,7 @@ fn test_cygwin(target: &str) {
758
761
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
759
762
760
763
// sigval is a struct in Rust, but a union in C:
761
- "sigval" => format ! ( "union sigval" ) ,
764
+ "sigval" => "union sigval" . to_string ( ) ,
762
765
763
766
// put `struct` in front of all structs:.
764
767
t if is_struct => format ! ( "struct {t}" ) ,
@@ -1505,6 +1508,7 @@ fn test_netbsd(target: &str) {
1505
1508
} ) ;
1506
1509
1507
1510
cfg. skip_fn ( move |name| {
1511
+ #[ expect( clippy:: wildcard_in_or_patterns) ]
1508
1512
match name {
1509
1513
// FIXME(netbsd): https://github.com/rust-lang/libc/issues/1272
1510
1514
"execv" | "execve" | "execvp" => true ,
@@ -1655,7 +1659,7 @@ fn test_dragonflybsd(target: &str) {
1655
1659
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1656
1660
1657
1661
// sigval is a struct in Rust, but a union in C:
1658
- "sigval" => format ! ( "union sigval" ) ,
1662
+ "sigval" => "union sigval" . to_string ( ) ,
1659
1663
1660
1664
// put `struct` in front of all structs:.
1661
1665
t if is_struct => format ! ( "struct {t}" ) ,
@@ -2045,7 +2049,7 @@ fn test_android(target: &str) {
2045
2049
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
2046
2050
2047
2051
// sigval is a struct in Rust, but a union in C:
2048
- "sigval" => format ! ( "union sigval" ) ,
2052
+ "sigval" => "union sigval" . to_string ( ) ,
2049
2053
2050
2054
// put `struct` in front of all structs:.
2051
2055
t if is_struct => format ! ( "struct {t}" ) ,
@@ -2404,18 +2408,9 @@ fn test_freebsd(target: &str) {
2404
2408
// Required for making freebsd11_stat available in the headers
2405
2409
cfg. define ( "_WANT_FREEBSD11_STAT" , None ) ;
2406
2410
2407
- let freebsd13 = match freebsd_ver {
2408
- Some ( n) if n >= 13 => true ,
2409
- _ => false ,
2410
- } ;
2411
- let freebsd14 = match freebsd_ver {
2412
- Some ( n) if n >= 14 => true ,
2413
- _ => false ,
2414
- } ;
2415
- let freebsd15 = match freebsd_ver {
2416
- Some ( n) if n >= 15 => true ,
2417
- _ => false ,
2418
- } ;
2411
+ let freebsd13 = matches ! ( freebsd_ver, Some ( n) if n >= 13 ) ;
2412
+ let freebsd14 = matches ! ( freebsd_ver, Some ( n) if n >= 14 ) ;
2413
+ let freebsd15 = matches ! ( freebsd_ver, Some ( n) if n >= 15 ) ;
2419
2414
2420
2415
headers ! { cfg:
2421
2416
"aio.h" ,
@@ -2558,7 +2553,7 @@ fn test_freebsd(target: &str) {
2558
2553
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
2559
2554
2560
2555
// sigval is a struct in Rust, but a union in C:
2561
- "sigval" => format ! ( "union sigval" ) ,
2556
+ "sigval" => "union sigval" . to_string ( ) ,
2562
2557
2563
2558
// put `struct` in front of all structs:.
2564
2559
t if is_struct => format ! ( "struct {t}" ) ,
@@ -3308,7 +3303,7 @@ fn test_neutrino(target: &str) {
3308
3303
3309
3304
let mut cfg = ctest_cfg ( ) ;
3310
3305
if target. ends_with ( "_iosock" ) {
3311
- let qnx_target_val = std :: env:: var ( "QNX_TARGET" )
3306
+ let qnx_target_val = env:: var ( "QNX_TARGET" )
3312
3307
. unwrap_or_else ( |_| "QNX_TARGET_not_set_please_source_qnxsdp" . into ( ) ) ;
3313
3308
3314
3309
cfg. include ( qnx_target_val + "/usr/include/io-sock" ) ;
@@ -3558,17 +3553,17 @@ fn test_neutrino(target: &str) {
3558
3553
struct_ == "_idle_hook" && field == "time"
3559
3554
} ) ;
3560
3555
3561
- cfg. skip_field ( move |struct_, field| {
3562
- ( struct_ == "__sched_param" && field == "reserved" ) ||
3563
- ( struct_ == "sched_param" && field == "reserved" ) ||
3564
- ( struct_ == "sigevent" && field == "__padding1" ) || // ensure alignment
3565
- ( struct_ == "sigevent" && field == "__padding2" ) || // union
3566
- ( struct_ == "sigevent" && field == "__sigev_un2 ") || // union
3567
- // sighandler_t type is super weird
3568
- ( struct_ == "sigaction" && field == "sa_sigaction ") ||
3569
- // does not exist
3570
- ( struct_ == "syspage_entry" && field == "__reserved" ) ||
3571
- false // keep me for smaller diffs when something is added above
3556
+ cfg. skip_field ( |struct_, field| {
3557
+ matches ! (
3558
+ ( struct_ , field ) ,
3559
+ ( "__sched_param" , "reserved" )
3560
+ | ( "sched_param" , "reserved" )
3561
+ | ( "sigevent" , "__padding1 ") // ensure alignment
3562
+ | ( "sigevent" , "__padding2" ) // union
3563
+ | ( "sigevent" , "__sigev_un2 ") // union
3564
+ | ( "sigaction" , "sa_sigaction" ) // sighandler_t type is super weird
3565
+ | ( "syspage_entry" , "__reserved" ) // does not exist
3566
+ )
3572
3567
} ) ;
3573
3568
3574
3569
cfg. skip_static ( move |name| ( name == "__dso_handle" ) ) ;
@@ -3658,9 +3653,7 @@ fn test_vxworks(target: &str) {
3658
3653
_ => false ,
3659
3654
} ) ;
3660
3655
3661
- cfg. skip_roundtrip ( move |s| match s {
3662
- _ => false ,
3663
- } ) ;
3656
+ cfg. skip_roundtrip ( |_| false ) ;
3664
3657
3665
3658
cfg. type_name ( move |ty, is_struct, is_union| match ty {
3666
3659
"DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty. to_string ( ) ,
@@ -4959,8 +4952,8 @@ fn test_linux_like_apis(target: &str) {
4959
4952
"strerror_r" => false ,
4960
4953
_ => true ,
4961
4954
} )
4962
- . skip_const ( |_| true )
4963
- . skip_struct ( |_| true ) ;
4955
+ . skip_const ( |_| true )
4956
+ . skip_struct ( |_| true ) ;
4964
4957
cfg. generate ( src_hotfix_dir ( ) . join ( "lib.rs" ) , "linux_strerror_r.rs" ) ;
4965
4958
}
4966
4959
@@ -5034,10 +5027,10 @@ fn test_linux_like_apis(target: &str) {
5034
5027
. skip_const ( |_| true )
5035
5028
. skip_struct ( |_| true )
5036
5029
. skip_const ( move |name| match name {
5037
- "IPV6_FLOWINFO"
5038
- | "IPV6_FLOWLABEL_MGR"
5039
- | "IPV6_FLOWINFO_SEND"
5040
- | "IPV6_FLOWINFO_FLOWLABEL"
5030
+ "IPV6_FLOWINFO"
5031
+ | "IPV6_FLOWLABEL_MGR"
5032
+ | "IPV6_FLOWINFO_SEND"
5033
+ | "IPV6_FLOWINFO_FLOWLABEL"
5041
5034
| "IPV6_FLOWINFO_PRIORITY" => false ,
5042
5035
_ => true ,
5043
5036
} )
@@ -5429,7 +5422,7 @@ fn test_haiku(target: &str) {
5429
5422
}
5430
5423
5431
5424
// is actually a union
5432
- "sigval" => format ! ( "union sigval" ) ,
5425
+ "sigval" => "union sigval" . to_string ( ) ,
5433
5426
t if is_union => format ! ( "union {t}" ) ,
5434
5427
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
5435
5428
t if is_struct => format ! ( "struct {t}" ) ,
0 commit comments