Skip to content
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
2 changes: 0 additions & 2 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,8 +2431,6 @@ impl<T: fmt::Debug + ?Sized, A: Allocator> fmt::Debug for Box<T, A> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// It's not possible to extract the inner Uniq directly from the Box,
// instead we cast it to a *const which aliases the Unique
let ptr: *const T = &**self;
fmt::Pointer::fmt(&ptr, f)
}
Expand Down
1 change: 0 additions & 1 deletion library/core/src/panic/unwind_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ pub struct AssertUnwindSafe<T>(#[stable(feature = "catch_unwind", since = "1.9.0
//
// * By default everything is unwind safe
// * pointers T contains mutability of some form are not unwind safe
// * Unique, an owning pointer, lifts an implementation
// * Types like Mutex/RwLock which are explicitly poisoned are unwind safe
// * Our custom AssertUnwindSafe wrapper is indeed unwind safe

Expand Down
18 changes: 10 additions & 8 deletions src/etc/gdb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
FIRST_FIELD = "__1"


def unwrap_unique_or_non_null(unique_or_nonnull):
# Gets the raw pointer out of a `NonNull` or a wrapper struct with a
# `pointer: NonNull` field (with that exact name)
def unwrap_non_null_or_wrapper(ptr):
# BACKCOMPAT: rust 1.32
# https://github.com/rust-lang/rust/commit/7a0911528058e87d22ea305695f4047572c5e067
# BACKCOMPAT: rust 1.60
# https://github.com/rust-lang/rust/commit/2a91eeac1a2d27dd3de1bf55515d765da20fd86f
ptr = unique_or_nonnull["pointer"]
ptr = ptr["pointer"]
return ptr if ptr.type.code == gdb.TYPE_CODE_PTR else ptr[ptr.type.fields()[0]]


Expand Down Expand Up @@ -62,7 +64,7 @@ def __init__(self, valobj):
self._valobj = valobj
vec = valobj["vec"]
self._length = int(vec["len"])
self._data_ptr = unwrap_unique_or_non_null(vec["buf"]["inner"]["ptr"])
self._data_ptr = unwrap_non_null_or_wrapper(vec["buf"]["inner"]["ptr"])

def to_string(self):
return self._data_ptr.lazy_string(encoding="utf-8", length=self._length)
Expand All @@ -80,7 +82,7 @@ def __init__(self, valobj):
vec = buf["bytes"] if is_windows else buf

self._length = int(vec["len"])
self._data_ptr = unwrap_unique_or_non_null(vec["buf"]["inner"]["ptr"])
self._data_ptr = unwrap_non_null_or_wrapper(vec["buf"]["inner"]["ptr"])

def to_string(self):
return self._data_ptr.lazy_string(encoding="utf-8", length=self._length)
Expand Down Expand Up @@ -160,7 +162,7 @@ class StdVecProvider(printer_base):
def __init__(self, valobj):
self._valobj = valobj
self._length = int(valobj["len"])
self._data_ptr = unwrap_unique_or_non_null(valobj["buf"]["inner"]["ptr"])
self._data_ptr = unwrap_non_null_or_wrapper(valobj["buf"]["inner"]["ptr"])
ptr_ty = gdb.Type.pointer(valobj.type.template_argument(0))
self._data_ptr = self._data_ptr.reinterpret_cast(ptr_ty)

Expand Down Expand Up @@ -196,7 +198,7 @@ def __init__(self, valobj):
if cap.type.code != gdb.TYPE_CODE_INT:
cap = cap[ZERO_FIELD]
self._cap = int(cap)
self._data_ptr = unwrap_unique_or_non_null(valobj["buf"]["inner"]["ptr"])
self._data_ptr = unwrap_non_null_or_wrapper(valobj["buf"]["inner"]["ptr"])
ptr_ty = gdb.Type.pointer(valobj.type.template_argument(0))
self._data_ptr = self._data_ptr.reinterpret_cast(ptr_ty)

Expand All @@ -221,7 +223,7 @@ class StdRcProvider(printer_base):
def __init__(self, valobj, is_atomic=False):
self._valobj = valobj
self._is_atomic = is_atomic
self._ptr = unwrap_unique_or_non_null(valobj["ptr"])
self._ptr = unwrap_non_null_or_wrapper(valobj["ptr"])
self._value = self._ptr["data" if is_atomic else "value"]
# FIXME(shua): the debuginfo template type should be 'str' not 'u8'
if self._ptr.type.target().name == "alloc::rc::RcInner<str>":
Expand Down Expand Up @@ -321,7 +323,7 @@ def cast_to_internal(node):
if node_ptr.type.name.startswith("alloc::collections::btree::node::BoxedNode<"):
# BACKCOMPAT: rust 1.49
node_ptr = node_ptr["ptr"]
node_ptr = unwrap_unique_or_non_null(node_ptr)
node_ptr = unwrap_non_null_or_wrapper(node_ptr)
leaf = node_ptr.dereference()
keys = leaf["keys"]
vals = leaf["vals"]
Expand Down
18 changes: 10 additions & 8 deletions src/etc/lldb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ def from_uint(self, name: str, value: int) -> SBValue:
return self.valobj.CreateValueFromData(name, data, type)


def unwrap_unique_or_non_null(unique_or_nonnull: SBValue) -> SBValue:
# Gets the raw pointer out of a `NonNull` or a wrapper struct with a
# `pointer: NonNull` field (with that exact name)
def unwrap_non_null_or_wrapper(ptr: SBValue) -> SBValue:
# BACKCOMPAT: rust 1.32
# https://github.com/rust-lang/rust/commit/7a0911528058e87d22ea305695f4047572c5e067
# BACKCOMPAT: rust 1.60
# https://github.com/rust-lang/rust/commit/2a91eeac1a2d27dd3de1bf55515d765da20fd86f
ptr = unique_or_nonnull.GetChildMemberWithName("pointer")
ptr = ptr.GetChildMemberWithName("pointer")
return ptr if ptr.TypeIsPointerType() else ptr.GetChildAtIndex(0)


Expand Down Expand Up @@ -417,7 +419,7 @@ def StdStringSummaryProvider(valobj: SBValue, dict: LLDBOpaque):
.GetNonSyntheticValue()
)

