Skip to content

Commit a9861d8

Browse files
bors[bot]SteveLauC
andauthored
Merge #1785
1785: Remove deprecated items r=asomers a=SteveLauC #### What this pr does 1. Convert `assert!(x == y)` to `assert_eq!(x, y)` 2. Convert `assert!(x != y)` to `assert_ne!(x, y)` 3. Add `.unwrap()` to unused `Result/Option` (in code comments) 4. Convert `std::ixx::MAX` to `ixx::MAX` 5. Convert `Box<Trait>` to `Box<dyn Trait>` Co-authored-by: SteveLauC <[email protected]> Co-authored-by: SteveLau <[email protected]>
2 parents 09b4b49 + 217c3b5 commit a9861d8

14 files changed

+46
-46
lines changed

src/sched.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ mod sched_affinity {
233233
/// use nix::unistd::Pid;
234234
///
235235
/// let mut cpu_set = CpuSet::new();
236-
/// cpu_set.set(0);
237-
/// sched_setaffinity(Pid::from_raw(0), &cpu_set);
236+
/// cpu_set.set(0).unwrap();
237+
/// sched_setaffinity(Pid::from_raw(0), &cpu_set).unwrap();
238238
/// ```
239239
pub fn sched_setaffinity(pid: Pid, cpuset: &CpuSet) -> Result<()> {
240240
let res = unsafe {

src/sys/personality.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn get() -> Result<Persona> {
8686
/// # use nix::sys::personality::{self, Persona};
8787
/// let mut pers = personality::get().unwrap();
8888
/// assert!(!pers.contains(Persona::ADDR_NO_RANDOMIZE));
89-
/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE);
89+
/// personality::set(pers | Persona::ADDR_NO_RANDOMIZE).unwrap();
9090
/// ```
9191
pub fn set(persona: Persona) -> Result<Persona> {
9292
let res = unsafe {

src/sys/quota.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//!
77
//! ```rust,no_run
88
//! # use nix::sys::quota::{Dqblk, quotactl_on, quotactl_set, QuotaFmt, QuotaType, QuotaValidFlags};
9-
//! quotactl_on(QuotaType::USRQUOTA, "/dev/sda1", QuotaFmt::QFMT_VFS_V1, "aquota.user");
9+
//! quotactl_on(QuotaType::USRQUOTA, "/dev/sda1", QuotaFmt::QFMT_VFS_V1, "aquota.user").unwrap();
1010
//! let mut dqblk: Dqblk = Default::default();
1111
//! dqblk.set_blocks_hard_limit(10000);
1212
//! dqblk.set_blocks_soft_limit(8000);
13-
//! quotactl_set(QuotaType::USRQUOTA, "/dev/sda1", 50, &dqblk, QuotaValidFlags::QIF_BLIMITS);
13+
//! quotactl_set(QuotaType::USRQUOTA, "/dev/sda1", 50, &dqblk, QuotaValidFlags::QIF_BLIMITS).unwrap();
1414
//! ```
1515
use std::default::Default;
1616
use std::{mem, ptr};

src/sys/socket/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ pub enum ControlMessageOwned {
677677
/// None).unwrap();
678678
/// setsockopt(in_socket, sockopt::ReceiveTimestamp, &true).unwrap();
679679
/// let localhost = SockaddrIn::from_str("127.0.0.1:0").unwrap();
680-
/// bind(in_socket, &localhost);
680+
/// bind(in_socket, &localhost).unwrap();
681681
/// let address: SockaddrIn = getsockname(in_socket).unwrap();
682682
/// // Get initial time
683683
/// let time0 = SystemTime::now();

src/sys/socket/sockopt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ mod test {
982982
let a_cred = getsockopt(a, super::PeerCredentials).unwrap();
983983
let b_cred = getsockopt(b, super::PeerCredentials).unwrap();
984984
assert_eq!(a_cred, b_cred);
985-
assert!(a_cred.pid() != 0);
985+
assert_ne!(a_cred.pid(), 0);
986986
}
987987

988988
#[test]

src/sys/termios.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
//! # use nix::sys::termios::{BaudRate, cfsetispeed, cfsetospeed, cfsetspeed, Termios};
6565
//! # fn main() {
6666
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
67-
//! cfsetispeed(&mut t, BaudRate::B9600);
68-
//! cfsetospeed(&mut t, BaudRate::B9600);
69-
//! cfsetspeed(&mut t, BaudRate::B9600);
67+
//! cfsetispeed(&mut t, BaudRate::B9600).unwrap();
68+
//! cfsetospeed(&mut t, BaudRate::B9600).unwrap();
69+
//! cfsetspeed(&mut t, BaudRate::B9600).unwrap();
7070
//! # }
7171
//! ```
7272
//!
@@ -76,10 +76,10 @@
7676
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios};
7777
//! # fn main() {
7878
//! # let mut t: Termios = unsafe { std::mem::zeroed() };
79-
//! # cfsetspeed(&mut t, BaudRate::B9600);
79+
//! # cfsetspeed(&mut t, BaudRate::B9600).unwrap();
8080
//! let speed = cfgetispeed(&t);
8181
//! assert_eq!(speed, cfgetospeed(&t));
82-
//! cfsetispeed(&mut t, speed);
82+
//! cfsetispeed(&mut t, speed).unwrap();
8383
//! # }
8484
//! ```
8585
//!

src/sys/time.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ const SECS_PER_MINUTE: i64 = 60;
193193
const SECS_PER_HOUR: i64 = 3600;
194194

195195
#[cfg(target_pointer_width = "64")]
196-
const TS_MAX_SECONDS: i64 = (::std::i64::MAX / NANOS_PER_SEC) - 1;
196+
const TS_MAX_SECONDS: i64 = (i64::MAX / NANOS_PER_SEC) - 1;
197197

198198
#[cfg(target_pointer_width = "32")]
199-
const TS_MAX_SECONDS: i64 = ::std::isize::MAX as i64;
199+
const TS_MAX_SECONDS: i64 = isize::MAX as i64;
200200

201201
const TS_MIN_SECONDS: i64 = -TS_MAX_SECONDS;
202202

@@ -453,10 +453,10 @@ pub struct TimeVal(timeval);
453453
const MICROS_PER_SEC: i64 = 1_000_000;
454454

455455
#[cfg(target_pointer_width = "64")]
456-
const TV_MAX_SECONDS: i64 = (::std::i64::MAX / MICROS_PER_SEC) - 1;
456+
const TV_MAX_SECONDS: i64 = (i64::MAX / MICROS_PER_SEC) - 1;
457457

458458
#[cfg(target_pointer_width = "32")]
459-
const TV_MAX_SECONDS: i64 = ::std::isize::MAX as i64;
459+
const TV_MAX_SECONDS: i64 = isize::MAX as i64;
460460

461461
const TV_MIN_SECONDS: i64 = -TV_MAX_SECONDS;
462462

@@ -713,7 +713,7 @@ mod test {
713713

714714
#[test]
715715
pub fn test_timespec() {
716-
assert!(TimeSpec::seconds(1) != TimeSpec::zero());
716+
assert_ne!(TimeSpec::seconds(1), TimeSpec::zero());
717717
assert_eq!(
718718
TimeSpec::seconds(1) + TimeSpec::seconds(2),
719719
TimeSpec::seconds(3)
@@ -743,7 +743,7 @@ mod test {
743743

744744
#[test]
745745
pub fn test_timespec_ord() {
746-
assert!(TimeSpec::seconds(1) == TimeSpec::nanoseconds(1_000_000_000));
746+
assert_eq!(TimeSpec::seconds(1), TimeSpec::nanoseconds(1_000_000_000));
747747
assert!(TimeSpec::seconds(1) < TimeSpec::nanoseconds(1_000_000_001));
748748
assert!(TimeSpec::seconds(1) > TimeSpec::nanoseconds(999_999_999));
749749
assert!(TimeSpec::seconds(-1) < TimeSpec::nanoseconds(-999_999_999));
@@ -765,7 +765,7 @@ mod test {
765765

766766
#[test]
767767
pub fn test_timeval() {
768-
assert!(TimeVal::seconds(1) != TimeVal::zero());
768+
assert_ne!(TimeVal::seconds(1), TimeVal::zero());
769769
assert_eq!(
770770
TimeVal::seconds(1) + TimeVal::seconds(2),
771771
TimeVal::seconds(3)
@@ -778,7 +778,7 @@ mod test {
778778

779779
#[test]
780780
pub fn test_timeval_ord() {
781-
assert!(TimeVal::seconds(1) == TimeVal::microseconds(1_000_000));
781+
assert_eq!(TimeVal::seconds(1), TimeVal::microseconds(1_000_000));
782782
assert!(TimeVal::seconds(1) < TimeVal::microseconds(1_000_001));
783783
assert!(TimeVal::seconds(1) > TimeVal::microseconds(999_999));
784784
assert!(TimeVal::seconds(-1) < TimeVal::microseconds(-999_999));

src/unistd.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ pub fn getgroups() -> Result<Vec<Gid>> {
15721572
/// # use std::error::Error;
15731573
/// # use nix::unistd::*;
15741574
/// #
1575-
/// # fn try_main() -> Result<(), Box<Error>> {
1575+
/// # fn try_main() -> Result<(), Box<dyn Error>> {
15761576
/// let uid = Uid::from_raw(33);
15771577
/// let gid = Gid::from_raw(34);
15781578
/// setgroups(&[gid])?;
@@ -1698,7 +1698,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> {
16981698
/// # use std::ffi::CString;
16991699
/// # use nix::unistd::*;
17001700
/// #
1701-
/// # fn try_main() -> Result<(), Box<Error>> {
1701+
/// # fn try_main() -> Result<(), Box<dyn Error>> {
17021702
/// let user = CString::new("www-data").unwrap();
17031703
/// let uid = Uid::from_raw(33);
17041704
/// let gid = Gid::from_raw(33);
@@ -3121,7 +3121,7 @@ impl User {
31213121
/// use nix::unistd::{Uid, User};
31223122
/// // Returns an Result<Option<User>>, thus the double unwrap.
31233123
/// let res = User::from_uid(Uid::from_raw(0)).unwrap().unwrap();
3124-
/// assert!(res.name == "root");
3124+
/// assert_eq!(res.name, "root");
31253125
/// ```
31263126
pub fn from_uid(uid: Uid) -> Result<Option<Self>> {
31273127
User::from_anything(|pwd, cbuf, cap, res| {
@@ -3140,7 +3140,7 @@ impl User {
31403140
/// use nix::unistd::User;
31413141
/// // Returns an Result<Option<User>>, thus the double unwrap.
31423142
/// let res = User::from_name("root").unwrap().unwrap();
3143-
/// assert!(res.name == "root");
3143+
/// assert_eq!(res.name, "root");
31443144
/// ```
31453145
pub fn from_name(name: &str) -> Result<Option<Self>> {
31463146
let name = CString::new(name).unwrap();

test/sys/test_pthread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn test_pthread_self() {
1111
#[test]
1212
fn test_pthread_self() {
1313
let tid = pthread_self();
14-
assert!(tid != 0);
14+
assert_ne!(tid, 0);
1515
}
1616

1717
#[test]

test/sys/test_ptrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn test_ptrace_setoptions() {
3333
require_capability!("test_ptrace_setoptions", CAP_SYS_PTRACE);
3434
let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD)
3535
.unwrap_err();
36-
assert!(err != Errno::EOPNOTSUPP);
36+
assert_ne!(err, Errno::EOPNOTSUPP);
3737
}
3838

3939
// Just make sure ptrace_getevent can be called at all, for now.
@@ -42,7 +42,7 @@ fn test_ptrace_setoptions() {
4242
fn test_ptrace_getevent() {
4343
require_capability!("test_ptrace_getevent", CAP_SYS_PTRACE);
4444
let err = ptrace::getevent(getpid()).unwrap_err();
45-
assert!(err != Errno::EOPNOTSUPP);
45+
assert_ne!(err, Errno::EOPNOTSUPP);
4646
}
4747

4848
// Just make sure ptrace_getsiginfo can be called at all, for now.

test/test_dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn flags() -> OFlag {
2020
fn read() {
2121
let tmp = tempdir().unwrap();
2222
File::create(&tmp.path().join("foo")).unwrap();
23-
::std::os::unix::fs::symlink("foo", tmp.path().join("bar")).unwrap();
23+
std::os::unix::fs::symlink("foo", tmp.path().join("bar")).unwrap();
2424
let mut dir = Dir::open(tmp.path(), flags(), Mode::empty()).unwrap();
2525
let mut entries: Vec<_> = dir.iter().map(|e| e.unwrap()).collect();
2626
entries.sort_by(|a, b| a.file_name().cmp(b.file_name()));

test/test_pty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn test_ptsname_copy() {
5858
assert_eq!(slave_name1, slave_name2);
5959
// Also make sure that the string was actually copied and they point to different parts of
6060
// memory.
61-
assert!(slave_name1.as_ptr() != slave_name2.as_ptr());
61+
assert_ne!(slave_name1.as_ptr(), slave_name2.as_ptr());
6262
}
6363

6464
/// Test data copying of `ptsname_r`
@@ -73,7 +73,7 @@ fn test_ptsname_r_copy() {
7373
let slave_name1 = ptsname_r(&master_fd).unwrap();
7474
let slave_name2 = ptsname_r(&master_fd).unwrap();
7575
assert_eq!(slave_name1, slave_name2);
76-
assert!(slave_name1.as_ptr() != slave_name2.as_ptr());
76+
assert_ne!(slave_name1.as_ptr(), slave_name2.as_ptr());
7777
}
7878

7979
/// Test that `ptsname` returns different names for different devices
@@ -93,7 +93,7 @@ fn test_ptsname_unique() {
9393
// Get the name of the slave
9494
let slave_name1 = unsafe { ptsname(&master1_fd) }.unwrap();
9595
let slave_name2 = unsafe { ptsname(&master2_fd) }.unwrap();
96-
assert!(slave_name1 != slave_name2);
96+
assert_ne!(slave_name1, slave_name2);
9797
}
9898

9999
/// Common setup for testing PTTY pairs

test/test_stat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ fn test_mknod() {
378378
let target = tempdir.path().join(file_name);
379379
mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap();
380380
let mode = lstat(&target).unwrap().st_mode as mode_t;
381-
assert!(mode & libc::S_IFREG == libc::S_IFREG);
382-
assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
381+
assert_eq!(mode & libc::S_IFREG, libc::S_IFREG);
382+
assert_eq!(mode & libc::S_IRWXU, libc::S_IRWXU);
383383
}
384384

385385
#[test]
@@ -416,6 +416,6 @@ fn test_mknodat() {
416416
)
417417
.unwrap()
418418
.st_mode as mode_t;
419-
assert!(mode & libc::S_IFREG == libc::S_IFREG);
420-
assert!(mode & libc::S_IRWXU == libc::S_IRWXU);
419+
assert_eq!(mode & libc::S_IFREG, libc::S_IFREG);
420+
assert_eq!(mode & libc::S_IRWXU, libc::S_IRWXU);
421421
}

test/test_unistd.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn test_mkfifo() {
114114

115115
let stats = stat::stat(&mkfifo_fifo).unwrap();
116116
let typ = stat::SFlag::from_bits_truncate(stats.st_mode as mode_t);
117-
assert!(typ == SFlag::S_IFIFO);
117+
assert_eq!(typ, SFlag::S_IFIFO);
118118
}
119119

120120
#[test]
@@ -300,7 +300,7 @@ fn test_initgroups() {
300300
}
301301

302302
#[cfg(not(any(target_os = "fuchsia", target_os = "redox")))]
303-
macro_rules! execve_test_factory(
303+
macro_rules! execve_test_factory (
304304
($test_name:ident, $syscall:ident, $exe: expr $(, $pathname:expr, $flags:expr)*) => (
305305

306306
#[cfg(test)]
@@ -694,9 +694,9 @@ fn test_sysconf_unsupported() {
694694
#[test]
695695
fn test_getresuid() {
696696
let resuids = getresuid().unwrap();
697-
assert!(resuids.real.as_raw() != libc::uid_t::max_value());
698-
assert!(resuids.effective.as_raw() != libc::uid_t::max_value());
699-
assert!(resuids.saved.as_raw() != libc::uid_t::max_value());
697+
assert_ne!(resuids.real.as_raw(), libc::uid_t::MAX);
698+
assert_ne!(resuids.effective.as_raw(), libc::uid_t::MAX);
699+
assert_ne!(resuids.saved.as_raw(), libc::uid_t::MAX);
700700
}
701701

702702
#[cfg(any(
@@ -709,9 +709,9 @@ fn test_getresuid() {
709709
#[test]
710710
fn test_getresgid() {
711711
let resgids = getresgid().unwrap();
712-
assert!(resgids.real.as_raw() != libc::gid_t::max_value());
713-
assert!(resgids.effective.as_raw() != libc::gid_t::max_value());
714-
assert!(resgids.saved.as_raw() != libc::gid_t::max_value());
712+
assert_ne!(resgids.real.as_raw(), libc::gid_t::MAX);
713+
assert_ne!(resgids.effective.as_raw(), libc::gid_t::MAX);
714+
assert_ne!(resgids.saved.as_raw(), libc::gid_t::MAX);
715715
}
716716

717717
// Test that we can create a pair of pipes. No need to verify that they pass
@@ -1335,7 +1335,7 @@ fn test_faccessat_not_existing() {
13351335
Some(dirfd),
13361336
not_exist_file,
13371337
AccessFlags::F_OK,
1338-
AtFlags::empty()
1338+
AtFlags::empty(),
13391339
)
13401340
.err()
13411341
.unwrap(),
@@ -1354,7 +1354,7 @@ fn test_faccessat_none_file_exists() {
13541354
None,
13551355
&path,
13561356
AccessFlags::R_OK | AccessFlags::W_OK,
1357-
AtFlags::empty()
1357+
AtFlags::empty(),
13581358
)
13591359
.is_ok());
13601360
}
@@ -1372,7 +1372,7 @@ fn test_faccessat_file_exists() {
13721372
Some(dirfd),
13731373
&path,
13741374
AccessFlags::R_OK | AccessFlags::W_OK,
1375-
AtFlags::empty()
1375+
AtFlags::empty(),
13761376
)
13771377
.is_ok());
13781378
}

0 commit comments

Comments
 (0)