Skip to content

Commit

Permalink
Auto merge of rust-lang#81578 - jonas-schievink:rollup-yhiyowl, r=jon…
Browse files Browse the repository at this point in the history
…as-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
  • Loading branch information
bors committed Jan 31, 2021
2 parents b3897e3 + 8b281d9 commit 7850c28
Show file tree
Hide file tree
Showing 35 changed files with 284 additions and 118 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(no_crate_inject, attr(deny(warnings)))
)]
#![feature(array_value_iter_slice)]
#![feature(dropck_eyepatch)]
#![feature(new_uninit)]
#![feature(maybe_uninit_slice)]
#![feature(array_value_iter)]
#![cfg_attr(bootstrap, feature(min_const_generics))]
#![feature(min_specialization)]
#![cfg_attr(test, feature(test))]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
//! get confused if the spans from leaf AST nodes occur in multiple places
//! in the HIR, especially for multiple identifiers.

#![feature(array_value_iter)]
#![feature(crate_visibility_modifier)]
#![feature(or_patterns)]
#![recursion_limit = "256"]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html

#![feature(array_value_iter)]
#![feature(crate_visibility_modifier)]
#![feature(const_fn)] // For the unsizing cast on `&[]`
#![feature(const_panic)]
Expand Down
10 changes: 1 addition & 9 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,15 +1254,7 @@ impl<'a> Parser<'a> {
f: impl FnOnce(&mut Self) -> PResult<'a, (R, TrailingToken)>,
) -> PResult<'a, R> {
let start_token = (self.token.clone(), self.token_spacing);
let cursor_snapshot = TokenCursor {
frame: self.token_cursor.frame.clone(),
// We only ever capture tokens within our current frame,
// so we can just use an empty frame stack
stack: vec![],
desugar_doc_comments: self.token_cursor.desugar_doc_comments,
num_next_calls: self.token_cursor.num_next_calls,
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
};
let cursor_snapshot = self.token_cursor.clone();

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

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! This API is completely unstable and subject to change.

#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(drain_filter)]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ The types of top-level items, which never contain unbound type
variables, are stored directly into the `tcx` typeck_results.
N.B., a type variable is not the same thing as a type parameter. A
type variable is rather an "instance" of a type parameter: that is,
given a generic function `fn foo<T>(t: T)`: while checking the
type variable is an instance of a type parameter. That is,
given a generic function `fn foo<T>(t: T)`, while checking the
function `foo`, the type `ty_param(0)` refers to the type `T`, which
is treated in abstract. When `foo()` is called, however, `T` will be
is treated in abstract. However, when `foo()` is called, `T` will be
substituted for a fresh type variable `N`. This variable will
eventually be resolved to some concrete type (which might itself be
type parameter).
a type parameter).
*/

