Skip to content

Commit 8c17efd

Browse files
Merge branch 'main' into slicechallenges
2 parents 6abf6b4 + b152f68 commit 8c17efd

File tree

61 files changed

+1629
-285
lines changed

Some content is hidden

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

61 files changed

+1629
-285
lines changed

.github/workflows/update-subtree.yml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ jobs:
137137
uses: peter-evans/create-pull-request@v7
138138
with:
139139
title: 'Update subtree/library to ${{ env.NEXT_TOOLCHAIN_DATE }}'
140-
body: |
140+
body: >
141141
This is an automated PR to update the subtree/library branch to the changes
142-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
143-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}), inclusive.
144-
**Do not merge this PR using the merge queue. Instead, use the rebase strategy.**
142+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
143+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}), inclusive.
144+
145+
**Review this PR as usual, but do not merge this PR using the GitHub web interface.
146+
Instead, once it is approved, use `git push` to literally push the changes to `subtree/library`
147+
without any rebase or merge.**
145148
branch: update-subtree/library
146149
delete-branch: true
147150
base: subtree/library
@@ -151,20 +154,36 @@ jobs:
151154
if: ${{ env.MERGE_CONFLICTS != 'noop' && env.MERGE_PR_EXISTS == 'no' }}
152155
run: |
153156
cd verify-rust-std
154-
if ! git rev-parse --verify subtree/library; then
157+
# create-pull-request resets branches locally, implying that
158+
# `subtree/library` no longer is what the above instructions created.
159+
if [ "${SUBTREE_PR_EXISTS}" = "yes" ]; then
155160
git checkout -t -b subtree/library origin/update-subtree/library
161+
else
162+
git checkout subtree/library
163+
git reset --hard origin/update-subtree/library
156164
fi
157165
git checkout main
158166
167+
# Tell git about the correct merge base to use, which is the subtree
168+
# head that we last merged from.
169+
PREV_SUBTREE_HEAD=$(git log --grep="^git-subtree-split:" | egrep '^[[:space:]]+git-subtree-split:' | awk '{print $2;exit}')
170+
echo "Previous subtree head: ${PREV_SUBTREE_HEAD}"
171+
git replace --graft subtree/library ${PREV_SUBTREE_HEAD}
172+
git replace --graft main ${PREV_SUBTREE_HEAD}
173+
159174
# This command may fail, which will require human intervention.
160175
if ! git \
161176
-c user.name=gitbot -c user.email=git@bot \
162-
subtree merge --prefix=library subtree/library --squash; then
177+
merge -Xsubtree=library subtree/library; then
163178
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
164179
git -c user.name=gitbot -c user.email=git@bot commit -a -m "Merge from $NEXT_COMMIT_HASH with conflicts"
165180
else
166181
echo "MERGE_CONFLICTS=no" >> $GITHUB_ENV
167182
fi
183+
git replace -d subtree/library
184+
git replace -d main~1
185+
NEW_SUBTREE_HEAD=$(git rev-parse subtree/library)
186+
echo "NEW_SUBTREE_HEAD=${NEW_SUBTREE_HEAD}" >> $GITHUB_ENV
168187
169188
sed -i "s/^channel = \"nightly-.*\"/channel = \"nightly-${NEXT_TOOLCHAIN_DATE}\"/" rust-toolchain.toml
170189
git -c user.name=gitbot -c user.email=git@bot \
@@ -173,16 +192,22 @@ jobs:
173192
sed -i "s/commit = .*/commit = \"${KANI_COMMIT_HASH}\"/" tool_config/kani-version.toml
174193
git -c user.name=gitbot -c user.email=git@bot \
175194
commit -m "Update Kani version to ${KANI_COMMIT_HASH}" tool_config/kani-version.toml
195+
176196
- name: Create Pull Request without conflicts
177197
if: ${{ env.MERGE_CONFLICTS == 'no' && env.MERGE_PR_EXISTS == 'no' }}
178198
uses: peter-evans/create-pull-request@v7
179199
with:
180200
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
181-
body: |
201+
body: >
182202
This is an automated PR to merge library subtree updates
183-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
184-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}), inclusive.
203+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
204+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}), inclusive.
185205
This is a clean merge, no conflicts were detected.
206+
**Do not remove or edit the following annotations:**
207+
208+
git-subtree-dir: library
209+
210+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
186211
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
187212
delete-branch: true
188213
base: main
@@ -193,12 +218,17 @@ jobs:
193218
uses: peter-evans/create-pull-request@v7
194219
with:
195220
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
196-
body: |
221+
body: >
197222
This is an automated PR to merge library subtree updates
198-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
199-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}) (inclusive)
223+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
224+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}) (inclusive)
200225
into main. `git merge` resulted in conflicts, which require manual resolution.
201226
Files were commited with merge conflict markers.
227+
**Do not remove or edit the following annotations:**
228+
229+
git-subtree-dir: library
230+
231+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
202232
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
203233
delete-branch: true
204234
base: main

