Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! This API is completely unstable and subject to change.
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(array_windows))]
#![doc(test(attr(deny(warnings), allow(internal_features))))]
#![feature(array_windows)]
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#![allow(internal_features)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![deny(unsafe_op_in_unsafe_fn)]
#![feature(allocator_api)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(ascii_char_variants)]
#![feature(assert_matches)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::direct_use_of_rustc_type_ir)]
#![allow(rustc::untranslatable_diagnostic)]
#![feature(array_windows)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(assert_matches)]
#![feature(associated_type_defaults)]
#![feature(box_patterns)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![feature(array_windows)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(associated_type_defaults)]
#![feature(if_let_guard)]
#![feature(macro_metavar_expr)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![feature(array_windows)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::direct_use_of_rustc_type_ir)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(allocator_api)]
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(associated_type_defaults)]
#![feature(box_as_ptr)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ define_helper!(
///
/// Overrides `with_crate_prefix`.
// This function is not currently used in-tree, but it's used by a downstream rustc-driver in
// This function is used by `rustc_public` and downstream rustc-driver in
// Ferrocene. Please check with them before removing it.
fn with_resolve_crate_name(CrateNamePrefixGuard, SHOULD_PREFIX_WITH_CRATE_NAME);
/// Adds the `crate::` prefix to paths where appropriate.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tidy-alphabetical-start
#![feature(array_windows)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(const_type_name)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_monomorphize/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tidy-alphabetical-start
#![feature(array_windows)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![feature(file_buffered)]
#![feature(if_let_guard)]
#![feature(impl_trait_in_assoc_type)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_public/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl CrateItem {
pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
self.body()
.ok_or_else(|| io::Error::other(format!("No body found for `{}`", self.name())))?
.dump(w, &self.name())
.dump(w, &self.trimmed_name())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_public/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ fn pretty_aggregate<W: Write>(
}
AggregateKind::Adt(def, var, _, _, _) => {
if def.kind() == AdtKind::Enum {
write!(writer, "{}::{}", def.name(), def.variant(*var).unwrap().name())?;
write!(writer, "{}::{}", def.trimmed_name(), def.variant(*var).unwrap().name())?;
} else {
write!(writer, "{}", def.variant(*var).unwrap().name())?;
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_public/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ pub struct VariantDef {
}

impl VariantDef {
/// The name of the variant, struct or union.
///
/// This will not include the name of the enum or qualified path.
pub fn name(&self) -> Symbol {
with(|cx| cx.variant_name(*self))
}
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_public_bridge/src/context/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use rustc_hir::{Attribute, LangItem};
use rustc_middle::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, GlobalAlloc, Scalar};
use rustc_middle::mir::{BinOp, Body, Const as MirConst, ConstValue, UnOp};
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
use rustc_middle::ty::print::{
with_forced_trimmed_paths, with_no_trimmed_paths, with_resolve_crate_name,
};
use rustc_middle::ty::util::Discr;
use rustc_middle::ty::{
AdtDef, AdtKind, AssocItem, Binder, ClosureKind, CoroutineArgsExt, EarlyBinder,
Expand Down Expand Up @@ -264,7 +266,8 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> {
if trimmed {
with_forced_trimmed_paths!(self.tcx.def_path_str(def_id))
} else {
with_no_trimmed_paths!(self.tcx.def_path_str(def_id))
// For local definitions, we need to prepend with crate name.
with_resolve_crate_name!(with_no_trimmed_paths!(self.tcx.def_path_str(def_id)))
}
}

Expand Down Expand Up @@ -724,9 +727,9 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> {
self.tcx.def_path_str_with_args(instance.def_id(), instance.args)
)
} else {
with_no_trimmed_paths!(
with_resolve_crate_name!(with_no_trimmed_paths!(
self.tcx.def_path_str_with_args(instance.def_id(), instance.args)
)
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(array_windows))]
#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
#![feature(array_windows)]
#![feature(cfg_select)]
#![feature(core_io_borrowed_buf)]
#![feature(if_let_guard)]
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 @@ -89,7 +89,6 @@
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(array_into_iter_constructors)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(assert_matches)]
#![feature(async_fn_traits)]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::cmp::Ordering::{self, Less};
use core::mem::MaybeUninit;
#[cfg(not(no_global_oom_handling))]
use core::ptr;
#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
pub use core::slice::ArrayWindows;
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]
pub use core::slice::EscapeAscii;
Expand Down
55 changes: 55 additions & 0 deletions library/core/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,58 @@ where
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
}
}

#[unstable(feature = "allocator_api", issue = "32838")]
unsafe impl<A> Allocator for &mut A
where
A: Allocator + ?Sized,
{
#[inline]
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
(**self).allocate(layout)
}

#[inline]
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
(**self).allocate_zeroed(layout)
}

#[inline]
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
// SAFETY: the safety contract must be upheld by the caller
unsafe { (**self).deallocate(ptr, layout) }
}

#[inline]
unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
// SAFETY: the safety contract must be upheld by the caller
unsafe { (**self).grow(ptr, old_layout, new_layout) }
}

#[inline]
unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
// SAFETY: the safety contract must be upheld by the caller
unsafe { (**self).grow_zeroed(ptr, old_layout, new_layout) }
}

#[inline]
unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError> {
// SAFETY: the safety contract must be upheld by the caller
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
}
}
60 changes: 60 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,30 @@ impl<T> Option<T> {
}
}

