Skip to content

Commit 72577e7

Browse files
committed
Resolve clippy::zero_ptr
Recent versions of Clippy now lint against `0 as *(const|mut) T` rather than using `null`/`null_mut`. Make the updates required for this to pass.
1 parent 65da4e4 commit 72577e7

File tree

30 files changed

+96
-83
lines changed

30 files changed

+96
-83
lines changed

src/fuchsia/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ pub type rlim_t = c_ulonglong;
8080

8181
// FIXME(fuchsia): why are these uninhabited types? that seems... wrong?
8282
// Presumably these should be `()` or an `extern type` (when that stabilizes).
83-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
83+
#[derive(Debug)]
8484
pub enum timezone {}
8585
impl Copy for timezone {}
8686
impl Clone for timezone {
8787
fn clone(&self) -> timezone {
8888
*self
8989
}
9090
}
91-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
91+
#[derive(Debug)]
9292
pub enum DIR {}
9393
impl Copy for DIR {}
9494
impl Clone for DIR {
@@ -97,7 +97,7 @@ impl Clone for DIR {
9797
}
9898
}
9999

100-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
100+
#[derive(Debug)]
101101
pub enum fpos64_t {} // FIXME(fuchsia): fill this out with a struct
102102
impl Copy for fpos64_t {}
103103
impl Clone for fpos64_t {
@@ -2356,7 +2356,7 @@ pub const ST_NOATIME: c_ulong = 1024;
23562356
pub const ST_NODIRATIME: c_ulong = 2048;
23572357

23582358
pub const RTLD_NEXT: *mut c_void = -1i64 as *mut c_void;
2359-
pub const RTLD_DEFAULT: *mut c_void = 0i64 as *mut c_void;
2359+
pub const RTLD_DEFAULT: *mut c_void = ptr::null_mut();
23602360
pub const RTLD_NODELETE: c_int = 0x1000;
23612361
pub const RTLD_NOW: c_int = 0x2;
23622362

@@ -2500,7 +2500,7 @@ pub const EFD_SEMAPHORE: c_int = 0x1;
25002500

25012501
pub const LOG_NFACILITIES: c_int = 24;
25022502

2503-
pub const SEM_FAILED: *mut crate::sem_t = 0 as *mut sem_t;
2503+
pub const SEM_FAILED: *mut crate::sem_t = ptr::null_mut();
25042504

25052505
pub const RB_AUTOBOOT: c_int = 0x01234567u32 as i32;
25062506
pub const RB_HALT_SYSTEM: c_int = 0xcdef0123u32 as i32;
@@ -3469,15 +3469,15 @@ fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
34693469
#[link(name = "fdio")]
34703470
extern "C" {}
34713471

3472-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3472+
#[derive(Debug)]
34733473
pub enum FILE {}
34743474
impl Copy for FILE {}
34753475
impl Clone for FILE {
34763476
fn clone(&self) -> FILE {
34773477
*self
34783478
}
34793479
}
3480-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3480+
#[derive(Debug)]
34813481
pub enum fpos_t {} // FIXME(fuchsia): fill this out with a struct
34823482
impl Copy for fpos_t {}
34833483
impl Clone for fpos_t {

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
// Attributes needed when building as part of the standard library
2323
#![cfg_attr(feature = "rustc-dep-of-std", feature(link_cfg, no_core))]
2424
#![cfg_attr(feature = "rustc-dep-of-std", allow(internal_features))]
25-
// Enable extra lints:
26-
#![cfg_attr(feature = "extra_traits", warn(missing_debug_implementations))]
2725
#![warn(missing_copy_implementations, safe_packed_borrows)]
2826
#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)]
2927
#![cfg_attr(feature = "rustc-dep-of-std", no_core)]

src/macros.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ macro_rules! prelude {
7272
mod prelude {
7373
// Exports from `core`
7474
#[allow(unused_imports)]
75-
pub(crate) use ::core::clone::Clone;
75+
pub(crate) use core::clone::Clone;
7676
#[allow(unused_imports)]
77-
pub(crate) use ::core::default::Default;
77+
pub(crate) use core::default::Default;
7878
#[allow(unused_imports)]
79-
pub(crate) use ::core::marker::{Copy, Send, Sync};
79+
pub(crate) use core::{fmt, hash, iter, mem, ptr};
8080
#[allow(unused_imports)]
81-
pub(crate) use ::core::option::Option;
81+
pub(crate) use core::marker::{Copy, Send, Sync};
8282
#[allow(unused_imports)]
83-
pub(crate) use ::core::prelude::v1::derive;
83+
pub(crate) use core::prelude::v1::derive;
8484
#[allow(unused_imports)]
85-
pub(crate) use ::core::{fmt, hash, iter, mem};
85+
pub(crate) use core::option::Option;
86+
87+
#[allow(unused_imports)]
88+
pub(crate) use fmt::Debug;
8689
#[allow(unused_imports)]
8790
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8891

@@ -120,9 +123,13 @@ macro_rules! s {
120123
#[repr(C)]
121124
#[cfg_attr(
122125
feature = "extra_traits",
123-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
126+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
127+
)]
128+
#[::core::prelude::v1::derive(
129+
::core::clone::Clone,
130+
::core::marker::Copy,
131+
::core::fmt::Debug,
124132
)]
125-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
126133
#[allow(deprecated)]
127134
$(#[$attr])*
128135
pub struct $i { $($field)* }
@@ -142,17 +149,21 @@ macro_rules! s_paren {
142149
__item! {
143150
#[cfg_attr(
144151
feature = "extra_traits",
145-
::core::prelude::v1::derive(Debug, Eq, Hash, PartialEq)
152+
::core::prelude::v1::derive(Eq, Hash, PartialEq)
153+
)]
154+
#[::core::prelude::v1::derive(
155+
::core::clone::Clone,
156+
::core::marker::Copy,
157+
::core::fmt::Debug,
146158
)]
147-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
148159
$(#[$attr])*
149160
pub struct $i ( $($field)* );
150161
}
151162
)*);
152163
}
153164

