Skip to content

Commit 7850c28

Browse files
committed
Auto merge of rust-lang#81578 - jonas-schievink:rollup-yhiyowl, r=jonas-schievink
Rollup of 18 pull requests Successful merges: - rust-lang#78044 (Implement io::Seek for io::Empty) - rust-lang#79285 (Stabilize Arc::{increment,decrement}_strong_count) - rust-lang#80053 (stabilise `cargo test -- --include-ignored`) - rust-lang#80279 (Implement missing `AsMut<str>` for `str`) - rust-lang#80470 (Stabilize by-value `[T; N]` iterator `core::array::IntoIter`) - rust-lang#80945 (Add Box::downcast() for dyn Any + Send + Sync) - rust-lang#81048 (Stabilize `core::slice::fill_with`) - rust-lang#81198 (Remove requirement that forces symmetric and transitive PartialEq impls to exist) - rust-lang#81422 (Account for existing `_` field pattern when suggesting `..`) - rust-lang#81472 (Clone entire `TokenCursor` when collecting tokens) - rust-lang#81484 (Optimize decimal formatting of 128-bit integers) - rust-lang#81491 (Balance sidebar `Deref` cycle check with main content) - rust-lang#81509 (Add a regression test for ICE of bad_placeholder_type) - rust-lang#81547 (Edit rustc_typeck top-level docs) - rust-lang#81550 (Replace predecessor with range in collections documentation) - rust-lang#81558 (Fix ascii art text wrapping in mobile) - rust-lang#81562 (Clarify that InPlaceIterable guarantees extend to all advancing iterator methods.) - rust-lang#81563 (Improve docblock readability on small screen) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b3897e3 + 8b281d9 commit 7850c28

File tree

35 files changed

+284
-118
lines changed

35 files changed

+284
-118
lines changed

compiler/rustc_arena/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
1212
test(no_crate_inject, attr(deny(warnings)))
1313
)]
14-
#![feature(array_value_iter_slice)]
1514
#![feature(dropck_eyepatch)]
1615
#![feature(new_uninit)]
1716
#![feature(maybe_uninit_slice)]
18-
#![feature(array_value_iter)]
1917
#![cfg_attr(bootstrap, feature(min_const_generics))]
2018
#![feature(min_specialization)]
2119
#![cfg_attr(test, feature(test))]

compiler/rustc_ast_lowering/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
//! get confused if the spans from leaf AST nodes occur in multiple places
3131
//! in the HIR, especially for multiple identifiers.
3232
33-
#![feature(array_value_iter)]
3433
#![feature(crate_visibility_modifier)]
3534
#![feature(or_patterns)]
3635
#![recursion_limit = "256"]

compiler/rustc_hir/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
5-
#![feature(array_value_iter)]
65
#![feature(crate_visibility_modifier)]
76
#![feature(const_fn)] // For the unsizing cast on `&[]`
87
#![feature(const_panic)]

compiler/rustc_parse/src/parser/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1254,15 +1254,7 @@ impl<'a> Parser<'a> {
12541254
f: impl FnOnce(&mut Self) -> PResult<'a, (R, TrailingToken)>,
12551255
) -> PResult<'a, R> {
12561256
let start_token = (self.token.clone(), self.token_spacing);
1257-
let cursor_snapshot = TokenCursor {
1258-
frame: self.token_cursor.frame.clone(),
1259-
// We only ever capture tokens within our current frame,
1260-
// so we can just use an empty frame stack
1261-
stack: vec![],
1262-
desugar_doc_comments: self.token_cursor.desugar_doc_comments,
1263-
num_next_calls: self.token_cursor.num_next_calls,
1264-
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
1265-
};
1257+
let cursor_snapshot = self.token_cursor.clone();
12661258

12671259
let (mut ret, trailing_token) = f(self)?;
12681260

compiler/rustc_trait_selection/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! This API is completely unstable and subject to change.
1212
1313
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
14-
#![feature(array_value_iter)]
1514
#![feature(bool_to_option)]
1615
#![feature(box_patterns)]
1716
#![feature(drain_filter)]

compiler/rustc_typeck/src/check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ The types of top-level items, which never contain unbound type
5252
variables, are stored directly into the `tcx` typeck_results.
5353
5454
N.B., a type variable is not the same thing as a type parameter. A
55-
type variable is rather an "instance" of a type parameter: that is,
56-
given a generic function `fn foo<T>(t: T)`: while checking the
55+
type variable is an instance of a type parameter. That is,
56+
given a generic function `fn foo<T>(t: T)`, while checking the
5757
function `foo`, the type `ty_param(0)` refers to the type `T`, which
58-
is treated in abstract. When `foo()` is called, however, `T` will be
58+
is treated in abstract. However, when `foo()` is called, `T` will be
5959
substituted for a fresh type variable `N`. This variable will
6060
eventually be resolved to some concrete type (which might itself be
61-
type parameter).
61+
a type parameter).
6262
6363
*/
6464

