Skip to content

Commit 915514f

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents 0bffcd3 + b3b5780 commit 915514f

File tree

62 files changed

+2881
-1675
lines changed

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

+2881
-1675
lines changed

alloc/src/boxed/thin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ struct WithHeader<H>(NonNull<u8>, PhantomData<H>);
171171
/// An opaque representation of `WithHeader<H>` to avoid the
172172
/// projection invariance of `<T as Pointee>::Metadata`.
173173
#[repr(transparent)]
174-
#[allow(dead_code)] // Field only used through `WithHeader` type above.
175174
struct WithOpaqueHeader(NonNull<u8>);
176175

177176
impl WithOpaqueHeader {

alloc/src/vec/in_place_collect.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! or [`BinaryHeap<T>`], the adapters guarantee to consume enough items per step to make room
1010
//! for the results (represented by [`InPlaceIterable`]), provide transitive access to `source`
1111
//! (via [`SourceIter`]) and thus the underlying allocation.
12-
//! And finally there are alignment and size constriants to consider, this is currently ensured via
12+
//! And finally there are alignment and size constraints to consider, this is currently ensured via
1313
//! const eval instead of trait bounds in the specialized [`SpecFromIter`] implementation.
1414
//!
1515
//! [`BinaryHeap<T>`]: crate::collections::BinaryHeap
@@ -168,7 +168,9 @@ const fn in_place_collectible<DEST, SRC>(
168168
step_merge: Option<NonZeroUsize>,
169169
step_expand: Option<NonZeroUsize>,
170170
) -> bool {
171-
if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::<SRC>() < mem::align_of::<DEST>() } {
171+
// Require matching alignments because an alignment-changing realloc is inefficient on many
172+
// system allocators and better implementations would require the unstable Allocator trait.
173+
if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
172174
return false;
173175
}
174176

@@ -188,7 +190,8 @@ const fn in_place_collectible<DEST, SRC>(
188190

189191
const fn needs_realloc<SRC, DEST>(src_cap: usize, dst_cap: usize) -> bool {
190192
if const { mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
191-
return src_cap > 0;
193+
// FIXME: use unreachable! once that works in const
194+
panic!("in_place_collectible() prevents this");
192195
}
193196

194197
// If src type size is an integer multiple of the destination type size then
@@ -276,8 +279,8 @@ where
276279
let dst_guard = InPlaceDstBufDrop { ptr: dst_buf, len, cap: dst_cap };
277280
src.forget_allocation_drop_remaining();
278281

279-
// Adjust the allocation if the alignment didn't match or the source had a capacity in bytes
280-
// that wasn't a multiple of the destination type size.
282+
// Adjust the allocation if the source had a capacity in bytes that wasn't a multiple
283+
// of the destination type size.
281284
// Since the discrepancy should generally be small this should only result in some
282285
// bookkeeping updates and no memmove.
283286
if needs_realloc::<I::Src, T>(src_cap, dst_cap) {
@@ -290,7 +293,7 @@ where
290293
let src_size = mem::size_of::<I::Src>().unchecked_mul(src_cap);
291294
let old_layout = Layout::from_size_align_unchecked(src_size, src_align);
292295

293-
// The must be equal or smaller for in-place iteration to be possible
296+
// The allocation must be equal or smaller for in-place iteration to be possible
294297
// therefore the new layout must be ≤ the old one and therefore valid.
295298
let dst_align = mem::align_of::<T>();
296299
let dst_size = mem::size_of::<T>().unchecked_mul(dst_cap);

alloc/src/vec/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ mod spec_extend;
358358
///
359359
/// `vec![x; n]`, `vec![a, b, c, d]`, and
360360
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
361-
/// with exactly the requested capacity. If <code>[len] == [capacity]</code>,
361+
/// with at least the requested capacity. If <code>[len] == [capacity]</code>,
362362
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
363363
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
364364
///
@@ -1023,8 +1023,11 @@ impl<T, A: Allocator> Vec<T, A> {
10231023

10241024
/// Shrinks the capacity of the vector as much as possible.
10251025
///
1026-
/// It will drop down as close as possible to the length but the allocator
1027-
/// may still inform the vector that there is space for a few more elements.
1026+
/// The behavior of this method depends on the allocator, which may either shrink the vector
1027+
/// in-place or reallocate. The resulting vector might still have some excess capacity, just as
1028+
/// is the case for [`with_capacity`]. See [`Allocator::shrink`] for more details.
1029+
///
1030+
/// [`with_capacity`]: Vec::with_capacity
10281031
///
10291032
/// # Examples
10301033
///
@@ -1074,10 +1077,10 @@ impl<T, A: Allocator> Vec<T, A> {
10741077

10751078
/// Converts the vector into [`Box<[T]>`][owned slice].
10761079
///
1077-
/// If the vector has excess capacity, its items will be moved into a
1078-
/// newly-allocated buffer with exactly the right capacity.
1080+
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
10791081
///
10801082
/// [owned slice]: Box
1083+
/// [`shrink_to_fit`]: Vec::shrink_to_fit
10811084
///
10821085
/// # Examples
10831086
///
@@ -3290,8 +3293,10 @@ impl<T, A: Allocator> From<Box<[T], A>> for Vec<T, A> {
32903293
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
32913294
/// Convert a vector into a boxed slice.
32923295
///
3293-
/// If `v` has excess capacity, its items will be moved into a
3294-
/// newly-allocated buffer with exactly the right capacity.
3296+
/// Before doing the conversion, this method discards excess capacity like [`Vec::shrink_to_fit`].
3297+
///
3298+
/// [owned slice]: Box
3299+
/// [`Vec::shrink_to_fit`]: Vec::shrink_to_fit
32953300
///
32963301
/// # Examples
32973302
///

alloc/src/vec/spec_from_iter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec};
1313
/// +-+-----------+
1414
/// |
1515
/// v
16-
/// +-+-------------------------------+ +---------------------+
17-
/// |SpecFromIter +---->+SpecFromIterNested |
18-
/// |where I: | | |where I: |
19-
/// | Iterator (default)----------+ | | Iterator (default) |
20-
/// | vec::IntoIter | | | TrustedLen |
21-
/// | SourceIterMarker---fallback-+ | +---------------------+
22-
/// +---------------------------------+
16+
/// +-+---------------------------------+ +---------------------+
17+
/// |SpecFromIter +---->+SpecFromIterNested |
18+
/// |where I: | | |where I: |
19+
/// | Iterator (default)------------+ | | Iterator (default) |
20+
/// | vec::IntoIter | | | TrustedLen |
21+
/// | InPlaceCollect--(fallback to)-+ | +---------------------+
22+
/// +-----------------------------------+
2323
/// ```
2424
pub(super) trait SpecFromIter<T, I> {
2525
fn from_iter(iter: I) -> Self;

core/benches/ascii.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ macro_rules! benches {
6363
}
6464
}
6565

66+
use std::fmt::Write;
6667
use test::black_box;
6768
use test::Bencher;
6869

@@ -351,3 +352,30 @@ static ASCII_CHARACTER_CLASS: [AsciiCharacterClass; 256] = [
351352
N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N,
352353
N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N,
353354
];
355+
356+
const ASCII_PATH: &[u8] = b"home/kyubey/rust/build/x86_64-unknown-linux-gnu/stage0/lib:/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0-tools/release/deps";
357+
const RUST_INCANTATION: &[u8] = br#"AR_x86_64_unknown_linux_gnu="ar" CARGO_INCREMENTAL="0" CARGO_PROFILE_RELEASE_DEBUG="1" CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="false" CARGO_PROFILE_RELEASE_OVERFLOW_CHECKS="false" CARGO_TARGET_DIR="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0-std" CC_x86_64_unknown_linux_gnu="cc" CFG_COMPILER_HOST_TRIPLE="x86_64-unknown-linux-gnu" CFG_RELEASE_CHANNEL="dev" CFLAGS_x86_64_unknown_linux_gnu="-ffunction-sections -fdata-sections -fPIC -m64" CXXFLAGS_x86_64_unknown_linux_gnu="-ffunction-sections -fdata-sections -fPIC -m64" CXX_x86_64_unknown_linux_gnu="c++" LD_LIBRARY_PATH="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" LIBC_CHECK_CFG="1" RANLIB_x86_64_unknown_linux_gnu="ar s" REAL_LIBRARY_PATH_VAR="LD_LIBRARY_PATH" RUSTBUILD_NATIVE_DIR="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/native" RUSTC="/home/kyubey/workspace/rust/build/bootstrap/debug/rustc" RUSTC_BOOTSTRAP="1" RUSTC_BREAK_ON_ICE="1" RUSTC_ERROR_METADATA_DST="/home/kyubey/workspace/rust/build/tmp/extended-error-metadata" RUSTC_FORCE_UNSTABLE="1" RUSTC_HOST_FUSE_LD_LLD="1" RUSTC_INSTALL_BINDIR="bin" RUSTC_LIBDIR="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/lib" RUSTC_LINT_FLAGS="-Wrust_2018_idioms -Wunused_lifetimes -Wsemicolon_in_expressions_from_macros" RUSTC_REAL="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc" RUSTC_SNAPSHOT="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc" RUSTC_SNAPSHOT_LIBDIR="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/lib" RUSTC_STAGE="0" RUSTC_SYSROOT="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot" RUSTC_VERBOSE="0" RUSTDOC="/home/kyubey/workspace/rust/build/bootstrap/debug/rustdoc" RUSTDOCFLAGS="-C target-cpu=native --cfg=bootstrap -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(no_rc) --check-cfg=values(no_sync) --check-cfg=values(freebsd12) --check-cfg=values(freebsd13) --check-cfg=values(backtrace_in_libstd) --check-cfg=values(target_env,\"libnx\") --check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"xtensa\") -Clink-arg=-fuse-ld=lld -Clink-arg=-Wl,--threads=1 -Wrustdoc::invalid_codeblock_attributes --crate-version 1.72.0-dev -Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\") -Zcrate-attr=warn(rust_2018_idioms)" RUSTDOC_FUSE_LD_LLD="1" RUSTDOC_LIBDIR="/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/lib" RUSTDOC_REAL="/path/to/nowhere/rustdoc/not/required" RUSTFLAGS="-C target-cpu=native --cfg=bootstrap -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(no_rc) --check-cfg=values(no_sync) --check-cfg=values(freebsd12) --check-cfg=values(freebsd13) --check-cfg=values(backtrace_in_libstd) --check-cfg=values(target_env,\"libnx\") --check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"xtensa\") -Zmacro-backtrace -Clink-args=-Wl,-z,origin -Clink-args=-Wl,-rpath,$ORIGIN/../lib -Clink-args=-fuse-ld=lld -Csplit-debuginfo=off -Cprefer-dynamic -Zinline-mir -Clto=off -Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" RUST_COMPILER_RT_ROOT="/home/kyubey/workspace/rust/src/llvm-project/compiler-rt" RUST_TEST_THREADS="48" WINAPI_NO_BUNDLED_LIBRARIES="1" __CARGO_DEFAULT_LIB_METADATA="bootstrapstd" "/home/kyubey/workspace/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "bench" "--target" "x86_64-unknown-linux-gnu" "-Zcheck-cfg=names,values,output" "-Zbinary-dep-depinfo" "-j" "48" "--features" " panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/home/kyubey/workspace/rust/library/sysroot/Cargo.toml" "-p" "core" "--" "bench_ascii_escape_display" "--quiet" "-Z" "unstable-options" "--format" "json""#;
358+
359+
#[bench]
360+
fn bench_ascii_escape_display_no_escape(b: &mut Bencher) {
361+
let mut writer = String::with_capacity(8 * 1024);
362+
363+
b.iter(move || {
364+
writer.clear();
365+
let iter = ASCII_PATH.escape_ascii();
366+
write!(writer, "{}", iter).unwrap();
367+
writer.len()
368+
})
369+
}
370+
371+
#[bench]
372+
fn bench_ascii_escape_display_mixed(b: &mut Bencher) {
373+
let mut writer = String::with_capacity(8 * 1024);
374+
375+
b.iter(move || {
376+
writer.clear();
377+
let iter = RUST_INCANTATION.escape_ascii();
378+
write!(writer, "{}", iter).unwrap();
379+
writer.len()
380+
})
381+
}

core/src/array/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<T, const N: usize> [T; N] {
647647
)]
648648
#[inline]
649649
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T]) {
650-
(&self[..]).split_array_ref::<M>()
650+
(&self[..]).split_first_chunk::<M>().unwrap()
651651
}
652652

653653
/// Divides one mutable array reference into two at an index.
@@ -680,7 +680,7 @@ impl<T, const N: usize> [T; N] {
680680
)]
681681
#[inline]
682682
pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T]) {
683-
(&mut self[..]).split_array_mut::<M>()
683+
(&mut self[..]).split_first_chunk_mut::<M>().unwrap()
684684
}
685685