pointer = unwrap_unique_or_non_null(
pointer = unwrap_non_null_or_wrapper(
inner_vec.GetChildMemberWithName("buf")
.GetChildMemberWithName("inner")
.GetChildMemberWithName("ptr")
Expand Down Expand Up @@ -453,7 +455,7 @@ def StdOsStringSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
if is_windows:
inner_vec = inner_vec.GetChildAtIndex(0)

pointer = unwrap_unique_or_non_null(
pointer = unwrap_non_null_or_wrapper(
inner_vec.GetChildMemberWithName("buf")
.GetChildMemberWithName("inner")
.GetChildMemberWithName("ptr")
Expand Down Expand Up @@ -614,7 +616,7 @@ def __init__(self, valobj: SBValue, _dict: LLDBOpaque):

def update(self):
inner_vec = self.valobj.GetChildMemberWithName("vec").GetNonSyntheticValue()
self.data_ptr = unwrap_unique_or_non_null(
self.data_ptr = unwrap_non_null_or_wrapper(
inner_vec.GetChildMemberWithName("buf")
.GetChildMemberWithName("inner")
.GetChildMemberWithName("ptr")
Expand Down Expand Up @@ -1158,7 +1160,7 @@ def get_child_at_index(self, index: int) -> Optional[SBValue]:

def update(self):
buf: SBValue = self.valobj.GetChildMemberWithName("buf")
self.data_ptr = unwrap_unique_or_non_null(
self.data_ptr = unwrap_non_null_or_wrapper(
buf.GetChildMemberWithName("inner").GetChildMemberWithName("ptr")
)

Expand Down Expand Up @@ -1333,7 +1335,7 @@ def update(self):
cap = cap.GetChildAtIndex(0)
self.cap = cap.GetValueAsUnsigned()

self.data_ptr = unwrap_unique_or_non_null(
self.data_ptr = unwrap_non_null_or_wrapper(
self.buf.GetChildMemberWithName("ptr")
)

Expand Down Expand Up @@ -1569,7 +1571,7 @@ class StdRcSyntheticProvider:
def __init__(self, valobj: SBValue, _dict: LLDBOpaque, is_atomic: bool = False):
self.valobj = valobj

self.ptr = unwrap_unique_or_non_null(self.valobj.GetChildMemberWithName("ptr"))
self.ptr = unwrap_non_null_or_wrapper(self.valobj.GetChildMemberWithName("ptr"))

self.value = self.ptr.GetChildMemberWithName("data" if is_atomic else "value")

Expand Down
7 changes: 0 additions & 7 deletions src/etc/natvis/libcore.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@
</Expand>
</Type>

<Type Name="core::ptr::unique::Unique&lt;*&gt;">
Comment thread
maxdexh marked this conversation as resolved.
Resolved
<DisplayString>Unique({(void*)pointer.pointer}: {pointer.pointer})</DisplayString>
<Expand>
<ExpandedItem>pointer</ExpandedItem>
</Expand>
</Type>

<Type Name="core::sync::atomic::Atomic&lt;bool&gt;">
<DisplayString>{(bool)v.value.__0}</DisplayString>
</Type>
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/functions-closures/nullable-pointer-opt-closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn main() {
assert_eq!(mem::size_of_val(&b), mem::size_of::<Box<i32>>());

// By Value Capture - Transitive case
let a = "Hello".to_string(); // String -> Vec -> Unique -> NonZero
let a = "Hello".to_string(); // String -> Vec -> NonNull
let b = Some(move || println!("{}", a));
// We captured `a` by value and since down the chain it contains
// a `NonZero` field, we can use it as the discriminant.
// a `NonNull` field, we can use it as the discriminant.
assert_eq!(mem::size_of_val(&b), mem::size_of::<String>());

// By Value - No Optimization
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/print_type_sizes/niche-filling.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This file illustrates how niche-filling enums are handled,
//! modelled after cases like `Option<&u32>`, `Option<bool>` and such.
//!
//! It uses `NonZero<u32>` rather than `&_` or `Unique<_>`, because
//! It uses `NonZero<u32>` rather than `&_` or `NonNull<_>`, because
//! the test is not set up to deal with target-dependent pointer width.
//!
//! It avoids using `u64`/`i64` because on some targets that is only 4-byte
Expand Down
Loading