Skip to content

Commit

Permalink
Rollup merge of rust-lang#63546 - lzutao:clouldabi-maybeuninit, r=Ral…
Browse files Browse the repository at this point in the history
…fJung

Remove uses of `mem::uninitialized()` from cloudabi

This PR removes uses of `mem::uninitialized` from `cloudabi` module,
excluding the layout test in `src/libstd/sys/cloudabi/abi/cloudabi.rs`.

r? @RalfJung
cc @EdSchouten
cc rust-lang#62397
  • Loading branch information
Centril authored Aug 15, 2019
2 parents ce4a45d + 6e8639a commit 87e3393
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/libstd/sys/cloudabi/abi/cloudabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@

#![no_std]
#![allow(non_camel_case_types)]
#![allow(deprecated)] // FIXME: using `mem::uninitialized()`

include!("bitflags.rs");

Expand Down
2 changes: 0 additions & 2 deletions src/libstd/sys/cloudabi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)] // mem::uninitialized

use crate::io::ErrorKind;
use crate::mem;

Expand Down
7 changes: 4 additions & 3 deletions src/libstd/sys/cloudabi/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ impl ReentrantMutex {
},
..mem::zeroed()
};
let mut event: abi::event = mem::uninitialized();
let mut nevents: usize = mem::uninitialized();
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
let mut event = MaybeUninit::<abi::event>::uninit();
let mut nevents = MaybeUninit::<usize>::uninit();
let ret = abi::poll(&subscription, event.as_mut_ptr(), 1, nevents.as_mut_ptr());
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire mutex");
let event = event.assume_init();
assert_eq!(event.error, abi::errno::SUCCESS, "Failed to acquire mutex");
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/libstd/sys/cloudabi/rwlock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::cell::UnsafeCell;
use crate::mem;
use crate::mem::MaybeUninit;
use crate::sync::atomic::{AtomicU32, Ordering};
use crate::sys::cloudabi::abi;

Expand Down Expand Up @@ -73,10 +74,11 @@ impl RWLock {
},
..mem::zeroed()
};
let mut event: abi::event = mem::uninitialized();
let mut nevents: usize = mem::uninitialized();
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
let mut event = MaybeUninit::<abi::event>::uninit();
let mut nevents = MaybeUninit::<usize>::uninit();
let ret = abi::poll(&subscription, event.as_mut_ptr(), 1, nevents.as_mut_ptr());
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire read lock");
let event = event.assume_init();
assert_eq!(
event.error,
abi::errno::SUCCESS,
Expand Down Expand Up @@ -182,10 +184,11 @@ impl RWLock {
},
..mem::zeroed()
};
let mut event: abi::event = mem::uninitialized();
let mut nevents: usize = mem::uninitialized();
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
let mut event = MaybeUninit::<abi::event>::uninit();
let mut nevents = MaybeUninit::<usize>::uninit();
let ret = abi::poll(&subscription, event.as_mut_ptr(), 1, nevents.as_mut_ptr());
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire write lock");
let event = event.assume_init();
assert_eq!(
event.error,
abi::errno::SUCCESS,
Expand Down
7 changes: 4 additions & 3 deletions src/libstd/sys/cloudabi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ impl Thread {
},
..mem::zeroed()
};
let mut event: abi::event = mem::uninitialized();
let mut nevents: usize = mem::uninitialized();
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
let mut event = mem::MaybeUninit::<abi::event>::uninit();
let mut nevents = mem::MaybeUninit::<usize>::uninit();
let ret = abi::poll(&subscription, event.as_mut_ptr(), 1, nevents.as_mut_ptr());
assert_eq!(ret, abi::errno::SUCCESS);
let event = event.assume_init();
assert_eq!(event.error, abi::errno::SUCCESS);
}
}
Expand Down

0 comments on commit 87e3393

Please sign in to comment.