Skip to content

Commit e649e90

Browse files
committed
Auto merge of rust-lang#62873 - Centril:rollup-ncnuelj, r=Centril
Rollup of 14 pull requests Successful merges: - rust-lang#62709 (Test that maplike FromIter satisfies uniqueness) - rust-lang#62713 (Stabilize <*mut _>::cast and <*const _>::cast) - rust-lang#62746 ( do not use assume_init in std::io) - rust-lang#62787 (Fix typo in src/libstd/net/udp.rs doc comment) - rust-lang#62788 (normalize use of backticks in compiler messages for libcore/ptr) - rust-lang#62799 (use const array repeat expressions for uninit_array) - rust-lang#62810 (normalize use of backticks in compiler messages for librustc_lint) - rust-lang#62812 (normalize use of backticks in compiler messages for librustc_metadata) - rust-lang#62832 (normalize use of backticks in compiler messages for librustc_incremental) - rust-lang#62845 (read: fix doc comment) - rust-lang#62853 (normalize use of backticks in compiler messages for librustc/hir) - rust-lang#62854 (Fix typo in Unicode character name) - rust-lang#62858 (Change wrong variable name.) - rust-lang#62870 (fix lexing of comments with many \r) Failed merges: r? @ghost
2 parents 4bc1ce7 + 376382a commit e649e90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+212
-154
lines changed

src/liballoc/collections/btree/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ use Entry::*;
7575
///
7676
/// // look up the values associated with some keys.
7777
/// let to_find = ["Up!", "Office Space"];
78-
/// for book in &to_find {
79-
/// match movie_reviews.get(book) {
80-
/// Some(review) => println!("{}: {}", book, review),
81-
/// None => println!("{} is unreviewed.", book)
78+
/// for movie in &to_find {
79+
/// match movie_reviews.get(movie) {
80+
/// Some(review) => println!("{}: {}", movie, review),
81+
/// None => println!("{} is unreviewed.", movie)
8282
/// }
8383
/// }
8484
///

