Skip to content

Commit d8275b5

Browse files
committed
chore: apply some clippy lints
1 parent 920cfdc commit d8275b5

File tree

21 files changed

+86
-71
lines changed

21 files changed

+86
-71
lines changed

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,19 @@ members = [
142142
"ctest-test",
143143
"libc-test",
144144
]
145+
146+
# FIXME(msrv): These should be renamed as `[workspace.lints.*]` once MSRV is above 1.64
147+
# This way all crates can use it with `[lints] workspace=true` section
148+
149+
[lints.rust]
150+
# FIXME(cleanup): should be cleaned up
151+
unused_qualifications = "allow" # make ident usage consistent in each file
152+
unused_imports = "allow"
153+
154+
[lints.clippy]
155+
identity_op = "allow" # some expressions like `0 | x` are clearer for bit ops
156+
missing_safety_doc = "allow" # safety? in libc? seriously?
157+
158+
# FIXME(clippy): all these should probably be fixed
159+
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this
160+
unnecessary_cast = "allow" # some casts like `as usize` are only needed for some targets

build.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{env, str};
44
// List of cfgs this build script is allowed to set. The list is needed to support check-cfg, as we
55
// need to know all the possible cfgs that this script will set. If you need to set another cfg
66
// make sure to add it to this list as well.
7-
const ALLOWED_CFGS: &'static [&'static str] = &[
7+
const ALLOWED_CFGS: &[&str] = &[
88
"emscripten_old_stat_abi",
99
"espidf_time32",
1010
"freebsd10",
@@ -24,7 +24,7 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
2424
];
2525

2626
// Extra values to allow for check-cfg.
27-
const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
27+
const CHECK_CFG_EXTRA: &[(&str, &[&str])] = &[
2828
(
2929
"target_os",
3030
&[
@@ -46,7 +46,6 @@ fn main() {
4646
println!("cargo:rerun-if-changed=build.rs");
4747

4848
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
49-
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
5049
let libc_ci = env::var("LIBC_CI").is_ok();
5150
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
5251
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
@@ -66,10 +65,8 @@ fn main() {
6665
vers
6766
} else if libc_ci {
6867
which_freebsd().unwrap_or(12)
69-
} else if rustc_dep_of_std {
70-
12
7168
} else {
72-
12
69+
12 // regardless of CARGO_FEATURE_RUSTC_DEP_OF_STD env var
7370
};
7471

7572
match which_freebsd {

src/fuchsia/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,9 +3429,9 @@ f! {
34293429

34303430
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
34313431
if ((*cmsg).cmsg_len as size_t) < mem::size_of::<cmsghdr>() {
3432-
0 as *mut cmsghdr
3432+
core::ptr::null_mut::<cmsghdr>()
34333433
} else if __CMSG_NEXT(cmsg).add(mem::size_of::<cmsghdr>()) >= __MHDR_END(mhdr) {
3434-
0 as *mut cmsghdr
3434+
core::ptr::null_mut::<cmsghdr>()
34353435
} else {
34363436
__CMSG_NEXT(cmsg).cast()
34373437
}
@@ -3441,7 +3441,7 @@ f! {
34413441
if (*mhdr).msg_controllen as size_t >= mem::size_of::<cmsghdr>() {
34423442
(*mhdr).msg_control.cast()
34433443
} else {
3444-
0 as *mut cmsghdr
3444+
core::ptr::null_mut::<cmsghdr>()
34453445
}
34463446
}
34473447

src/unix/aix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ f! {
24412441
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
24422442
(*mhdr).msg_control as *mut cmsghdr
24432443
} else {
2444-
0 as *mut cmsghdr
2444+
core::ptr::null_mut::<cmsghdr>()
24452445
}
24462446
}
24472447

@@ -2452,7 +2452,7 @@ f! {
24522452
if (cmsg as usize + (*cmsg).cmsg_len as usize + mem::size_of::<cmsghdr>())
24532453
> ((*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize)
24542454
{
2455-
0 as *mut cmsghdr
2455+
core::ptr::null_mut::<cmsghdr>()
24562456
} else {
24572457
// AIX does not have any alignment/padding for ancillary data, so we don't need _CMSG_ALIGN here.
24582458
(cmsg as usize + (*cmsg).cmsg_len as usize) as *mut cmsghdr

src/unix/bsd/apple/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5463,7 +5463,7 @@ pub const VMADDR_PORT_ANY: c_uint = 0xFFFFFFFF;
54635463

54645464
const fn __DARWIN_ALIGN32(p: usize) -> usize {
54655465
const __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1;
5466-
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
5466+
(p + __DARWIN_ALIGNBYTES32) & !__DARWIN_ALIGNBYTES32
54675467
}
54685468

54695469
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ f! {
15601560
if next <= max {
15611561
(cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
15621562
} else {
1563-
0 as *mut cmsghdr
1563+
core::ptr::null_mut::<cmsghdr>()
15641564
}
15651565
}
15661566

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4906,7 +4906,7 @@ const_fn! {
49064906

49074907
f! {
49084908
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
4909-
(cmsg as *mut c_uchar).offset(_ALIGN(mem::size_of::<cmsghdr>()) as isize)
4909+
(cmsg as *mut c_uchar).add(_ALIGN(mem::size_of::<cmsghdr>()))
49104910
}
49114911

49124912
pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
@@ -4921,7 +4921,7 @@ f! {
49214921
cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(mem::size_of::<cmsghdr>());
49224922
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
49234923
if next > max {
4924-
0 as *mut cmsghdr
4924+
core::ptr::null_mut::<cmsghdr>()
49254925
} else {
49264926
(cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
49274927
}
@@ -4968,14 +4968,12 @@ f! {
49684968
let bitset_bits = 8 * mem::size_of::<c_long>();
49694969
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
49704970
cpuset.__bits[idx] |= 1 << offset;
4971-
()
49724971
}
49734972

49744973
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpuset_t) -> () {
49754974
let bitset_bits = 8 * mem::size_of::<c_long>();
49764975
let (idx, offset) = (cpu / bitset_bits, cpu % bitset_bits);
49774976
cpuset.__bits[idx] &= !(1 << offset);
4978-
()
49794977
}
49804978

49814979
pub fn CPU_ISSET(cpu: usize, cpuset: &cpuset_t) -> bool {

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ const_fn! {
24232423

24242424
f! {
24252425
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
2426-
(cmsg as *mut c_uchar).offset(_ALIGN(mem::size_of::<cmsghdr>()) as isize)
2426+
(cmsg as *mut c_uchar).add(_ALIGN(mem::size_of::<cmsghdr>()))
24272427
}
24282428

24292429
pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
@@ -2438,7 +2438,7 @@ f! {
24382438
cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(mem::size_of::<cmsghdr>());
24392439
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
24402440
if next > max {
2441-
0 as *mut cmsghdr
2441+
core::ptr::null_mut::<cmsghdr>()
24422442
} else {
24432443
(cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
24442444
}

src/unix/bsd/netbsdlike/openbsd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ f! {
19401940
cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + _ALIGN(mem::size_of::<cmsghdr>());
19411941
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
19421942
if next > max {
1943-
0 as *mut cmsghdr
1943+
core::ptr::null_mut::<cmsghdr>()
19441944
} else {
19451945
(cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
19461946
}

src/unix/haiku/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ f! {
15701570
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
15711571
(*mhdr).msg_control as *mut cmsghdr
15721572
} else {
1573-
0 as *mut cmsghdr
1573+
core::ptr::null_mut::<cmsghdr>()
15741574
}
15751575
}
15761576

@@ -1595,7 +1595,7 @@ f! {
15951595
+ CMSG_ALIGN(mem::size_of::<cmsghdr>());
15961596
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
15971597
if next > max {
1598-
0 as *mut cmsghdr
1598+
core::ptr::null_mut::<cmsghdr>()
15991599
} else {
16001600
(cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
16011601
}

0 commit comments

Comments
 (0)