686686
/// Divides one array reference into two at an index from the end.
@@ -725,7 +725,7 @@ impl<T, const N: usize> [T; N] {
725725
)]
726726
#[inline]
727727
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M]) {
728-
(&self[..]).rsplit_array_ref::<M>()
728+
(&self[..]).split_last_chunk::<M>().unwrap()
729729
}
730730

731731
/// Divides one mutable array reference into two at an index from the end.
@@ -758,7 +758,7 @@ impl<T, const N: usize> [T; N] {
758758
)]
759759
#[inline]
760760
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M]) {
761-
(&mut self[..]).rsplit_array_mut::<M>()
761+
(&mut self[..]).split_last_chunk_mut::<M>().unwrap()
762762
}
763763
}
764764

core/src/ascii.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ pub fn escape_default(c: u8) -> EscapeDefault {
9696
EscapeDefault(escape::EscapeIterInner::new(data, range))
9797
}
9898

99+
impl EscapeDefault {
100+
pub(crate) fn empty() -> Self {
101+
let data = [Char::Null; 4];
102+
EscapeDefault(escape::EscapeIterInner::new(data, 0..0))
103+
}
104+
105+
pub(crate) fn as_str(&self) -> &str {
106+
self.0.as_str()
107+
}
108+
}
109+
99110
#[stable(feature = "rust1", since = "1.0.0")]
100111
impl Iterator for EscapeDefault {
101112
type Item = u8;

core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ where
415415
// Request and its methods
416416
///////////////////////////////////////////////////////////////////////////////
417417

418-
/// `Request` supports generic, type-driven access to data. It's use is currently restricted to the
418+
/// `Request` supports generic, type-driven access to data. Its use is currently restricted to the
419419
/// standard library in cases where trait authors wish to allow trait implementors to share generic
420420
/// information across trait boundaries. The motivating and prototypical use case is
421421
/// `core::error::Error` which would otherwise require a method per concrete type (eg.

core/src/iter/adapters/flatten.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ impl<I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U> FlatMap<I, U, F> {
2424
pub(in crate::iter) fn new(iter: I, f: F) -> FlatMap<I, U, F> {
2525
FlatMap { inner: FlattenCompat::new(iter.map(f)) }
2626
}
27+
28+
pub(crate) fn into_parts(self) -> (Option<U::IntoIter>, Option<I>, Option<U::IntoIter>) {
29+
(
30+
self.inner.frontiter,
31+
self.inner.iter.into_inner().map(Map::into_inner),
32+
self.inner.backiter,
33+
)
34+
}
2735
}
2836

2937
#[stable(feature = "rust1", since = "1.0.0")]

core/src/iter/adapters/fuse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl<I> Fuse<I> {
2424
pub(in crate::iter) fn new(iter: I) -> Fuse<I> {
2525
Fuse { iter: Some(iter) }
2626
}
27+
28+
pub(crate) fn into_inner(self) -> Option<I> {
29+
self.iter
30+
}
2731
}
2832

2933
#[stable(feature = "fused", since = "1.26.0")]

0 commit comments

Comments
 (0)