Skip to content

Commit 8b15e27

Browse files
committed
chore: lint libc-test/build.rs
run `cargo clippy --all-targets` on `libc-test/build.rs`, and fix all default issues. ### Notes * `copy_dir_hotfix` had a `replace` parameter that was never used
1 parent d00adf4 commit 8b15e27

File tree

3 files changed

+59
-80
lines changed

3 files changed

+59
-80
lines changed

libc-test/Cargo.toml

-14
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,5 @@ harness = true
107107
# once MSRV is above 1.64 and replaced with `[lints] workspace=true`
108108

109109
[lints.rust]
110-
# FIXME(cleanup): make ident usage consistent in each file
111-
unused_qualifications = "allow"
112110

113111
[lints.clippy]
114-
# FIXME(clippy): fix these
115-
needless_return = "allow"
116-
comparison_to_empty = "allow"
117-
unused_io_amount = "allow"
118-
write_with_newline = "allow"
119-
needless_borrows_for_generic_args = "allow"
120-
only_used_in_recursion = "allow"
121-
match_like_matches_macro = "allow"
122-
useless_format = "allow"
123-
wildcard_in_or_patterns = "allow"
124-
nonminimal_bool = "allow"
125-
match_single_binding = "allow"

libc-test/build.rs

+56-63
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(warnings)]
2+
#![allow(clippy::match_like_matches_macro)]
23