154-
/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature, as well as `Debug`
155-
/// with `extra_traits` since that can always be derived.
165+
/// Implement `Clone`, `Copy`, and `Debug` since those can be derived, but exclude `PartialEq`,
166+
/// `Eq`, and `Hash`.
156167
///
157168
/// Most items will prefer to use [`s`].
158169
macro_rules! s_no_extra_traits {
@@ -171,7 +182,6 @@ macro_rules! s_no_extra_traits {
171182
pub union $i { $($field)* }
172183
}
173184

174-
#[cfg(feature = "extra_traits")]
175185
impl ::core::fmt::Debug for $i {
176186
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
177187
f.debug_struct(::core::stringify!($i)).finish_non_exhaustive()
@@ -182,8 +192,11 @@ macro_rules! s_no_extra_traits {
182192
(it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => (
183193
__item! {
184194
#[repr(C)]
185-
#[::core::prelude::v1::derive(::core::clone::Clone, ::core::marker::Copy)]
186-
#[cfg_attr(feature = "extra_traits", ::core::prelude::v1::derive(Debug))]
195+
#[::core::prelude::v1::derive(
196+
::core::clone::Clone,
197+
::core::marker::Copy,
198+
::core::fmt::Debug,
199+
)]
187200
$(#[$attr])*
188201
pub struct $i { $($field)* }
189202
}

src/solid/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ pub const SIGUSR1: c_int = 30;
395395
pub const SIGUSR2: c_int = 31;
396396
pub const SIGPWR: c_int = 32;
397397

398-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
398+
#[derive(Debug)]
399399
pub enum FILE {}
400400
impl Copy for FILE {}
401401
impl Clone for FILE {
402402
fn clone(&self) -> FILE {
403403
*self
404404
}
405405
}
406-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
406+
#[derive(Debug)]
407407
pub enum fpos_t {}
408408
impl Copy for fpos_t {}
409409
impl Clone for fpos_t {

src/unix/aix/powerpc64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::prelude::*;
33

44
// Define lock_data_instrumented as an empty enum
55
missing! {
6-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
6+
#[derive(Debug)]
77
pub enum lock_data_instrumented {}
88
}
99

src/unix/bsd/apple/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub type copyfile_callback_t = Option<
175175
pub type attrgroup_t = u32;
176176
pub type vol_capabilities_set_t = [u32; 4];
177177

178-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
178+
#[derive(Debug)]
179179
pub enum timezone {}
180180
impl Copy for timezone {}
181181
impl Clone for timezone {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub type vm_map_entry_t = *mut vm_map_entry;
4545

4646
pub type pmap = __c_anonymous_pmap;
4747

48-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
48+
#[derive(Debug)]
4949
pub enum sem {}
5050
impl Copy for sem {}
5151
impl Clone for sem {

src/unix/bsd/freebsdlike/freebsd/freebsd11/b32.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::off_t;
22
use crate::prelude::*;
33

44
#[repr(C)]
5-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
5+
#[derive(Debug)]
6+
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
67
pub struct stat {
78
pub st_dev: crate::dev_t,
89
pub st_ino: crate::ino_t,

src/unix/bsd/freebsdlike/freebsd/freebsd11/b64.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::off_t;
22
use crate::prelude::*;
33

44
#[repr(C)]
5-
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
5+
#[derive(Debug)]
6+
#[cfg_attr(feature = "extra_traits", derive(Eq, Hash, PartialEq))]
67
pub struct stat {
78
pub st_dev: crate::dev_t,
89
pub st_ino: crate::ino_t,

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cfg_if! {
5959

6060
// link.h
6161

62-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
62+
#[derive(Debug)]
6363
pub enum timezone {}
6464
impl Copy for timezone {}
6565
impl Clone for timezone {
@@ -1197,9 +1197,9 @@ pub const _SC_RAW_SOCKETS: c_int = 119;
11971197
pub const _SC_SYMLOOP_MAX: c_int = 120;
11981198
pub const _SC_PHYS_PAGES: c_int = 121;
11991199

1200-
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as *mut _;
1201-
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
1202-
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
1200+
pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = ptr::null_mut();
1201+
pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = ptr::null_mut();
1202+
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = ptr::null_mut();
12031203
pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 1;
12041204
pub const PTHREAD_MUTEX_RECURSIVE: c_int = 2;
12051205
pub const PTHREAD_MUTEX_NORMAL: c_int = 3;
@@ -1331,7 +1331,7 @@ pub const B230400: speed_t = 230400;
13311331
pub const EXTA: speed_t = 19200;
13321332
pub const EXTB: speed_t = 38400;
13331333

1334-
pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
1334+
pub const SEM_FAILED: *mut sem_t = ptr::null_mut();
13351335

13361336
pub const CRTSCTS: crate::tcflag_t = 0x00030000;
13371337
pub const CCTS_OFLOW: crate::tcflag_t = 0x00010000;

0 commit comments

Comments
 (0)