Skip to content

Commit bdafaaa

Browse files
committed
chore: apply some clippy lints
1 parent e8b0152 commit bdafaaa

File tree

21 files changed

+77
-86
lines changed

21 files changed

+77
-86
lines changed

Cargo.toml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,14 @@ members = [
147147
# This way all crates can use it with `[lints] workspace=true` section
148148

149149
[lints.rust]
150-
# FIXME(cleanup): make ident usage consistent in each file
151-
unused_qualifications = "allow"
150+
# FIXME(cleanup): should be cleaned up
151+
unused_imports = "allow"
152+
unused_qualifications = "allow" # make ident usage consistent in each file
152153

153154
[lints.clippy]
154-
missing_safety_doc = "allow"
155+
identity_op = "allow" # some expressions like `0 | x` are clearer for bit ops
156+
missing_safety_doc = "allow" # safety? in libc? seriously?
155157

156-
# FIXME(clippy): all these are default lints and should probably be fixed
157-
identity_op = "allow"
158-
if_same_then_else = "allow"
159-
non_minimal_cfg = "allow"
160-
precedence = "allow"
161-
redundant_field_names = "allow"
162-
redundant_static_lifetimes = "allow"
163-
unnecessary_cast = "allow"
164-
unused_unit = "allow"
165-
zero_ptr = "allow"
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
}

src/unix/hurd/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,7 @@ f! {
34443444
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
34453445
(*mhdr).msg_control as *mut cmsghdr
34463446
} else {
3447-
0 as *mut cmsghdr
3447+
core::ptr::null_mut::<cmsghdr>()
34483448
}
34493449
}
34503450

@@ -3462,14 +3462,14 @@ f! {
34623462

34633463
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
34643464
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
3465-
return 0 as *mut cmsghdr;
3465+
return core::ptr::null_mut::<cmsghdr>();
34663466
};
34673467
let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
34683468
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
34693469
if (next.offset(1)) as usize > max
34703470
|| next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max
34713471
{
3472-
0 as *mut cmsghdr
3472+
core::ptr::null_mut::<cmsghdr>()
34733473
} else {
34743474
next as *mut cmsghdr
34753475
}

src/unix/linux_like/android/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3611,7 +3611,7 @@ f! {
36113611
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
36123612
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
36133613
if (next.offset(1)) as usize > max {
3614-
0 as *mut cmsghdr
3614+
core::ptr::null_mut::<cmsghdr>()
36153615
} else {
36163616
next as *mut cmsghdr
36173617
}

src/unix/linux_like/emscripten/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,12 +1412,12 @@ pub const SOMAXCONN: c_int = 128;
14121412
f! {
14131413
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
14141414
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
1415-
return 0 as *mut cmsghdr;
1415+
return core::ptr::null_mut::<cmsghdr>();
14161416
};
14171417
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
14181418
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
14191419
if (next.offset(1)) as usize > max {
1420-
0 as *mut cmsghdr
1420+
core::ptr::null_mut::<cmsghdr>()
14211421
} else {
14221422
next as *mut cmsghdr
14231423
}

src/unix/linux_like/linux/gnu/b64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ cfg_if! {
119119
} else if #[cfg(any(target_arch = "s390x"))] {
120120
mod s390x;
121121
pub use self::s390x::*;
122-
} else if #[cfg(any(target_arch = "x86_64"))] {
122+
} else if #[cfg(target_arch = "x86_64")] {
123123
mod x86_64;
124124
pub use self::x86_64::*;
125125
} else if #[cfg(any(target_arch = "riscv64"))] {

src/unix/linux_like/linux/gnu/b64/riscv64/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ pub const REG_NARGS: usize = 8;
601601

602602
pub const COMPAT_HWCAP_ISA_I: c_ulong = 1 << (b'I' - b'A');
603603
pub const COMPAT_HWCAP_ISA_M: c_ulong = 1 << (b'M' - b'A');
604+
#[allow(clippy::eq_op)]
604605
pub const COMPAT_HWCAP_ISA_A: c_ulong = 1 << (b'A' - b'A');
605606
pub const COMPAT_HWCAP_ISA_F: c_ulong = 1 << (b'F' - b'A');
606607
pub const COMPAT_HWCAP_ISA_D: c_ulong = 1 << (b'D' - b'A');

