Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless unsafe, mut and ptr casts in example in send-and-sync.md #308

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/send-and-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<T> Carton<T> {
pub fn new(value: T) -> Self {
// Allocate enough memory on the heap to store one T.
assert_ne!(size_of::<T>(), 0, "Zero-sized types are out of the scope of this example");
let mut memptr = ptr::null_mut() as *mut T;
let mut memptr: *mut T = ptr::null_mut();
unsafe {
let ret = libc::posix_memalign(
(&mut memptr).cast(),
Expand All @@ -113,10 +113,10 @@ impl<T> Carton<T> {
};

// NonNull is just a wrapper that enforces that the pointer isn't null.
let mut ptr = unsafe {
let ptr = {
// Safety: memptr is dereferenceable because we created it from a
// reference and have exclusive access.
ptr::NonNull::new(memptr.cast::<T>())
ptr::NonNull::new(memptr)
.expect("Guaranteed non-null if posix_memalign returns 0")
};

Expand Down