Skip to content

Commit

Permalink
Clean up: Applied x test tidy --bless. NOT COMPILABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lyons-kehl committed Dec 13, 2022
1 parent 6d87db2 commit 3847e14
Show file tree
Hide file tree
Showing 27 changed files with 828 additions and 347 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.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/mir/index.html
use core::alloc::GlobalCoAllocMeta;
use crate::mir::interpret::{
AllocRange, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, LitToConstInput, Scalar,
};
Expand All @@ -14,6 +13,7 @@ use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, DefIdTree, List, Ty, TyCtxt};
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
use core::alloc::GlobalCoAllocMeta;

use rustc_data_structures::captures::Captures;
use rustc_errors::ErrorGuaranteed;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
//! The intention is that this file only contains datatype declarations, no code.
use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection};
use core::alloc::GlobalCoAllocMeta;
use core::mem;
use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection};

use crate::mir::coverage::{CodeRegion, CoverageKind};
use crate::traits::Reveal;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
use core::alloc::GlobalCoAllocMeta;
use core::mem;
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream};
use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing};
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod stmt;
mod ty;

use crate::lexer::UnmatchedBrace;
use core::alloc::GlobalCoAllocMeta;
pub use attr_wrapper::AttrWrapper;
use core::alloc::GlobalCoAllocMeta;
pub use diagnostics::AttemptLocalParseRecovery;
pub(crate) use item::FnParseMode;
pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma};
Expand Down Expand Up @@ -169,7 +169,10 @@ pub struct Parser<'a> {
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure
// it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Parser<'_>, 336 + 4 * mem::size_of::<GlobalCoAllocMeta>());
rustc_data_structures::static_assert_size!(
Parser<'_>,
336 + 4 * mem::size_of::<GlobalCoAllocMeta>()
);

/// Stores span information about a closure.
#[derive(Clone)]
Expand Down
34 changes: 28 additions & 6 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,12 @@ impl<T> Box<[T]> {
Err(_) => return Err(AllocError),
};
let ptr = Global.allocate(layout)?;
Ok(RawVec::<T, Global, false>::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len))
Ok(RawVec::<T, Global, false>::from_raw_parts_in(
ptr.as_mut_ptr() as *mut _,
len,
Global,
)
.into_box(len))
}
}

Expand Down Expand Up @@ -732,13 +737,20 @@ impl<T> Box<[T]> {
Err(_) => return Err(AllocError),
};
let ptr = Global.allocate_zeroed(layout)?;
Ok(RawVec::<T, Global, false>::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len))
Ok(RawVec::<T, Global, false>::from_raw_parts_in(
ptr.as_mut_ptr() as *mut _,
len,
Global,
)
.into_box(len))
}
}
}

impl<T, A: Allocator> Box<[T], A>
where [(); core::alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); core::alloc::co_alloc_metadata_num_slots::<A>()]:,
{
/// Constructs a new boxed slice with uninitialized contents in the provided allocator.
///
/// # Examples
Expand Down Expand Up @@ -766,7 +778,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots::<A>()]: {
// #[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { RawVec::<T, A, {alloc::SHORT_TERM_VEC_PREFERS_COOP}>::with_capacity_in(len, alloc).into_box(len) }
unsafe {
RawVec::<T, A, { alloc::SHORT_TERM_VEC_PREFERS_COOP }>::with_capacity_in(len, alloc)
.into_box(len)
}
}

/// Constructs a new boxed slice with uninitialized contents in the provided allocator,
Expand Down Expand Up @@ -794,7 +809,12 @@ where [(); core::alloc::co_alloc_metadata_num_slots::<A>()]: {
// #[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
unsafe { RawVec::<T, A, {alloc::SHORT_TERM_VEC_PREFERS_COOP}>::with_capacity_zeroed_in(len, alloc).into_box(len) }
unsafe {
RawVec::<T, A, { alloc::SHORT_TERM_VEC_PREFERS_COOP }>::with_capacity_zeroed_in(
len, alloc,
)
.into_box(len)
}
}
}

Expand Down Expand Up @@ -2052,7 +2072,9 @@ impl<I> FromIterator<I> for Box<[I]> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_slice_clone", since = "1.3.0")]
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A>
where [(); core::alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); core::alloc::co_alloc_metadata_num_slots::<A>()]:,
{
fn clone(&self) -> Self {
let alloc = Box::allocator(self).clone();
self.to_vec_in(alloc).into_boxed_slice()
Expand Down
12 changes: 8 additions & 4 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@
#![allow(missing_docs)]
#![stable(feature = "rust1", since = "1.0.0")]

use core::{alloc, fmt};
use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen};
use core::mem::{self, swap, ManuallyDrop};
use core::ops::{Deref, DerefMut};
use core::ptr;
use core::{alloc, fmt};

use crate::alloc::Global;

Expand Down Expand Up @@ -1198,7 +1198,7 @@ impl<T> BinaryHeap<T> {
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<'_, T, {alloc::SHORT_TERM_VEC_PREFERS_COOP}> {
pub fn drain(&mut self) -> Drain<'_, T, { alloc::SHORT_TERM_VEC_PREFERS_COOP }> {
Drain { iter: self.data.drain(..) }
}

Expand Down Expand Up @@ -1479,13 +1479,17 @@ unsafe impl<T: Ord> TrustedLen for IntoIterSorted<T> {}
#[stable(feature = "drain", since = "1.6.0")]
#[derive(Debug)]
pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]: {
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
{
iter: vec::Drain<'a, T, Global, COOP_PREFERRED>,
}

#[stable(feature = "drain", since = "1.6.0")]
impl<T, const COOP_PREFERRED: bool> Iterator for Drain<'_, T, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]: {
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREFERRED)]:,
{
type Item = T;

#[inline]
Expand Down
77 changes: 55 additions & 22 deletions library/alloc/src/collections/vec_deque/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ pub struct Drain<
'a,
T: 'a,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP}
>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP },
> where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
// We can't just use a &mut VecDeque<T, A>, as that would make Drain invariant over T
// and we want it to be covariant instead
deque: NonNull<VecDeque<T, A, COOP_PREFERRED>>,
Expand All @@ -37,7 +38,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
}

impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
pub(super) unsafe fn new(
deque: &'a mut VecDeque<T, A, COOP_PREFERRED>,
drain_start: usize,
Expand Down Expand Up @@ -91,8 +94,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
}

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug, A: Allocator, const COOP_PREFERRED: bool> fmt::Debug for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
impl<T: fmt::Debug, A: Allocator, const COOP_PREFERRED: bool> fmt::Debug
for Drain<'_, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Drain")
.field(&self.drain_len)
Expand All @@ -104,21 +110,37 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
}

#[stable(feature = "drain", since = "1.6.0")]
unsafe impl<T: Sync, A: Allocator + Sync, const COOP_PREFERRED: bool> Sync for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {}
unsafe impl<T: Sync, A: Allocator + Sync, const COOP_PREFERRED: bool> Sync
for Drain<'_, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
}
#[stable(feature = "drain", since = "1.6.0")]
unsafe impl<T: Send, A: Allocator + Send, const COOP_PREFERRED: bool> Send for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {}
unsafe impl<T: Send, A: Allocator + Send, const COOP_PREFERRED: bool> Send
for Drain<'_, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
}

#[stable(feature = "drain", since = "1.6.0")]
impl<T, A: Allocator, const COOP_PREFERRED: bool> Drop for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
fn drop(&mut self) {
struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> (&'r mut Drain<'a, T, A, COOP_PREFERRED>)
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:;
struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>(
&'r mut Drain<'a, T, A, COOP_PREFERRED>,
)
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:;

impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop
for DropGuard<'r, 'a, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
fn drop(&mut self) {
if self.0.remaining != 0 {
unsafe {
Expand Down Expand Up @@ -200,7 +222,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE

#[stable(feature = "drain", since = "1.6.0")]
impl<T, A: Allocator, const COOP_PREFERRED: bool> Iterator for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
type Item = T;

#[inline]
Expand All @@ -222,8 +246,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
}

#[stable(feature = "drain", since = "1.6.0")]
impl<T, A: Allocator, const COOP_PREFERRED: bool> DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
impl<T, A: Allocator, const COOP_PREFERRED: bool> DoubleEndedIterator
for Drain<'_, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
#[inline]
fn next_back(&mut self) -> Option<T> {
if self.remaining == 0 {
Expand All @@ -236,9 +263,15 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRE
}

#[stable(feature = "drain", since = "1.6.0")]
impl<T, A: Allocator, const COOP_PREFERRED: bool> ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {}
impl<T, A: Allocator, const COOP_PREFERRED: bool> ExactSizeIterator
for Drain<'_, T, A, COOP_PREFERRED>
where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
}

#[stable(feature = "fused", since = "1.26.0")]
impl<T, A: Allocator, const COOP_PREFERRED: bool> FusedIterator for Drain<'_, T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {}
impl<T, A: Allocator, const COOP_PREFERRED: bool> FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:
{
}
41 changes: 28 additions & 13 deletions library/alloc/src/collections/vec_deque/into_iter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::{alloc, fmt};
use core::iter::{FusedIterator, TrustedLen};
use core::{alloc, fmt};

use crate::alloc::{Allocator, Global};

Expand All @@ -17,14 +17,17 @@ use super::VecDeque;
pub struct IntoIter<
T,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
const COOP_PREFERRED: bool = true
>
where [(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]: {
const COOP_PREFERRED: bool = true,
> where
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREFERRED)]:,
{
inner: VecDeque<T, A, COOP_PREFERRED>,
}

impl<T, A: Allocator, const COOP_PREFERRED: bool> IntoIter<T, A, COOP_PREFERRED>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:,
{
pub(super) fn new(inner: VecDeque<T, A, COOP_PREFERRED>) -> Self {
IntoIter { inner }
}
Expand All @@ -36,15 +39,19 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {

#[stable(feature = "collection_debug", since = "1.17.0")]
impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IntoIter").field(&self.inner).finish()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A: Allocator> Iterator for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:,
{
type Item = T;

#[inline]
Expand All @@ -61,7 +68,9 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:,
{
#[inline]
fn next_back(&mut self) -> Option<T> {
self.inner.pop_back()
Expand All @@ -70,16 +79,22 @@ where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A: Allocator> ExactSizeIterator for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {
where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:,
{
fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}

#[stable(feature = "fused", since = "1.26.0")]
impl<T, A: Allocator> FusedIterator for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {}
impl<T, A: Allocator> FusedIterator for IntoIter<T, A> where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:
{
}

#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A>
where [(); alloc::co_alloc_metadata_num_slots::<A>()]: {}
unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> where
[(); alloc::co_alloc_metadata_num_slots::<A>()]:
{
}
Loading

0 comments on commit 3847e14

Please # to comment.