Expand Down
22 changes: 15 additions & 7 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
vec![(left, "(".to_string()), (right.shrink_to_hi(), ")".to_string())],
Applicability::MachineApplicable,
);
} else if fields.len() > subpats.len() {
let after_fields_span = if pat_span == DUMMY_SP {
pat_span
} else {
pat_span.with_hi(pat_span.hi() - BytePos(1)).shrink_to_hi()
};
} else if fields.len() > subpats.len() && pat_span != DUMMY_SP {
let after_fields_span = pat_span.with_hi(pat_span.hi() - BytePos(1)).shrink_to_hi();
let all_fields_span = match subpats {
[] => after_fields_span,
[field] => field.span,
Expand All @@ -1055,7 +1051,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Check if all the fields in the pattern are wildcards.
let all_wildcards = subpats.iter().all(|pat| matches!(pat.kind, PatKind::Wild));
let first_tail_wildcard =
subpats.iter().enumerate().fold(None, |acc, (pos, pat)| match (acc, &pat.kind) {
(None, PatKind::Wild) => Some(pos),
(Some(_), PatKind::Wild) => acc,
_ => None,
});
let tail_span = match first_tail_wildcard {
None => after_fields_span,
Some(0) => subpats[0].span.to(after_fields_span),
Some(pos) => subpats[pos - 1].span.shrink_to_hi().to(after_fields_span),
};

// FIXME: heuristic-based suggestion to check current types for where to add `_`.
let mut wildcard_sugg = vec!["_"; fields.len() - subpats.len()].join(", ");
if !subpats.is_empty() {
wildcard_sugg = String::from(", ") + &wildcard_sugg;
Expand All @@ -1080,7 +1088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
} else {
err.span_suggestion_verbose(
after_fields_span,
tail_span,
"use `..` to ignore the rest of the fields",
String::from(", .."),
Applicability::MaybeIncorrect,
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ The type checker is responsible for:
1. Determining the type of each expression.
2. Resolving methods and traits.
3. Guaranteeing that most type rules are met. ("Most?", you say, "why most?"
Well, dear reader, read on)
Well, dear reader, read on.)
The main entry point is `check_crate()`. Type checking operates in
The main entry point is [`check_crate()`]. Type checking operates in
several major phases:
1. The collect phase first passes over all items and determines their
Expand All @@ -25,7 +25,7 @@ several major phases:
containing function). Inference is used to supply types wherever
they are unknown. The actual checking of a function itself has
several phases (check, regionck, writeback), as discussed in the
documentation for the `check` module.
documentation for the [`check`] module.
The type checker is defined into various submodules which are documented
independently:
Expand Down Expand Up @@ -56,7 +56,6 @@ This API is completely unstable and subject to change.
*/

#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_value_iter)]
#![feature(bool_to_option)]
#![feature(box_syntax)]
#![feature(crate_visibility_modifier)]
Expand Down
33 changes: 33 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,39 @@ impl<A: Allocator> Box<dyn Any + Send, A> {
}
}

impl<A: Allocator> Box<dyn Any + Send + Sync, A> {
#[inline]
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
/// Attempt to downcast the box to a concrete type.
///
/// # Examples
///
/// ```
/// use std::any::Any;
///
/// fn print_if_string(value: Box<dyn Any + Send + Sync>) {
/// if let Ok(string) = value.downcast::<String>() {
/// println!("String ({}): {}", string.len(), string);
/// }
/// }
///
/// let my_string = "Hello World".to_string();
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// ```
pub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self> {
if self.is::<T>() {
unsafe {
let (raw, alloc): (*mut (dyn Any + Send + Sync), _) =
Box::into_raw_with_allocator(self);
Ok(Box::from_raw_in(raw as *mut T, alloc))
}
} else {
Err(self)
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Display + ?Sized, A: Allocator> fmt::Display for Box<T, A> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
#![feature(allocator_api)]
#![feature(array_chunks)]
#![feature(array_methods)]
#![feature(array_value_iter)]
#![feature(array_windows)]
#![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)]
Expand Down
18 changes: 7 additions & 11 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,13 @@ impl<T: ?Sized> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(arc_mutate_strong_count)]
///
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
///
/// unsafe {
/// let ptr = Arc::into_raw(five);
/// Arc::incr_strong_count(ptr);
/// Arc::increment_strong_count(ptr);
///
/// // This assertion is deterministic because we haven't shared
/// // the `Arc` between threads.
Expand All @@ -979,8 +977,8 @@ impl<T: ?Sized> Arc<T> {
/// }
/// ```
#[inline]
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
pub unsafe fn incr_strong_count(ptr: *const T) {
#[stable(feature = "arc_mutate_strong_count", since = "1.51.0")]
pub unsafe fn increment_strong_count(ptr: *const T) {
// Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
let arc = unsafe { mem::ManuallyDrop::new(Arc::<T>::from_raw(ptr)) };
// Now increase refcount, but don't drop new refcount either
Expand All @@ -1001,27 +999,25 @@ impl<T: ?Sized> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(arc_mutate_strong_count)]
///
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
///
/// unsafe {
/// let ptr = Arc::into_raw(five);
/// Arc::incr_strong_count(ptr);
/// Arc::increment_strong_count(ptr);
///
/// // Those assertions are deterministic because we haven't shared
/// // the `Arc` between threads.
/// let five = Arc::from_raw(ptr);
/// assert_eq!(2, Arc::strong_count(&five));
/// Arc::decr_strong_count(ptr);
/// Arc::decrement_strong_count(ptr);
/// assert_eq!(1, Arc::strong_count(&five));
/// }
/// ```
#[inline]
#[unstable(feature = "arc_mutate_strong_count", issue = "71983")]
pub unsafe fn decr_strong_count(ptr: *const T) {
#[stable(feature = "arc_mutate_strong_count", since = "1.51.0")]
pub unsafe fn decrement_strong_count(ptr: *const T) {
unsafe { mem::drop(Arc::from_raw(ptr)) };
}

Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
// Increment the reference count of the arc to clone it.
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
unsafe { Arc::incr_strong_count(waker as *const W) };
unsafe { Arc::increment_strong_count(waker as *const W) };
RawWaker::new(
waker as *const (),
&RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
Expand All @@ -83,7 +83,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {

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

RawWaker::new(
Expand Down
25 changes: 18 additions & 7 deletions library/core/src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
/// A by-value [array] iterator.
///
/// [array]: ../../std/primitive.array.html
#[unstable(feature = "array_value_iter", issue = "65798")]
#[stable(feature = "array_value_iter", since = "1.51.0")]
pub struct IntoIter<T, const N: usize> {
/// This is the array we are iterating over.
///
Expand All @@ -38,10 +38,21 @@ pub struct IntoIter<T, const N: usize> {
impl<T, const N: usize> IntoIter<T, N> {
/// Creates a new iterator over the given `array`.
///
/// *Note*: this method might never get stabilized and/or removed in the
/// future as there will likely be another, preferred way of obtaining this
/// iterator (either via `IntoIterator` for arrays or via another way).
#[unstable(feature = "array_value_iter", issue = "65798")]
/// *Note*: this method might be deprecated in the future,
/// after [`IntoIterator` is implemented for arrays][array-into-iter].
///
/// # Examples
///
/// ```
/// use std::array;
///
/// for value in array::IntoIter::new([1, 2, 3, 4, 5]) {
/// // The type of `value` is a `i32` here, instead of `&i32`
/// let _: i32 = value;
/// }
/// ```
/// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
#[stable(feature = "array_value_iter", since = "1.51.0")]
pub fn new(array: [T; N]) -> Self {
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`
// promise:
Expand Down Expand Up @@ -69,7 +80,7 @@ impl<T, const N: usize> IntoIter<T, N> {

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

/// Returns a mutable slice of all elements that have not been yielded yet.
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
#[stable(feature = "array_value_iter", since = "1.51.0")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
// SAFETY: We know that all elements within `alive` are properly initialized.
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::slice::{Iter, IterMut};

mod iter;

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

/// Converts a reference to `T` into a reference to an array of length 1 (without copying).
Expand Down
16 changes: 10 additions & 6 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ use self::Ordering::*;
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
/// so floating point types implement `PartialEq` but not [`trait@Eq`].
///
/// Formally, the equality must be (for all `a`, `b` and `c`):
/// Formally, the equality must be (for all `a`, `b`, `c` of type `A`, `B`,
/// `C`):
///
/// - symmetric: `a == b` implies `b == a`; and
/// - transitive: `a == b` and `b == c` implies `a == c`.
/// - **Symmetric**: if `A: PartialEq<B>` and `B: PartialEq<A>`, then **`a == b`
/// implies `b == a`**; and
///
/// - **Transitive**: if `A: PartialEq<B>` and `B: PartialEq<C>` and `A:
/// PartialEq<C>`, then **`a == b` and `b == c` implies `a == c`**.
///
/// Note that these requirements mean that the trait itself must be implemented
/// symmetrically and transitively: if `T: PartialEq<U>` and `U: PartialEq<V>`
/// then `U: PartialEq<T>` and `T: PartialEq<V>`.
/// Note that the `B: PartialEq<A>` (symmetric) and `A: PartialEq<C>`
/// (transitive) impls are not forced to exist, but these requirements apply
/// whenever they do exist.
///
/// ## Derivable
///
Expand Down
8 changes: 8 additions & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,14 @@ impl AsRef<str> for str {
}
}

#[stable(feature = "as_mut_str_for_str", since = "1.51.0")]
impl AsMut<str> for str {
#[inline]
fn as_mut(&mut self) -> &mut str {
self
}
}

////////////////////////////////////////////////////////////////////////////////
// THE NO-ERROR ERROR TYPE
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 7850c28

Please sign in to comment.