Skip to content

Commit 6139672

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 966b3b9 + 052d8a0 commit 6139672

File tree

24 files changed

+181
-110
lines changed

24 files changed

+181
-110
lines changed

alloc/src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ impl_eq! { Cow<'a, str>, &'b str }
26112611
impl_eq! { Cow<'a, str>, String }
26122612

26132613
#[stable(feature = "rust1", since = "1.0.0")]
2614-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2614+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
26152615
impl const Default for String {
26162616
/// Creates an empty `String`.
26172617
#[inline]

alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec<T, A> {
38953895
}
38963896

38973897
#[stable(feature = "rust1", since = "1.0.0")]
3898-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
3898+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
38993899
impl<T> const Default for Vec<T> {
39003900
/// Creates an empty `Vec<T>`.
39013901
///

core/src/cell.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<T: Copy> Clone for Cell<T> {
333333
}
334334

335335
#[stable(feature = "rust1", since = "1.0.0")]
336-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
336+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
337337
impl<T: ~const Default> const Default for Cell<T> {
338338
/// Creates a `Cell<T>`, with the `Default` value for T.
339339
#[inline]
@@ -1324,7 +1324,7 @@ impl<T: Clone> Clone for RefCell<T> {
13241324
}
13251325

13261326
#[stable(feature = "rust1", since = "1.0.0")]
1327-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
1327+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
13281328
impl<T: ~const Default> const Default for RefCell<T> {
13291329
/// Creates a `RefCell<T>`, with the `Default` value for T.
13301330
#[inline]
@@ -2332,7 +2332,7 @@ impl<T: ?Sized> UnsafeCell<T> {
23322332
}
23332333

23342334
#[stable(feature = "unsafe_cell_default", since = "1.10.0")]
2335-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2335+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
23362336
impl<T: ~const Default> const Default for UnsafeCell<T> {
23372337
/// Creates an `UnsafeCell`, with the `Default` value for T.
23382338
fn default() -> UnsafeCell<T> {
@@ -2437,7 +2437,7 @@ impl<T: ?Sized> SyncUnsafeCell<T> {
24372437
}
24382438

24392439
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
2440-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2440+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
24412441
impl<T: ~const Default> const Default for SyncUnsafeCell<T> {
24422442
/// Creates an `SyncUnsafeCell`, with the `Default` value for T.
24432443
fn default() -> SyncUnsafeCell<T> {

core/src/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ use crate::ascii::Char as AsciiChar;
104104
#[rustc_diagnostic_item = "Default"]
105105
#[stable(feature = "rust1", since = "1.0.0")]
106106
#[const_trait]
107-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
107+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
108108
pub trait Default: Sized {
109109
/// Returns the "default value" for a type.
110110
///
@@ -151,7 +151,7 @@ pub macro Default($item:item) {
151151
macro_rules! default_impl {
152152
($t:ty, $v:expr, $doc:tt) => {
153153
#[stable(feature = "rust1", since = "1.0.0")]
154-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
154+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
155155
impl const Default for $t {
156156
#[inline(always)]
157157
#[doc = $doc]

core/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ pub const unsafe fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
910910
/// # Safety
911911
///
912912
/// - `index < PtrMetadata(slice_ptr)`, so the indexing is in-bounds for the slice
913-
/// - the resulting offsetting is in-bounds of the allocated object, which is
913+
/// - the resulting offsetting is in-bounds of the allocation, which is
914914
/// always the case for references, but needs to be upheld manually for pointers
915915
#[rustc_nounwind]
916916
#[rustc_intrinsic]

core/src/io/borrowed_buf.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ impl<'data> From<&'data mut [MaybeUninit<u8>]> for BorrowedBuf<'data> {
6969
}
7070
}
7171

72+
/// Creates a new `BorrowedBuf` from a cursor.
73+
///
74+
/// Use `BorrowedCursor::with_unfilled_buf` instead for a safer alternative.
75+
impl<'data> From<BorrowedCursor<'data>> for BorrowedBuf<'data> {
76+
#[inline]
77+
fn from(mut buf: BorrowedCursor<'data>) -> BorrowedBuf<'data> {
78+
let init = buf.init_mut().len();
79+
BorrowedBuf {
80+
// SAFETY: no initialized byte is ever uninitialized as per
81+
// `BorrowedBuf`'s invariant
82+
buf: unsafe { buf.buf.buf.get_unchecked_mut(buf.buf.filled..) },
83+
filled: 0,
84+
init,
85+
}
86+
}
87+
}
88+
7289
impl<'data> BorrowedBuf<'data> {
7390
/// Returns the total capacity of the buffer.
7491
#[inline]
@@ -353,4 +370,38 @@ impl<'a> BorrowedCursor<'a> {
353370
}
354371
self.buf.filled += buf.len();
355372
}
373+
374+
/// Runs the given closure with a `BorrowedBuf` containing the unfilled part
375+
/// of the cursor.
376+
///
377+
/// This enables inspecting what was written to the cursor.
378+
///
379+
/// # Panics
380+
///
381+
/// Panics if the `BorrowedBuf` given to the closure is replaced by another
382+
/// one.
383+
pub fn with_unfilled_buf<T>(&mut self, f: impl FnOnce(&mut BorrowedBuf<'_>) -> T) -> T {
384+
let mut buf = BorrowedBuf::from(self.reborrow());
385+
let prev_ptr = buf.buf as *const _;
386+
let res = f(&mut buf);
387+
388+
// Check that the caller didn't replace the `BorrowedBuf`.
389+
// This is necessary for the safety of the code below: if the check wasn't
390+
// there, one could mark some bytes as initialized even though there aren't.
391+
assert!(core::ptr::addr_eq(prev_ptr, buf.buf));
392+
393+
let filled = buf.filled;
394+
let init = buf.init;
395+
396+
// Update `init` and `filled` fields with what was written to the buffer.
397+
// `self.buf.filled` was the starting length of the `BorrowedBuf`.
398+
//
399+
// SAFETY: These amounts of bytes were initialized/filled in the `BorrowedBuf`,
400+
// and therefore they are initialized/filled in the cursor too, because the
401+
// buffer wasn't replaced.
402+
self.buf.init = self.buf.filled + init;
403+
self.buf.filled += filled;
404+
405+
res
406+
}
356407
}

core/src/iter/sources/empty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<T> Clone for Empty<T> {
8181
// not #[derive] because that adds a Default bound on T,
8282
// which isn't necessary.
8383
#[stable(feature = "iter_empty", since = "1.2.0")]
84-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
84+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
8585
impl<T> const Default for Empty<T> {
8686
fn default() -> Empty<T> {
8787
Empty(marker::PhantomData)

core/src/marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<T: PointeeSized> Clone for PhantomData<T> {
863863
}
864864

865865
#[stable(feature = "rust1", since = "1.0.0")]
866-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
866+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
867867
impl<T: PointeeSized> const Default for PhantomData<T> {
868868
fn default() -> Self {
869869
Self

core/src/ops/function.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use crate::marker::Tuple;
7373
#[fundamental] // so that regex can rely that `&str: !FnMut`
7474
#[must_use = "closures are lazy and do nothing unless called"]
7575
#[const_trait]
76-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
76+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
7777
pub trait Fn<Args: Tuple>: FnMut<Args> {
7878
/// Performs the call operation.
7979
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -161,7 +161,7 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
161161
#[fundamental] // so that regex can rely that `&str: !FnMut`
162162
#[must_use = "closures are lazy and do nothing unless called"]
163163
#[const_trait]
164-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
164+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
165165
pub trait FnMut<Args: Tuple>: FnOnce<Args> {
166166
/// Performs the call operation.
167167
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -241,7 +241,7 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
241241
#[fundamental] // so that regex can rely that `&str: !FnMut`
242242
#[must_use = "closures are lazy and do nothing unless called"]
243243
#[const_trait]
244-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
244+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
245245
pub trait FnOnce<Args: Tuple> {
246246
/// The returned type after the call operator is used.
247247
#[lang = "fn_once_output"]
@@ -257,7 +257,7 @@ mod impls {
257257
use crate::marker::Tuple;
258258

259259
#[stable(feature = "rust1", since = "1.0.0")]
260-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
260+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
261261
impl<A: Tuple, F: ?Sized> const Fn<A> for &F
262262
where
263263
F: ~const Fn<A>,
@@ -268,7 +268,7 @@ mod impls {
268268
}
269269

270270
#[stable(feature = "rust1", since = "1.0.0")]
271-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
271+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
272272
impl<A: Tuple, F: ?Sized> const FnMut<A> for &F
273273
where
274274
F: ~const Fn<A>,
@@ -279,7 +279,7 @@ mod impls {
279279
}
280280

281281
#[stable(feature = "rust1", since = "1.0.0")]
282-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
282+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
283283
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &F
284284
where
285285
F: ~const Fn<A>,
@@ -292,7 +292,7 @@ mod impls {
292292
}
293293

294294
#[stable(feature = "rust1", since = "1.0.0")]
295-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
295+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
296296
impl<A: Tuple, F: ?Sized> const FnMut<A> for &mut F
297297
where
298298
F: ~const FnMut<A>,
@@ -303,7 +303,7 @@ mod impls {
303303
}
304304

305305
#[stable(feature = "rust1", since = "1.0.0")]
306-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
306+
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
307307
impl<A: Tuple, F: ?Sized> const FnOnce<A> for &mut F
308308
where
309309
F: ~const FnMut<A>,

core/src/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ where
21122112
impl<T> crate::clone::UseCloned for Option<T> where T: crate::clone::UseCloned {}
21132113

21142114
#[stable(feature = "rust1", since = "1.0.0")]
2115-
#[rustc_const_unstable(feature = "const_default", issue = "67792")]
2115+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
21162116
impl<T> const Default for Option<T> {
21172117
/// Returns [`None`][Option::None].
21182118
///

0 commit comments

Comments
 (0)