Skip to content

Commit

Permalink
Fix is_dangling import when Arc is #[cfg]’ed out
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jul 6, 2018
1 parent 5717d99 commit 67202b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/liballoc/rc.rs
Expand Up @@ -261,7 +261,6 @@ use core::convert::From;

use alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
use string::String;
use sync::is_dangling;
use vec::Vec;

struct RcBox<T: ?Sized> {
Expand Down Expand Up @@ -1192,6 +1191,12 @@ impl<T> Weak<T> {
}
}

pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
let address = ptr.as_ptr() as *mut () as usize;
let align = align_of_val(unsafe { ptr.as_ref() });
address == align
}

impl<T: ?Sized> Weak<T> {
/// Attempts to upgrade the `Weak` pointer to an [`Rc`], extending
/// the lifetime of the value if successful.
Expand Down
7 changes: 1 addition & 6 deletions src/liballoc/sync.rs
Expand Up @@ -34,6 +34,7 @@ use core::convert::From;

use alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
use boxed::Box;
use rc::is_dangling;
use string::String;
use vec::Vec;

Expand Down Expand Up @@ -1038,12 +1039,6 @@ impl<T> Weak<T> {
}
}

pub(crate) fn is_dangling<T: ?Sized>(ptr: NonNull<T>) -> bool {
let address = ptr.as_ptr() as *mut () as usize;
let align = align_of_val(unsafe { ptr.as_ref() });
address == align
}

impl<T: ?Sized> Weak<T> {
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], extending
/// the lifetime of the value if successful.
Expand Down

0 comments on commit 67202b8

Please sign in to comment.