library/Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
]
99

1010
exclude = [
11+
"literal-escaper",
1112
# stdarch has its own Cargo workspace
1213
"stdarch",
1314
"windows_targets"

library/alloc/src/sync.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,29 @@ macro_rules! acquire {
8484
///
8585
/// Shared references in Rust disallow mutation by default, and `Arc` is no
8686
/// exception: you cannot generally obtain a mutable reference to something
87-
/// inside an `Arc`. If you need to mutate through an `Arc`, use
88-
/// [`Mutex`][mutex], [`RwLock`][rwlock], or one of the [`Atomic`][atomic]
89-
/// types.
87+
/// inside an `Arc`. If you do need to mutate through an `Arc`, you have several options:
88+
///
89+
/// 1. Use interior mutability with synchronization primitives like [`Mutex`][mutex],
90+
/// [`RwLock`][rwlock], or one of the [`Atomic`][atomic] types.
91+
///
92+
/// 2. Use clone-on-write semantics with [`Arc::make_mut`] which provides efficient mutation
93+
/// without requiring interior mutability. This approach clones the data only when
94+
/// needed (when there are multiple references) and can be more efficient when mutations
95+
/// are infrequent.
96+
///
97+
/// 3. Use [`Arc::get_mut`] when you know your `Arc` is not shared (has a reference count of 1),
98+
/// which provides direct mutable access to the inner value without any cloning.
99+
///
100+
/// ```
101+
/// use std::sync::Arc;
102+
///
103+
/// let mut data = Arc::new(vec![1, 2, 3]);
104+
///
105+
/// // This will clone the vector only if there are other references to it
106+
/// Arc::make_mut(&mut data).push(4);
107+
///
108+
/// assert_eq!(*data, vec![1, 2, 3, 4]);
109+
/// ```
90110
///
91111
/// **Note**: This type is only available on platforms that support atomic
92112
/// loads and stores of pointers, which includes all platforms that support

library/alloc/src/vec/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,19 @@ impl<T, A: Allocator> Vec<T, A> {
12521252
/// vec.push(42);
12531253
/// assert!(vec.capacity() >= 10);
12541254
/// ```
1255+
///
1256+
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
1257+
///
1258+
/// ```
1259+
/// #[derive(Clone)]
1260+
/// struct ZeroSized;
1261+
///
1262+
/// fn main() {
1263+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1264+
/// let v = vec![ZeroSized; 0];
1265+
/// assert_eq!(v.capacity(), usize::MAX);
1266+
/// }
1267+
/// ```
12551268
#[inline]
12561269
#[stable(feature = "rust1", since = "1.0.0")]
12571270
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]

library/core/src/convert/num.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,42 @@ impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.2
156156
// https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-951.pdf
157157

158158
// Note: integers can only be represented with full precision in a float if
159-
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
159+
// they fit in the significand, which is:
160+
// * 11 bits in f16
161+
// * 24 bits in f32
162+
// * 53 bits in f64
163+
// * 113 bits in f128
160164
// Lossy float conversions are not implemented at this time.
165+
// FIXME(f16_f128): The `f16`/`f128` impls `#[stable]` attributes should be changed to reference
166+
// `f16`/`f128` when they are stabilised (trait impls have to have a `#[stable]` attribute, but none
167+
// of the `f16`/`f128` impls can be used on stable as the `f16` and `f128` types are unstable).
161168

162169
// signed integer -> float
170+
impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
163171
impl_from!(i8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
164172
impl_from!(i8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
173+
impl_from!(i8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
165174
impl_from!(i16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
166175
impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
176+
impl_from!(i16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
167177
impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
178+
impl_from!(i32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
179+
// FIXME(f16_f128): This impl would allow using `f128` on stable before it is stabilised.
180+
// impl_from!(i64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
168181

169182
// unsigned integer -> float
183+
impl_from!(u8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
170184
impl_from!(u8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
171185
impl_from!(u8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
186+
impl_from!(u8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
187+
impl_from!(u16 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172188
impl_from!(u16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
173189
impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
190+
impl_from!(u16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
174191
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
192+
impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
193+
// FIXME(f16_f128): This impl would allow using `f128` on stable before it is stabilised.
194+
// impl_from!(u64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
175195

176196
// float -> float
177197
// FIXME(f16_f128): adding additional `From<{float}>` impls to `f32` breaks inference. See
@@ -183,20 +203,27 @@ impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0
183203
impl_from!(f64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
184204

185205
macro_rules! impl_float_from_bool {
186-
($float:ty) => {
206+
(
207+
$float:ty $(;
208+
doctest_prefix: $(#[doc = $doctest_prefix:literal])*
209+
doctest_suffix: $(#[doc = $doctest_suffix:literal])*
210+
)?
211+
) => {
187212
#[stable(feature = "float_from_bool", since = "1.68.0")]
188213
impl From<bool> for $float {
189214
#[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
190215
/// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
191216
///
192217
/// # Examples
193218
/// ```
219+
$($(#[doc = $doctest_prefix])*)?
194220
#[doc = concat!("let x: ", stringify!($float)," = false.into();")]
195221
/// assert_eq!(x, 0.0);
196222
/// assert!(x.is_sign_positive());
197223
///
198224
#[doc = concat!("let y: ", stringify!($float)," = true.into();")]
199225
/// assert_eq!(y, 1.0);
226+
$($(#[doc = $doctest_suffix])*)?
200227
/// ```
201228
#[inline]
202229
fn from(small: bool) -> Self {
@@ -207,8 +234,27 @@ macro_rules! impl_float_from_bool {
207234
}
208235

209236
// boolean -> float
237+
impl_float_from_bool!(
238+
f16;
239+
doctest_prefix:
240+
// rustdoc doesn't remove the conventional space after the `///`
241+
///#![feature(f16)]
242+
///# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
243+
///
244+
doctest_suffix:
245+
///# }
246+
);
210247
impl_float_from_bool!(f32);
211248
impl_float_from_bool!(f64);
249+
impl_float_from_bool!(
250+
f128;
251+
doctest_prefix:
252+
///#![feature(f128)]
253+
///# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
254+
///
255+
doctest_suffix:
256+
///# }
257+
);
212258

213259
// no possible bounds violation
214260
macro_rules! impl_try_from_unbounded {

library/core/src/intrinsics/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,8 @@ pub const fn ptr_metadata<P: ptr::Pointee<Metadata = M> + ?Sized, M>(ptr: *const
36643664
/// For regions of memory which might overlap, use [`copy`] instead.
36653665
///
36663666
/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
3667-
/// with the argument order swapped.
3667+
/// with the source and destination arguments swapped,
3668+
/// and `count` counting the number of `T`s instead of bytes.
36683669
///
36693670
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the
36703671
/// requirements of `T`. The initialization state is preserved exactly.
@@ -3791,8 +3792,10 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
37913792
/// If the source and destination will *never* overlap,
37923793
/// [`copy_nonoverlapping`] can be used instead.
37933794
///
3794-
/// `copy` is semantically equivalent to C's [`memmove`], but with the argument
3795-
/// order swapped. Copying takes place as if the bytes were copied from `src`
3795+
/// `copy` is semantically equivalent to C's [`memmove`], but
3796+
/// with the source and destination arguments swapped,
3797+
/// and `count` counting the number of `T`s instead of bytes.
3798+
/// Copying takes place as if the bytes were copied from `src`
37963799
/// to a temporary array and then copied from the array to `dst`.
37973800
///
37983801
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the

library/core/src/ops/control_flow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ use crate::{convert, ops};
8080
/// [`Continue`]: ControlFlow::Continue
8181
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
8282
#[rustc_diagnostic_item = "ControlFlow"]
83+
#[must_use]
8384
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
8485
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
8586
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

library/literal-escaper/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "literal-escaper"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
std = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-std' }
8+
9+
[features]
10+
rustc-dep-of-std = ["dep:std"]

library/literal-escaper/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# literal-escaper
2+
3+
This crate provides code to unescape string literals. It is used by `rustc_lexer`
4+
and `proc_macro`.

0 commit comments

Comments
 (0)