compiler/rustc_typeck/src/check/pat.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1041,12 +1041,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10411041
vec![(left, "(".to_string()), (right.shrink_to_hi(), ")".to_string())],
10421042
Applicability::MachineApplicable,
10431043
);
1044-
} else if fields.len() > subpats.len() {
1045-
let after_fields_span = if pat_span == DUMMY_SP {
1046-
pat_span
1047-
} else {
1048-
pat_span.with_hi(pat_span.hi() - BytePos(1)).shrink_to_hi()
1049-
};
1044+
} else if fields.len() > subpats.len() && pat_span != DUMMY_SP {
1045+
let after_fields_span = pat_span.with_hi(pat_span.hi() - BytePos(1)).shrink_to_hi();
10501046
let all_fields_span = match subpats {
10511047
[] => after_fields_span,
10521048
[field] => field.span,
@@ -1055,7 +1051,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10551051

10561052
// Check if all the fields in the pattern are wildcards.
10571053
let all_wildcards = subpats.iter().all(|pat| matches!(pat.kind, PatKind::Wild));
1054+
let first_tail_wildcard =
1055+
subpats.iter().enumerate().fold(None, |acc, (pos, pat)| match (acc, &pat.kind) {
1056+
(None, PatKind::Wild) => Some(pos),
1057+
(Some(_), PatKind::Wild) => acc,
1058+
_ => None,
1059+
});
1060+
let tail_span = match first_tail_wildcard {
1061+
None => after_fields_span,
1062+
Some(0) => subpats[0].span.to(after_fields_span),
1063+
Some(pos) => subpats[pos - 1].span.shrink_to_hi().to(after_fields_span),
1064+
};
10581065

1066+
// FIXME: heuristic-based suggestion to check current types for where to add `_`.
10591067
let mut wildcard_sugg = vec!["_"; fields.len() - subpats.len()].join(", ");
10601068
if !subpats.is_empty() {
10611069
wildcard_sugg = String::from(", ") + &wildcard_sugg;
@@ -1080,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10801088
);
10811089
} else {
10821090
err.span_suggestion_verbose(
1083-
after_fields_span,
1091+
tail_span,
10841092
"use `..` to ignore the rest of the fields",
10851093
String::from(", .."),
10861094
Applicability::MaybeIncorrect,

compiler/rustc_typeck/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ The type checker is responsible for:
77
1. Determining the type of each expression.
88
2. Resolving methods and traits.
99
3. Guaranteeing that most type rules are met. ("Most?", you say, "why most?"
10-
Well, dear reader, read on)
10+
Well, dear reader, read on.)
1111
12-
The main entry point is `check_crate()`. Type checking operates in
12+
The main entry point is [`check_crate()`]. Type checking operates in
1313
several major phases:
1414
1515
1. The collect phase first passes over all items and determines their
@@ -25,7 +25,7 @@ several major phases:
2525
containing function). Inference is used to supply types wherever
2626
they are unknown. The actual checking of a function itself has
2727
several phases (check, regionck, writeback), as discussed in the
28-
documentation for the `check` module.
28+
documentation for the [`check`] module.
2929
3030
The type checker is defined into various submodules which are documented
3131
independently:
@@ -56,7 +56,6 @@ This API is completely unstable and subject to change.
5656
*/
5757

5858
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
59-
#![feature(array_value_iter)]
6059
#![feature(bool_to_option)]
6160
#![feature(box_syntax)]
6261
#![feature(crate_visibility_modifier)]

library/alloc/src/boxed.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,39 @@ impl<A: Allocator> Box<dyn Any + Send, A> {
13721372
}
13731373
}
13741374