impl<T: IntoIterator> Option<T> {
/// Transforms an optional iterator into an iterator.
///
/// If `self` is `None`, the resulting iterator is empty.
/// Otherwise, an iterator is made from the `Some` value and returned.
/// # Examples
/// ```
/// #![feature(option_into_flat_iter)]
///
/// let o1 = Some([1, 2]);
/// let o2 = None::<&[usize]>;
///
/// assert_eq!(o1.into_flat_iter().collect::<Vec<_>>(), [1, 2]);
/// assert_eq!(o2.into_flat_iter().collect::<Vec<_>>(), Vec::<&usize>::new());
/// ```
#[unstable(feature = "option_into_flat_iter", issue = "148441")]
pub fn into_flat_iter<A>(self) -> OptionFlatten<A>
where
T: IntoIterator<IntoIter = A>,
{
OptionFlatten { iter: self.map(IntoIterator::into_iter) }
}
}

impl<T, U> Option<(T, U)> {
/// Unzips an option containing a tuple of two options.
///
Expand Down Expand Up @@ -2575,6 +2599,42 @@ impl<A> FusedIterator for IntoIter<A> {}
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<A> TrustedLen for IntoIter<A> {}

/// The iterator produced by [`Option::into_flat_iter`]. See its documentation for more.
#[derive(Clone, Debug)]
#[unstable(feature = "option_into_flat_iter", issue = "148441")]
pub struct OptionFlatten<A> {
iter: Option<A>,
}

#[unstable(feature = "option_into_flat_iter", issue = "148441")]
impl<A: Iterator> Iterator for OptionFlatten<A> {
type Item = A::Item;

fn next(&mut self) -> Option<Self::Item> {
self.iter.as_mut()?.next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.as_ref().map(|i| i.size_hint()).unwrap_or((0, Some(0)))
}
}

#[unstable(feature = "option_into_flat_iter", issue = "148441")]
impl<A: DoubleEndedIterator> DoubleEndedIterator for OptionFlatten<A> {
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.as_mut()?.next_back()
}
}

#[unstable(feature = "option_into_flat_iter", issue = "148441")]
impl<A: ExactSizeIterator> ExactSizeIterator for OptionFlatten<A> {}

#[unstable(feature = "option_into_flat_iter", issue = "148441")]
impl<A: FusedIterator> FusedIterator for OptionFlatten<A> {}

#[unstable(feature = "option_into_flat_iter", issue = "148441")]
unsafe impl<A: TrustedLen> TrustedLen for OptionFlatten<A> {}

/////////////////////////////////////////////////////////////////////////////
// FromIterator
/////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 4 additions & 6 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2165,8 +2165,6 @@ unsafe impl<T> Sync for ChunksExactMut<'_, T> where T: Sync {}
/// # Example
///
/// ```
/// #![feature(array_windows)]
///
/// let slice = [0, 1, 2, 3];
/// let mut iter = slice.array_windows::<2>();
/// assert_eq!(iter.next(), Some(&[0, 1]));
Expand All @@ -2178,7 +2176,7 @@ unsafe impl<T> Sync for ChunksExactMut<'_, T> where T: Sync {}
/// [`array_windows`]: slice::array_windows
/// [slices]: slice
#[derive(Debug, Clone, Copy)]
#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ArrayWindows<'a, T: 'a, const N: usize> {
v: &'a [T],
Expand All @@ -2191,7 +2189,7 @@ impl<'a, T: 'a, const N: usize> ArrayWindows<'a, T, N> {
}
}

#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
impl<'a, T, const N: usize> Iterator for ArrayWindows<'a, T, N> {
type Item = &'a [T; N];

Expand Down Expand Up @@ -2228,7 +2226,7 @@ impl<'a, T, const N: usize> Iterator for ArrayWindows<'a, T, N> {
}
}

#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
impl<'a, T, const N: usize> DoubleEndedIterator for ArrayWindows<'a, T, N> {
#[inline]
fn next_back(&mut self) -> Option<&'a [T; N]> {
Expand All @@ -2247,7 +2245,7 @@ impl<'a, T, const N: usize> DoubleEndedIterator for ArrayWindows<'a, T, N> {
}
}

#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
fn is_empty(&self) -> bool {
self.v.len() < N
Expand Down
12 changes: 7 additions & 5 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub use ascii::is_ascii_simple;
pub use index::SliceIndex;
#[unstable(feature = "slice_range", issue = "76393")]
pub use index::{range, try_range};
#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
pub use iter::ArrayWindows;
#[stable(feature = "slice_group_by", since = "1.77.0")]
pub use iter::{ChunkBy, ChunkByMut};
Expand Down Expand Up @@ -1620,13 +1620,15 @@ impl<T> [T] {
///
/// # Panics
///
/// Panics if `N` is zero. This check will most probably get changed to a compile time
/// error before this method gets stabilized.
/// Panics if `N` is zero.
///
/// Note that this check is against a const generic parameter, not a runtime
/// value, and thus a particular monomorphization will either always panic
/// or it will never panic.
///
/// # Examples
///
/// ```
/// #![feature(array_windows)]
/// let slice = [0, 1, 2, 3];
/// let mut iter = slice.array_windows();
/// assert_eq!(iter.next().unwrap(), &[0, 1]);
Expand All @@ -1636,7 +1638,7 @@ impl<T> [T] {
/// ```
///
/// [`windows`]: slice::windows
#[unstable(feature = "array_windows", issue = "75027")]
#[stable(feature = "array_windows", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
#[track_caller]
Expand Down
1 change: 0 additions & 1 deletion library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(array_ptr_get)]
#![feature(array_try_from_fn)]
#![feature(array_try_map)]
#![feature(array_windows)]
#![feature(ascii_char)]
#![feature(ascii_char_variants)]
#![feature(async_iter_from_iter)]
Expand Down
Loading
Loading