src/unix/linux_like/linux/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5986,16 +5986,16 @@ f! {
59865986

59875987
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
59885988
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
5989-
return 0 as *mut cmsghdr;
5989+
return core::ptr::null_mut::<cmsghdr>();
59905990
};
59915991
let next = (cmsg as usize + super::CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr;
59925992
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
59935993
if (next.wrapping_offset(1)) as usize > max
59945994
|| next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max
59955995
{
5996-
0 as *mut cmsghdr
5996+
core::ptr::null_mut::<cmsghdr>()
59975997
} else {
5998-
next as *mut cmsghdr
5998+
next
59995999
}
60006000
}
60016001

@@ -6015,14 +6015,12 @@ f! {
60156015
let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc
60166016
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
60176017
cpuset.bits[idx] |= 1 << offset;
6018-
()
60196018
}
60206019

60216020
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
60226021
let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc
60236022
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
60246023
cpuset.bits[idx] &= !(1 << offset);
6025-
()
60266024
}
60276025

60286026
pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
@@ -6049,7 +6047,7 @@ f! {
60496047
}
60506048

60516049
pub fn SCTP_PR_INDEX(policy: c_int) -> c_int {
6052-
policy >> 4 - 1
6050+
policy >> (4 - 1)
60536051
}
60546052

60556053
pub fn SCTP_PR_POLICY(policy: c_int) -> c_int {
@@ -6059,7 +6057,6 @@ f! {
60596057
pub fn SCTP_PR_SET_POLICY(flags: &mut c_int, policy: c_int) -> () {
60606058
*flags &= !SCTP_PR_SCTP_MASK;
60616059
*flags |= policy;
6062-
()
60636060
}
60646061

60656062
pub fn IPTOS_TOS(tos: u8) -> u8 {
@@ -6120,20 +6117,15 @@ f! {
61206117

61216118
pub fn BPF_STMT(code: __u16, k: __u32) -> sock_filter {
61226119
sock_filter {
6123-
code: code,
6120+
code,
61246121
jt: 0,
61256122
jf: 0,
6126-
k: k,
6123+
k,
61276124
}
61286125
}
61296126

61306127
pub fn BPF_JUMP(code: __u16, k: __u32, jt: __u8, jf: __u8) -> sock_filter {
6131-
sock_filter {
6132-
code: code,
6133-
jt: jt,
6134-
jf: jf,
6135-
k: k,
6136-
}
6128+
sock_filter { code, jt, jf, k }
61376129
}
61386130

61396131
pub fn ELF32_R_SYM(val: Elf32_Word) -> Elf32_Word {
@@ -6145,7 +6137,7 @@ f! {
61456137
}
61466138

61476139
pub fn ELF32_R_INFO(sym: Elf32_Word, t: Elf32_Word) -> Elf32_Word {
6148-
sym << 8 + t & 0xff
6140+
sym << (8 + t) & 0xff
61496141
}
61506142

61516143
pub fn ELF64_R_SYM(val: Elf64_Xword) -> Elf64_Xword {
@@ -6157,7 +6149,7 @@ f! {
61576149
}
61586150

61596151
pub fn ELF64_R_INFO(sym: Elf64_Xword, t: Elf64_Xword) -> Elf64_Xword {
6160-
sym << 32 + t
6152+
sym << (32 + t)
61616153
}
61626154
}
61636155

src/unix/linux_like/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ cfg_if! {
16991699

17001700
const_fn! {
17011701
{const} fn CMSG_ALIGN(len: usize) -> usize {
1702-
len + mem::size_of::<usize>() - 1 & !(mem::size_of::<usize>() - 1)
1702+
(len + mem::size_of::<usize>() - 1) & !(mem::size_of::<usize>() - 1)
17031703
}
17041704
}
17051705

@@ -1708,7 +1708,7 @@ f! {
17081708
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
17091709
(*mhdr).msg_control as *mut cmsghdr
17101710
} else {
1711-
0 as *mut cmsghdr
1711+
core::ptr::null_mut::<cmsghdr>()
17121712
}
17131713
}
17141714

src/unix/nto/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,15 +2801,15 @@ f! {
28012801
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
28022802
(*mhdr).msg_control as *mut cmsghdr
28032803
} else {
2804-
0 as *mut cmsghdr
2804+
core::ptr::null_mut::<cmsghdr>()
28052805
}
28062806
}
28072807

28082808
pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
28092809
let msg = _CMSG_ALIGN((*cmsg).cmsg_len as usize);
28102810
let next = cmsg as usize + msg + _CMSG_ALIGN(mem::size_of::<cmsghdr>());
28112811
if next > (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize {
2812-
0 as *mut cmsghdr
2812+
core::ptr::null_mut::<cmsghdr>()
28132813
} else {
28142814
(cmsg as usize + msg) as *mut cmsghdr
28152815
}

0 commit comments

Comments
 (0)