Skip to content

Commit f092873

Browse files
committed
chore: apply some clippy lints
1 parent e70f6ea commit f092873

File tree

15 files changed

+36
-39
lines changed

15 files changed

+36
-39
lines changed

Cargo.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,16 @@ members = [
143143
"libc-test",
144144
]
145145

146-
#
147-
# TODO: These should be renamed as `[workspace.lints.*]` once MSRV is abve 1.64
146+
# FIXME(msrv): These should be renamed as `[workspace.lints.*]` once MSRV is above 1.64
148147
# This way all crates can use it with `[lints] workspace=true` section
149-
#
150148

151149
[lints.rust]
152-
# TODO: make ident usage consistent in each file
150+
# FIXME(cleanup): make ident usage consistent in each file
153151
unused_qualifications = "allow"
154152

155153
[lints.clippy]
156-
# TODO: enable pedantic lints with exceptions
157-
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this
158154
identity_op = "allow" # some expressions like `0 | x` are clearer for bit ops
159155
missing_safety_doc = "allow" # safety? in libc? seriously?
156+
157+
# FIXME(clippy): all these should probably be fixed
158+
non_minimal_cfg = "allow" # for some reason cfg_if! sometimes trigger this

src/fuchsia/mod.rs

+3-3
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

+2-2
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/freebsdlike/dragonfly/mod.rs

+1-1
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

+5-7
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -4952,30 +4952,28 @@ f! {
49524952
__xuname(256, buf as *mut c_void)
49534953
}
49544954

4955-
pub fn CPU_ZERO(cpuset: &mut cpuset_t) -> () {
4955+
pub fn CPU_ZERO(cpuset: &mut cpuset_t) {
49564956
for slot in cpuset.__bits.iter_mut() {
49574957
*slot = 0;
49584958
}
49594959
}
49604960

4961-
pub fn CPU_FILL(cpuset: &mut cpuset_t) -> () {
4961+
pub fn CPU_FILL(cpuset: &mut cpuset_t) {
49624962
for slot in cpuset.__bits.iter_mut() {
49634963
*slot = !0;
49644964
}
49654965
}
49664966

4967-
pub fn CPU_SET(cpu: usize, cpuset: &mut cpuset_t) -> () {
4967+
pub fn CPU_SET(cpu: usize, cpuset: &mut cpuset_t) {
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

4974-
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpuset_t) -> () {
4973+
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -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

+1-1
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

+2-2
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

+3-3
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

+1-1
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

+2-2
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/nto/mod.rs

+2-2
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
}

src/unix/solarish/compat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ unsafe fn bail(fdm: c_int, fds: c_int) -> c_int {
5050
crate::close(fdm);
5151
}
5252
*___errno() = e;
53-
return -1;
53+
-1
5454
}
5555

5656
#[cfg(target_os = "illumos")]
@@ -184,7 +184,7 @@ pub unsafe fn getpwent_r(
184184
) -> c_int {
185185
let old_errno = *crate::___errno();
186186
*crate::___errno() = 0;
187-
*result = native_getpwent_r(pwd, buf, min(buflen, c_int::max_value() as size_t) as c_int);
187+
*result = native_getpwent_r(pwd, buf, min(buflen, c_int::MAX as size_t) as c_int);
188188

189189
let ret = if (*result).is_null() {
190190
*crate::___errno()
@@ -204,7 +204,7 @@ pub unsafe fn getgrent_r(
204204
) -> c_int {
205205
let old_errno = *crate::___errno();
206206
*crate::___errno() = 0;
207-
*result = native_getgrent_r(grp, buf, min(buflen, c_int::max_value() as size_t) as c_int);
207+
*result = native_getgrent_r(grp, buf, min(buflen, c_int::MAX as size_t) as c_int);
208208

209209
let ret = if (*result).is_null() {
210210
*crate::___errno()

src/unix/solarish/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ f! {
24832483

24842484
pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
24852485
if ((*mhdr).msg_controllen as usize) < size_of::<cmsghdr>() {
2486-
0 as *mut cmsghdr
2486+
core::ptr::null_mut::<cmsghdr>()
24872487
} else {
24882488
(*mhdr).msg_control as *mut cmsghdr
24892489
}
@@ -2497,14 +2497,14 @@ f! {
24972497
_CMSG_HDR_ALIGN(cmsg as usize + (*cmsg).cmsg_len as usize + size_of::<cmsghdr>());
24982498
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
24992499
if next > max {
2500-
0 as *mut cmsghdr
2500+
core::ptr::null_mut::<cmsghdr>()
25012501
} else {
25022502
_CMSG_HDR_ALIGN(cmsg as usize + (*cmsg).cmsg_len as usize) as *mut cmsghdr
25032503
}
25042504
}
25052505

25062506
pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
2507-
_CMSG_HDR_ALIGN(size_of::<cmsghdr>() as usize + length as usize) as c_uint
2507+
_CMSG_HDR_ALIGN(size_of::<cmsghdr>() + length as usize) as c_uint
25082508
}
25092509

25102510
pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {

src/vxworks/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1139,15 +1139,15 @@ f! {
11391139
if next <= max {
11401140
(cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
11411141
} else {
1142-
0 as *mut cmsghdr
1142+
core::ptr::null_mut::<cmsghdr>()
11431143
}
11441144
}
11451145

11461146
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
11471147
if (*mhdr).msg_controllen as usize > 0 {
11481148
(*mhdr).msg_control as *mut cmsghdr
11491149
} else {
1150-
0 as *mut cmsghdr
1150+
core::ptr::null_mut::<cmsghdr>()
11511151
}
11521152
}
11531153

0 commit comments

Comments
 (0)