Skip to content

Commit b21e075

Browse files
nyuriktgross35
authored andcommitted
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 (backport <rust-lang#4412>) [ adjust section heading to avoid ### turning into comment - Trevor ] (cherry picked from commit 8b15e27)
1 parent d716b80 commit b21e075

File tree

3 files changed

+59
-80
lines changed

3 files changed

+59
-80
lines changed

libc-test/Cargo.toml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,5 @@ harness = true
109109
# once MSRV is above 1.64 and replaced with `[lints] workspace=true`
110110

111111
[lints.rust]
112-
# FIXME(cleanup): make ident usage consistent in each file
113-
unused_qualifications = "allow"
114112

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

libc-test/build.rs

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

34
extern crate ctest2 as ctest;
45

@@ -52,23 +53,23 @@ fn do_cc() {
5253

5354
fn do_ctest() {
5455
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),
7273
t => panic!("unknown target {t}"),
7374
}
7475
}
@@ -111,7 +112,7 @@ fn do_semver() {
111112
process_semver_file(&mut output, &mut semver_root, &os);
112113
let os_arch = format!("{os}-{arch}");
113114
process_semver_file(&mut output, &mut semver_root, &os_arch);
114-
if target_env != "" {
115+
if !target_env.is_empty() {
115116
let os_env = format!("{os}-{target_env}");
116117
process_semver_file(&mut output, &mut semver_root, &os_env);
117118

@@ -136,21 +137,21 @@ fn process_semver_file<W: Write, P: AsRef<Path>>(output: &mut W, path: &mut Path
136137
};
137138
let input = BufReader::new(input_file);
138139

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();
141142
for line in input.lines() {
142143
let line = line.unwrap().into_bytes();
143144
match line.first() {
144145
// Ignore comments and empty lines.
145146
Some(b'#') | None => continue,
146147
_ => {
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();
150151
}
151152
}
152153
}
153-
output.write(b"};\n\n").unwrap();
154+
output.write_all(b"};\n\n").unwrap();
154155
path.pop();
155156
}
156157

@@ -172,8 +173,10 @@ fn main() {
172173
do_semver();
173174
}
174175

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)]
175178
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();
177180
for entry in src.read_dir().unwrap() {
178181
let entry = entry.unwrap();
179182
let src_path = entry.path();
@@ -758,7 +761,7 @@ fn test_cygwin(target: &str) {
758761
t if t.ends_with("_t") => t.to_string(),
759762

760763
// sigval is a struct in Rust, but a union in C:
761-
"sigval" => format!("union sigval"),
764+
"sigval" => "union sigval".to_string(),
762765

763766
// put `struct` in front of all structs:.
764767
t if is_struct => format!("struct {t}"),
@@ -1505,6 +1508,7 @@ fn test_netbsd(target: &str) {
15051508
});
15061509

15071510
cfg.skip_fn(move |name| {
1511+
#[expect(clippy::wildcard_in_or_patterns)]
15081512
match name {
15091513
// FIXME(netbsd): https://github.com/rust-lang/libc/issues/1272
15101514
"execv" | "execve" | "execvp" => true,
@@ -1655,7 +1659,7 @@ fn test_dragonflybsd(target: &str) {
16551659
t if t.ends_with("_t") => t.to_string(),
16561660

16571661
// sigval is a struct in Rust, but a union in C:
1658-
"sigval" => format!("union sigval"),
1662+
"sigval" => "union sigval".to_string(),
16591663

16601664
// put `struct` in front of all structs:.
16611665
t if is_struct => format!("struct {t}"),
@@ -2045,7 +2049,7 @@ fn test_android(target: &str) {
20452049
t if t.ends_with("_t") => t.to_string(),
20462050

20472051
// sigval is a struct in Rust, but a union in C:
2048-
"sigval" => format!("union sigval"),
2052+
"sigval" => "union sigval".to_string(),
20492053

20502054
// put `struct` in front of all structs:.
20512055
t if is_struct => format!("struct {t}"),
@@ -2404,18 +2408,9 @@ fn test_freebsd(target: &str) {
24042408
// Required for making freebsd11_stat available in the headers
24052409
cfg.define("_WANT_FREEBSD11_STAT", None);
24062410

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

24202415
headers! { cfg:
24212416
"aio.h",
@@ -2558,7 +2553,7 @@ fn test_freebsd(target: &str) {
25582553
t if t.ends_with("_t") => t.to_string(),
25592554

25602555
// sigval is a struct in Rust, but a union in C:
2561-
"sigval" => format!("union sigval"),
2556+
"sigval" => "union sigval".to_string(),
25622557

25632558
// put `struct` in front of all structs:.
25642559
t if is_struct => format!("struct {t}"),
@@ -3308,7 +3303,7 @@ fn test_neutrino(target: &str) {
33083303

33093304
let mut cfg = ctest_cfg();
33103305
if target.ends_with("_iosock") {
3311-
let qnx_target_val = std::env::var("QNX_TARGET")
3306+
let qnx_target_val = env::var("QNX_TARGET")
33123307
.unwrap_or_else(|_| "QNX_TARGET_not_set_please_source_qnxsdp".into());
33133308

33143309
cfg.include(qnx_target_val + "/usr/include/io-sock");
@@ -3558,17 +3553,17 @@ fn test_neutrino(target: &str) {
35583553
struct_ == "_idle_hook" && field == "time"
35593554
});
35603555

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+
)
35723567
});
35733568

35743569
cfg.skip_static(move |name| (name == "__dso_handle"));
@@ -3658,9 +3653,7 @@ fn test_vxworks(target: &str) {
36583653
_ => false,
36593654
});
36603655

3661-
cfg.skip_roundtrip(move |s| match s {
3662-
_ => false,
3663-
});
3656+
cfg.skip_roundtrip(|_| false);
36643657

36653658
cfg.type_name(move |ty, is_struct, is_union| match ty {
36663659
"DIR" | "FILE" | "Dl_info" | "RTP_DESC" => ty.to_string(),
@@ -4959,8 +4952,8 @@ fn test_linux_like_apis(target: &str) {
49594952
"strerror_r" => false,
49604953
_ => true,
49614954
})
4962-
.skip_const(|_| true)
4963-
.skip_struct(|_| true);
4955+
.skip_const(|_| true)
4956+
.skip_struct(|_| true);
49644957
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
49654958
}
49664959

@@ -5034,10 +5027,10 @@ fn test_linux_like_apis(target: &str) {
50345027
.skip_const(|_| true)
50355028
.skip_struct(|_| true)
50365029
.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"
50415034
| "IPV6_FLOWINFO_PRIORITY" => false,
50425035
_ => true,
50435036
})
@@ -5429,7 +5422,7 @@ fn test_haiku(target: &str) {
54295422
}
54305423

54315424
// is actually a union
5432-
"sigval" => format!("union sigval"),
5425+
"sigval" => "union sigval".to_string(),
54335426
t if is_union => format!("union {t}"),
54345427
t if t.ends_with("_t") => t.to_string(),
54355428
t if is_struct => format!("struct {t}"),

libc-test/test/makedev.rs

Lines changed: 3 additions & 3 deletions
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)