34
use std::fs::File;
45
use std::io::{BufRead, BufReader, BufWriter, Write};
@@ -50,23 +51,23 @@ fn do_cc() {
5051

5152
fn do_ctest() {
5253
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),
7071
t => panic!("unknown target {t}"),
7172
}
7273
}
@@ -104,7 +105,7 @@ fn do_semver() {
104105
process_semver_file(&mut output, &mut semver_root, &os);
105106
let os_arch = format!("{os}-{arch}");
106107
process_semver_file(&mut output, &mut semver_root, &os_arch);
107-
if target_env != "" {
108+
if !target_env.is_empty() {
108109
let os_env = format!("{os}-{target_env}");
109110
process_semver_file(&mut output, &mut semver_root, &os_env);
110111

@@ -129,21 +130,21 @@ fn process_semver_file<W: Write, P: AsRef<Path>>(output: &mut W, path: &mut Path
129130
};
130131
let input = BufReader::new(input_file);
131132

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();
134135
for line in input.lines() {
135136
let line = line.unwrap().into_bytes();
136137
match line.first() {
137138
// Ignore comments and empty lines.
138139
Some(b'#') | None => continue,
139140
_ => {
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();
143144
}
144145
}
145146
}
146-
output.write(b"};\n\n").unwrap();
147+
output.write_all(b"};\n\n").unwrap();
147148
path.pop();
148149
}
149150

@@ -165,8 +166,10 @@ fn main() {
165166
do_semver();
166167
}
167168

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)]
168171
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();
170173
for entry in src.read_dir().unwrap() {
171174
let entry = entry.unwrap();
172175
let src_path = entry.path();
@@ -712,7 +715,7 @@ fn test_cygwin(target: &str) {
712715
t if t.ends_with("_t") => t.to_string(),
713716

714717
// sigval is a struct in Rust, but a union in C:
715-
"sigval" => format!("union sigval"),
718+
"sigval" => "union sigval".to_string(),
716719

717720
// put `struct` in front of all structs:.
718721
t if is_struct => format!("struct {t}"),
@@ -1449,6 +1452,7 @@ fn test_netbsd(target: &str) {
14491452
});
14501453

14511454
cfg.skip_fn(move |name| {
1455+
#[expect(clippy::wildcard_in_or_patterns)]
14521456
match name {
14531457
// FIXME(netbsd): netbsd 10 minimum
14541458
"getentropy" | "getrandom" => true,
@@ -1597,7 +1601,7 @@ fn test_dragonflybsd(target: &str) {
15971601
t if t.ends_with("_t") => t.to_string(),
15981602

15991603
// sigval is a struct in Rust, but a union in C:
1600-
"sigval" => format!("union sigval"),
1604+
"sigval" => "union sigval".to_string(),
16011605

16021606
// put `struct` in front of all structs:.
16031607
t if is_struct => format!("struct {t}"),
@@ -1984,7 +1988,7 @@ fn test_android(target: &str) {
19841988
t if t.ends_with("_t") => t.to_string(),
19851989

19861990
// sigval is a struct in Rust, but a union in C:
1987-
"sigval" => format!("union sigval"),
1991+
"sigval" => "union sigval".to_string(),
19881992

19891993
// put `struct` in front of all structs:.
19901994
t if is_struct => format!("struct {t}"),
@@ -2346,18 +2350,9 @@ fn test_freebsd(target: &str) {
23462350
// Required for making freebsd11_stat available in the headers
23472351
cfg.define("_WANT_FREEBSD11_STAT", None);
23482352

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);
23612356

23622357
headers! { cfg:
23632358
"aio.h",
@@ -2500,7 +2495,7 @@ fn test_freebsd(target: &str) {
25002495
t if t.ends_with("_t") => t.to_string(),
25012496

25022497
// sigval is a struct in Rust, but a union in C:
2503-
"sigval" => format!("union sigval"),
2498+
"sigval" => "union sigval".to_string(),
25042499

25052500
// put `struct` in front of all structs:.
25062501
t if is_struct => format!("struct {t}"),
@@ -3237,7 +3232,7 @@ fn test_neutrino(target: &str) {
32373232

32383233
let mut cfg = ctest_cfg();
32393234
if target.ends_with("_iosock") {
3240-
let qnx_target_val = std::env::var("QNX_TARGET")
3235+
let qnx_target_val = env::var("QNX_TARGET")
32413236
.unwrap_or_else(|_| "QNX_TARGET_not_set_please_source_qnxsdp".into());
32423237

32433238
cfg.include(qnx_target_val + "/usr/include/io-sock");
@@ -3484,17 +3479,17 @@ fn test_neutrino(target: &str) {
34843479
struct_ == "_idle_hook" && field == "time"
34853480
});
34863481

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+
)
34983493
});
34993494

35003495
cfg.skip_static(move |name| (name == "__dso_handle"));
@@ -3584,9 +3579,7 @@ fn test_vxworks(target: &str) {
35843579
_ => false,
35853580
});
35863581

3587-
cfg.skip_roundtrip(move |s| match s {
3588-
_ => false,
3589-
});
3582+
cfg.skip_roundtrip(|_| false);
35903583

35913584
cfg.type_name(move |ty, is_struct, is_union| match ty {
35923585
"DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty.to_string(),
@@ -4846,8 +4839,8 @@ fn test_linux_like_apis(target: &str) {
48464839
"strerror_r" => false,
48474840
_ => true,
48484841
})
4849-
.skip_const(|_| true)
4850-
.skip_struct(|_| true);
4842+
.skip_const(|_| true)
4843+
.skip_struct(|_| true);
48514844
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
48524845
}
48534846

@@ -4921,10 +4914,10 @@ fn test_linux_like_apis(target: &str) {
49214914
.skip_const(|_| true)
49224915
.skip_struct(|_| true)
49234916
.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"
49284921
| "IPV6_FLOWINFO_PRIORITY" => false,
49294922
_ => true,
49304923
})
@@ -5314,7 +5307,7 @@ fn test_haiku(target: &str) {
53145307
}
53155308

53165309
// is actually a union
5317-
"sigval" => format!("union sigval"),
5310+
"sigval" => "union sigval".to_string(),
53185311
t if is_union => format!("union {t}"),
53195312
t if t.ends_with("_t") => t.to_string(),
53205313
t if is_struct => format!("struct {t}"),

libc-test/test/makedev.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ cfg_if::cfg_if! {
3030
target_os = "openbsd",
3131
target_os = "cygwin",
3232
))] {
33-
pub type MajorRetType = libc::c_uint;
34-
pub type MinorRetType = libc::c_uint;
33+
pub type MajorRetType = c_uint;
34+
pub type MinorRetType = c_uint;
3535
} else if #[cfg(any(
3636
target_os = "android",
3737
target_os = "dragonfly",
@@ -129,7 +129,7 @@ fn test_openbsd_like() {
129129
))]
130130
#[test]
131131
fn test_fbsd12_like() {
132-
if std::mem::size_of::<dev_t>() >= 8 {
132+
if size_of::<dev_t>() >= 8 {
133133
for major_exp in [0, 16, 24, 31] {
134134
for major in [(1 << major_exp) - 1, (1 << major_exp)] {
135135
for minor_exp in [1, 8, 16, 24, 31] {

0 commit comments

Comments
 (0)