1375+
impl<A: Allocator> Box<dyn Any + Send + Sync, A> {
1376+
#[inline]
1377+
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
1378+
/// Attempt to downcast the box to a concrete type.
1379+
///
1380+
/// # Examples
1381+
///
1382+
/// ```
1383+
/// use std::any::Any;
1384+
///
1385+
/// fn print_if_string(value: Box<dyn Any + Send + Sync>) {
1386+
/// if let Ok(string) = value.downcast::<String>() {
1387+
/// println!("String ({}): {}", string.len(), string);
1388+
/// }
1389+
/// }
1390+
///
1391+
/// let my_string = "Hello World".to_string();
1392+
/// print_if_string(Box::new(my_string));
1393+
/// print_if_string(Box::new(0i8));
1394+
/// ```
1395+
pub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self> {
1396+
if self.is::<T>() {
1397+
unsafe {
1398+
let (raw, alloc): (*mut (dyn Any + Send + Sync), _) =
1399+
Box::into_raw_with_allocator(self);
1400+
Ok(Box::from_raw_in(raw as *mut T, alloc))
1401+
}
1402+
} else {
1403+
Err(self)
1404+
}
1405+
}
1406+
}
1407+
13751408
#[stable(feature = "rust1", since = "1.0.0")]
13761409
impl<T: fmt::Display + ?Sized, A: Allocator> fmt::Display for Box<T, A> {
13771410
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#![feature(allocator_api)]
7979
#![feature(array_chunks)]
8080
#![feature(array_methods)]
81-
#![feature(array_value_iter)]
8281
#![feature(array_windows)]
8382
#![feature(allow_internal_unstable)]
8483
#![feature(arbitrary_self_types)]

library/alloc/src/sync.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -962,15 +962,13 @@ impl<T: ?Sized> Arc<T> {
962962
/// # Examples
963963
///
964964
/// ```
965-
/// #![feature(arc_mutate_strong_count)]
966-
///
967965
/// use std::sync::Arc;
968966
///
969967
/// let five = Arc::new(5);
970968
///
971969
/// unsafe {
972970
/// let ptr = Arc::into_raw(five);
973-
/// Arc::incr_strong_count(ptr);
971+
/// Arc::increment_strong_count(ptr);
974972
///
975973
/// // This assertion is deterministic because we haven't shared
976974
/// // the `Arc` between threads.
@@ -979,8 +977,8 @@ impl<T: ?Sized> Arc<T> {
979977
/// }
980978
/// ```
981979
#[inline]
982-
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
983-
pub unsafe fn incr_strong_count(ptr: *const T) {
980+
#[stable(feature = "arc_mutate_strong_count", since = "1.51.0")]
981+
pub unsafe fn increment_strong_count(ptr: *const T) {
984982
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
985983
let arc = unsafe { mem::ManuallyDrop::new(Arc::<T>::from_raw(ptr)) };
986984
// Now increase refcount, but don't drop new refcount either
@@ -1001,27 +999,25 @@ impl<T: ?Sized> Arc<T> {
1001999
/// # Examples
10021000
///
10031001
/// ```
1004-
/// #![feature(arc_mutate_strong_count)]
1005-
///
10061002
/// use std::sync::Arc;
10071003
///
10081004
/// let five = Arc::new(5);
10091005
///
10101006
/// unsafe {
10111007
/// let ptr = Arc::into_raw(five);
1012-
/// Arc::incr_strong_count(ptr);
1008+
/// Arc::increment_strong_count(ptr);
10131009
///
10141010
/// // Those assertions are deterministic because we haven't shared
10151011
/// // the `Arc` between threads.
10161012
/// let five = Arc::from_raw(ptr);
10171013
/// assert_eq!(2, Arc::strong_count(&five));
1018-
/// Arc::decr_strong_count(ptr);
1014+
/// Arc::decrement_strong_count(ptr);
10191015
/// assert_eq!(1, Arc::strong_count(&five));
10201016
/// }
10211017
/// ```
10221018
#[inline]
1023-
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
1024-
pub unsafe fn decr_strong_count(ptr: *const T) {
1019+
#[stable(feature = "arc_mutate_strong_count", since = "1.51.0")]
1020+
pub unsafe fn decrement_strong_count(ptr: *const T) {
10251021
unsafe { mem::drop(Arc::from_raw(ptr)) };
10261022
}
10271023

library/alloc/src/task.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
6262
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
6363
// Increment the reference count of the arc to clone it.
6464
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
65-
unsafe { Arc::incr_strong_count(waker as *const W) };
65+
unsafe { Arc::increment_strong_count(waker as *const W) };
6666
RawWaker::new(
6767
waker as *const (),
6868
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
@@ -83,7 +83,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
8383

8484
// Decrement the reference count of the Arc on drop
8585
unsafe fn drop_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) {
86-
unsafe { Arc::decr_strong_count(waker as *const W) };
86+
unsafe { Arc::decrement_strong_count(waker as *const W) };
8787
}
8888

8989
RawWaker::new(

library/core/src/array/iter.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
/// A by-value [array] iterator.
1212
///
1313
/// [array]: ../../std/primitive.array.html
14-
#[unstable(feature = "array_value_iter", issue = "65798")]
14+
#[stable(feature = "array_value_iter", since = "1.51.0")]
1515
pub struct IntoIter<T, const N: usize> {
1616
/// This is the array we are iterating over.
1717
///
@@ -38,10 +38,21 @@ pub struct IntoIter<T, const N: usize> {
3838
impl<T, const N: usize> IntoIter<T, N> {
3939
/// Creates a new iterator over the given `array`.
4040
///
41-
/// *Note*: this method might never get stabilized and/or removed in the
42-
/// future as there will likely be another, preferred way of obtaining this
43-
/// iterator (either via `IntoIterator` for arrays or via another way).
44-
#[unstable(feature = "array_value_iter", issue = "65798")]
41+
/// *Note*: this method might be deprecated in the future,
42+
/// after [`IntoIterator` is implemented for arrays][array-into-iter].
43+
///
44+
/// # Examples
45+
///
46+
/// ```
47+
/// use std::array;
48+
///
49+
/// for value in array::IntoIter::new([1, 2, 3, 4, 5]) {
50+
/// // The type of `value` is a `i32` here, instead of `&i32`
51+
/// let _: i32 = value;
52+
/// }
53+
/// ```
54+
/// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
55+
#[stable(feature = "array_value_iter", since = "1.51.0")]
4556
pub fn new(array: [T; N]) -> Self {
4657
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`
4758
// promise:
@@ -69,7 +80,7 @@ impl<T, const N: usize> IntoIter<T, N> {
6980

7081
/// Returns an immutable slice of all elements that have not been yielded
7182
/// yet.
72-
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
83+
#[stable(feature = "array_value_iter", since = "1.51.0")]
7384
pub fn as_slice(&self) -> &[T] {
7485
// SAFETY: We know that all elements within `alive` are properly initialized.
7586
unsafe {
@@ -79,7 +90,7 @@ impl<T, const N: usize> IntoIter<T, N> {
7990
}
8091

8192
/// Returns a mutable slice of all elements that have not been yielded yet.
82-
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
93+
#[stable(feature = "array_value_iter", since = "1.51.0")]
8394
pub fn as_mut_slice(&mut self) -> &mut [T] {
8495
// SAFETY: We know that all elements within `alive` are properly initialized.
8596
unsafe {

library/core/src/array/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::slice::{Iter, IterMut};
1818

1919
mod iter;
2020

21-
#[unstable(feature = "array_value_iter", issue = "65798")]
21+
#[stable(feature = "array_value_iter", since = "1.51.0")]
2222
pub use iter::IntoIter;
2323

2424
/// Converts a reference to `T` into a reference to an array of length 1 (without copying).

library/core/src/cmp.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ use self::Ordering::*;
3131
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
3232
/// so floating point types implement `PartialEq` but not [`trait@Eq`].
3333
///
34-
/// Formally, the equality must be (for all `a`, `b` and `c`):
34+
/// Formally, the equality must be (for all `a`, `b`, `c` of type `A`, `B`,
35+
/// `C`):
3536
///
36-
/// - symmetric: `a == b` implies `b == a`; and
37-
/// - transitive: `a == b` and `b == c` implies `a == c`.
37+
/// - **Symmetric**: if `A: PartialEq<B>` and `B: PartialEq<A>`, then **`a == b`
38+
/// implies `b == a`**; and
39+
///
40+
/// - **Transitive**: if `A: PartialEq<B>` and `B: PartialEq<C>` and `A:
41+
/// PartialEq<C>`, then **`a == b` and `b == c` implies `a == c`**.
3842
///
39-
/// Note that these requirements mean that the trait itself must be implemented
40-
/// symmetrically and transitively: if `T: PartialEq<U>` and `U: PartialEq<V>`
41-
/// then `U: PartialEq<T>` and `T: PartialEq<V>`.
43+
/// Note that the `B: PartialEq<A>` (symmetric) and `A: PartialEq<C>`
44+
/// (transitive) impls are not forced to exist, but these requirements apply
45+
/// whenever they do exist.
4246
///
4347
/// ## Derivable
4448
///

library/core/src/convert/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,14 @@ impl AsRef<str> for str {
616616
}
617617
}
618618

619+
#[stable(feature = "as_mut_str_for_str", since = "1.51.0")]
620+
impl AsMut<str> for str {
621+
#[inline]
622+
fn as_mut(&mut self) -> &mut str {
623+
self
624+
}
625+
}
626+
619627
////////////////////////////////////////////////////////////////////////////////
620628
// THE NO-ERROR ERROR TYPE
621629
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)