Skip to content

Commit f8f1b15

Browse files
committed
Auto merge of rust-lang#80867 - JohnTitor:rollup-tvqw555, r=JohnTitor
Rollup of 9 pull requests Successful merges: - rust-lang#79502 (Implement From<char> for u64 and u128.) - rust-lang#79968 (Improve core::ptr::drop_in_place debuginfo) - rust-lang#80774 (Fix safety comment) - rust-lang#80801 (Use correct span for structured suggestion) - rust-lang#80803 (Remove useless `fill_in` function) - rust-lang#80820 (Support `download-ci-llvm` on NixOS) - rust-lang#80825 (Remove under-used ImplPolarity enum) - rust-lang#80850 (Allow #[rustc_builtin_macro = "name"]) - rust-lang#80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d18d5c4 + 304d080 commit f8f1b15

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

alloc/src/vec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ impl<T, A: Allocator> Vec<T, A> {
990990
// such that no value will be dropped twice in case `drop_in_place`
991991
// were to panic once (if it panics twice, the program aborts).
992992
unsafe {
993+
// Note: It's intentional that this is `>` and not `>=`.
994+
// Changing it to `>=` has negative performance
995+
// implications in some cases. See #78884 for more.
993996
if len > self.len {
994997
return;
995998
}

core/src/char/convert.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,48 @@ impl From<char> for u32 {
113113
}
114114
}
115115

116+
#[stable(feature = "more_char_conversions", since = "1.51.0")]
117+
impl From<char> for u64 {
118+
/// Converts a [`char`] into a [`u64`].
119+
///
120+
/// # Examples
121+
///
122+
/// ```
123+
/// use std::mem;
124+
///
125+
/// let c = '👤';
126+
/// let u = u64::from(c);
127+
/// assert!(8 == mem::size_of_val(&u))
128+
/// ```
129+
#[inline]
130+
fn from(c: char) -> Self {
131+
// The char is casted to the value of the code point, then zero-extended to 64 bit.
132+
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
133+
c as u64
134+
}
135+
}
136+
137+
#[stable(feature = "more_char_conversions", since = "1.51.0")]
138+
impl From<char> for u128 {
139+
/// Converts a [`char`] into a [`u128`].
140+
///
141+
/// # Examples
142+
///
143+
/// ```
144+
/// use std::mem;
145+
///
146+
/// let c = '⚙';
147+
/// let u = u128::from(c);
148+
/// assert!(16 == mem::size_of_val(&u))
149+
/// ```
150+
#[inline]
151+
fn from(c: char) -> Self {
152+
// The char is casted to the value of the code point, then zero-extended to 128 bit.
153+
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
154+
c as u128
155+
}
156+
}
157+
116158
/// Maps a byte in 0x00..=0xFF to a `char` whose code point has the same value, in U+0000..=U+00FF.
117159
///
118160
/// Unicode is designed such that this effectively decodes bytes

std/src/alloc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ impl System {
166166
match old_layout.size() {
167167
0 => self.alloc_impl(new_layout, zeroed),
168168

169-
// SAFETY: `new_size` is non-zero as `old_size` is greater than or equal to `new_size`
170-
// as required by safety conditions. Other conditions must be upheld by the caller
169+
// SAFETY: `new_size` is non-zero as `new_size` is greater than or equal to `old_size`
170+
// as required by safety conditions and the `old_size == 0` case was handled in the
171+
// previous match arm. Other conditions must be upheld by the caller
171172
old_size if old_layout.align() == new_layout.align() => unsafe {
172173
let new_size = new_layout.size();
173174

0 commit comments

Comments
 (0)