src/liballoc/collections/btree/node.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ impl<K, V> LeafNode<K, V> {
106106
LeafNode {
107107
// As a general policy, we leave fields uninitialized if they can be, as this should
108108
// be both slightly faster and easier to track in Valgrind.
109-
keys: uninitialized_array![_; CAPACITY],
110-
vals: uninitialized_array![_; CAPACITY],
109+
keys: uninit_array![_; CAPACITY],
110+
vals: uninit_array![_; CAPACITY],
111111
parent: ptr::null(),
112112
parent_idx: MaybeUninit::uninit(),
113113
len: 0
@@ -159,7 +159,7 @@ impl<K, V> InternalNode<K, V> {
159159
unsafe fn new() -> Self {
160160
InternalNode {
161161
data: LeafNode::new(),
162-
edges: uninitialized_array![_; 2*B],
162+
edges: uninit_array![_; 2*B],
163163
}
164164
}
165165
}

src/liballoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@
7777
#![feature(box_syntax)]
7878
#![feature(cfg_target_has_atomic)]
7979
#![feature(coerce_unsized)]
80+
#![cfg_attr(not(bootstrap), feature(const_in_array_repeat_expressions))]
8081
#![feature(dispatch_from_dyn)]
8182
#![feature(core_intrinsics)]
8283
#![feature(dropck_eyepatch)]
8384
#![feature(exact_size_is_empty)]
8485
#![feature(fmt_internals)]
8586
#![feature(fn_traits)]
8687
#![feature(fundamental)]
88+
#![feature(internal_uninit_const)]
8789
#![feature(lang_items)]
8890
#![feature(libc)]
8991
#![feature(nll)]

src/libcore/fmt/float.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
1212
unsafe {
1313
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
1414
let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit();
15-
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
16-
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
15+
// FIXME(#53491): This is calling `get_mut` on an uninitialized
16+
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
1717
// we decided whether that is valid or not.
18-
// Using `freeze` is *not enough*; `flt2dec::Part` is an enum!
18+
// We can do this only because we are libstd and coupled to the compiler.
19+
// (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
1920
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
2021
*num, sign, precision,
2122
false, buf.get_mut(), parts.get_mut());

src/libcore/fmt/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait GenericRadix {
5151
// characters for a base 2 number.
5252
let zero = T::zero();
5353
let is_nonnegative = x >= zero;
54-
let mut buf = uninitialized_array![u8; 128];
54+
let mut buf = [MaybeUninit::<u8>::uninit(); 128];
5555
let mut curr = buf.len();
5656
let base = T::from_u8(Self::BASE);
5757
if is_nonnegative {
@@ -189,7 +189,7 @@ static DEC_DIGITS_LUT: &[u8; 200] =
189189
macro_rules! impl_Display {
190190
($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => {
191191
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192-
let mut buf = uninitialized_array![u8; 39];
192+
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
193193
let mut curr = buf.len() as isize;
194194
let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf);
195195
let lut_ptr = DEC_DIGITS_LUT.as_ptr();

src/libcore/macros.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,20 +626,37 @@ macro_rules! todo {
626626
/// Creates an array of [`MaybeUninit`].
627627
///
628628
/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`.
629+
/// It exists solely because bootstrap does not yet support const array-init expressions.
629630
///
630631
/// [`MaybeUninit`]: mem/union.MaybeUninit.html
632+
// FIXME: Remove both versions of this macro once bootstrap is 1.38.
631633
#[macro_export]
632634
#[unstable(feature = "maybe_uninit_array", issue = "53491")]
633-
macro_rules! uninitialized_array {
635+
#[cfg(bootstrap)]
636+
macro_rules! uninit_array {
634637
// This `assume_init` is safe because an array of `MaybeUninit` does not
635638
// require initialization.
636-
// FIXME(#49147): Could be replaced by an array initializer, once those can
637-
// be any const expression.
638639
($t:ty; $size:expr) => (unsafe {
639640
MaybeUninit::<[MaybeUninit<$t>; $size]>::uninit().assume_init()
640641
});
641642
}
642643

644+
/// Creates an array of [`MaybeUninit`].
645+
///
646+
/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`.
647+
/// It exists solely because bootstrap does not yet support const array-init expressions.
648+
///
649+
/// [`MaybeUninit`]: mem/union.MaybeUninit.html
650+
// FIXME: Just inline this version of the macro once bootstrap is 1.38.
651+
#[macro_export]
652+
#[unstable(feature = "maybe_uninit_array", issue = "53491")]
653+
#[cfg(not(bootstrap))]
654+
macro_rules! uninit_array {
655+
($t:ty; $size:expr) => (
656+
[MaybeUninit::<$t>::UNINIT; $size]
657+
);
658+
}
659+
643660
/// Built-in macros to the compiler itself.
644661
///
645662
/// These macros do not have any corresponding definition with a `macro_rules!`

src/libcore/mem/maybe_uninit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ impl<T> MaybeUninit<T> {
252252
MaybeUninit { uninit: () }
253253
}
254254

255+
/// A promotable constant, equivalent to `uninit()`.
256+
#[unstable(feature = "internal_uninit_const", issue = "0",
257+
reason = "hack to work around promotability")]
258+
pub const UNINIT: Self = Self::uninit();
259+
255260
/// Creates a new `MaybeUninit<T>` in an uninitialized state, with the memory being
256261
/// filled with `0` bytes. It depends on `T` whether that already makes for
257262
/// proper initialization. For example, `MaybeUninit<usize>::zeroed()` is initialized,

src/libcore/ptr/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ impl<T: ?Sized> *const T {
10431043
}
10441044

10451045
/// Cast to a pointer to a different type
1046-
#[unstable(feature = "ptr_cast", issue = "60602")]
1046+
#[stable(feature = "ptr_cast", since = "1.38.0")]
10471047
#[inline]
10481048
pub const fn cast<U>(self) -> *const U {
10491049
self as _
@@ -1678,7 +1678,7 @@ impl<T: ?Sized> *mut T {
16781678
}
16791679

16801680
/// Cast to a pointer to a different type
1681-
#[unstable(feature = "ptr_cast", issue = "60602")]
1681+
#[stable(feature = "ptr_cast", since = "1.38.0")]
16821682
#[inline]
16831683
pub const fn cast<U>(self) -> *mut U {
16841684
self as _

src/libcore/ptr/unique.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use crate::ptr::NonNull;
2626
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
2727
/// for any type which upholds Unique's aliasing requirements.
2828
#[unstable(feature = "ptr_internals", issue = "0",
29-
reason = "use NonNull instead and consider PhantomData<T> \
30-
(if you also use #[may_dangle]), Send, and/or Sync")]
29+
reason = "use `NonNull` instead and consider `PhantomData<T>` \
30+
(if you also use `#[may_dangle]`), `Send`, and/or `Sync`")]
3131
#[doc(hidden)]
3232
#[repr(transparent)]
3333
#[rustc_layout_scalar_valid_range_start(1)]

src/libcore/slice/sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
216216
let mut block_l = BLOCK;
217217
let mut start_l = ptr::null_mut();
218218
let mut end_l = ptr::null_mut();
219-
let mut offsets_l: [MaybeUninit<u8>; BLOCK] = uninitialized_array![u8; BLOCK];
219+
let mut offsets_l = [MaybeUninit::<u8>::uninit(); BLOCK];
220220

221221
// The current block on the right side (from `r.sub(block_r)` to `r`).
222222
let mut r = unsafe { l.add(v.len()) };
223223
let mut block_r = BLOCK;
224224
let mut start_r = ptr::null_mut();
225225
let mut end_r = ptr::null_mut();
226-
let mut offsets_r: [MaybeUninit<u8>; BLOCK] = uninitialized_array![u8; BLOCK];
226+
let mut offsets_r = [MaybeUninit::<u8>::uninit(); BLOCK];
227227

228228
// FIXME: When we get VLAs, try creating one array of length `min(v.len(), 2 * BLOCK)` rather
229229
// than two fixed-size arrays of length `BLOCK`. VLAs might be more cache-efficient.

0 commit comments

Comments
 (0)