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

rc: Take *const T in is_dangling #119434

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,7 @@ impl<T, A: Allocator> Weak<T, A> {
}
}

pub(crate) fn is_dangling<T: ?Sized>(ptr: *mut T) -> bool {
pub(crate) fn is_dangling<T: ?Sized>(ptr: *const T) -> bool {
(ptr.cast::<()>()).addr() == usize::MAX
}

Expand Down Expand Up @@ -3003,7 +3003,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self {
// See Weak::as_ptr for context on how the input pointer is derived.

let ptr = if is_dangling(ptr as *mut T) {
let ptr = if is_dangling(ptr) {
// This is a dangling Weak.
ptr as *mut RcBox<T>
} else {
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
pub unsafe fn from_raw_in(ptr: *const T, alloc: A) -> Self {
// See Weak::as_ptr for context on how the input pointer is derived.

let ptr = if is_dangling(ptr as *mut T) {
let ptr = if is_dangling(ptr) {
// This is a dangling Weak.
ptr as *mut ArcInner<T>
} else {
Expand Down