diff options
| author | Laurențiu Nicola <lnicola@users.noreply.github.com> | 2025-06-30 15:11:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 15:11:33 +0000 |
| commit | c5f4b80cb9a678297548ea13feb2e57696e09e6e (patch) | |
| tree | 69ecc9ed7f6fb830c4814d1085ba96820b4ab864 /library/alloc/src | |
| parent | 863d0b5d53ebd5aa2d3c2c415fff841741c3937c (diff) | |
| parent | 0edf5726c773484b53f9612f687dec916a60883f (diff) | |
| download | rust-c5f4b80cb9a678297548ea13feb2e57696e09e6e.tar.gz rust-c5f4b80cb9a678297548ea13feb2e57696e09e6e.zip | |
Merge pull request #20128 from lnicola/sync-from-rust
Sync from downstream
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/btree/set.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 109 | ||||
| -rw-r--r-- | library/alloc/src/rc.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/sync.rs | 1 |
4 files changed, 110 insertions, 5 deletions
diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index aa9e5fce1d4..d50ce02bda7 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1517,9 +1517,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> { // use stable sort to preserve the insertion order. arr.sort(); - let iter = IntoIterator::into_iter(arr).map(|k| (k, SetValZST::default())); - let map = BTreeMap::bulk_build_from_sorted_iter(iter, Global); - BTreeSet { map } + BTreeSet::from_sorted_iter(IntoIterator::into_iter(arr), Global) } } diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 48849bf7536..93bdad75380 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -1099,6 +1099,46 @@ impl From<&CStr> for CString { } } +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CStr> for CString { + #[inline] + fn eq(&self, other: &CStr) -> bool { + **self == *other + } + + #[inline] + fn ne(&self, other: &CStr) -> bool { + **self != *other + } +} + +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<&CStr> for CString { + #[inline] + fn eq(&self, other: &&CStr) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &&CStr) -> bool { + **self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<Cow<'_, CStr>> for CString { + #[inline] + fn eq(&self, other: &Cow<'_, CStr>) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &Cow<'_, CStr>) -> bool { + **self != **other + } +} + #[stable(feature = "cstring_asref", since = "1.7.0")] impl ops::Index<ops::RangeFull> for CString { type Output = CStr; @@ -1181,6 +1221,75 @@ impl CStr { } } +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CString> for CStr { + #[inline] + fn eq(&self, other: &CString) -> bool { + *self == **other + } + + #[inline] + fn ne(&self, other: &CString) -> bool { + *self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<Cow<'_, Self>> for CStr { + #[inline] + fn eq(&self, other: &Cow<'_, Self>) -> bool { + *self == **other + } + + #[inline] + fn ne(&self, other: &Cow<'_, Self>) -> bool { + *self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CStr> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &CStr) -> bool { + **self == *other + } + + #[inline] + fn ne(&self, other: &CStr) -> bool { + **self != *other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<&CStr> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &&CStr) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &&CStr) -> bool { + **self != **other + } +} + +#[cfg(not(no_global_oom_handling))] +#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")] +impl PartialEq<CString> for Cow<'_, CStr> { + #[inline] + fn eq(&self, other: &CString) -> bool { + **self == **other + } + + #[inline] + fn ne(&self, other: &CString) -> bool { + **self != **other + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl core::error::Error for NulError { #[allow(deprecated)] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 4b8ea708e7e..010d17f7476 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -3004,7 +3004,6 @@ pub struct Weak< // `Weak::new` sets this to `usize::MAX` so that it doesn’t need // to allocate space on the heap. That's not a value a real pointer // will ever have because RcInner has alignment at least 2. - // This is only possible when `T: Sized`; unsized `T` never dangle. ptr: NonNull<RcInner<T>>, alloc: A, } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 17090925cfa..1e3c03977bd 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -342,7 +342,6 @@ pub struct Weak< // `Weak::new` sets this to `usize::MAX` so that it doesn’t need // to allocate space on the heap. That's not a value a real pointer // will ever have because RcInner has alignment at least 2. - // This is only possible when `T: Sized`; unsized `T` never dangle. ptr: NonNull<ArcInner<T>>, alloc: A, } |
