Skip to content

Commit dfe0d21

Browse files
committedJul 8, 2023
Auto merge of #2971 - rust-lang:rustup2023-07-08, r=RalfJung
Automatic sync from rustc
·
1.87.01.73.0
2 parents 2323ecb + c182669 commit dfe0d21

File tree

116 files changed

+1049
-405
lines changed

Some content is hidden

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

116 files changed

+1049
-405
lines changed
 

‎compiler/rustc_abi/src/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait LayoutCalculator {
134134
scalar_valid_range: (Bound<u128>, Bound<u128>),
135135
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
136136
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
137-
niche_optimize_enum: bool,
137+
dont_niche_optimize_enum: bool,
138138
always_sized: bool,
139139
) -> Option<LayoutS> {
140140
let dl = self.current_data_layout();
@@ -183,10 +183,10 @@ pub trait LayoutCalculator {
183183
// (Typechecking will reject discriminant-sizing attrs.)
184184

185185
let v = present_first;
186-
let kind = if is_enum || variants[v].is_empty() {
186+
let kind = if is_enum || variants[v].is_empty() || always_sized {
187187
StructKind::AlwaysSized
188188
} else {
189-
if !always_sized { StructKind::MaybeUnsized } else { StructKind::AlwaysSized }
189+
StructKind::MaybeUnsized
190190
};
191191

192192
let mut st = self.univariant(dl, &variants[v], repr, kind)?;
@@ -280,7 +280,7 @@ pub trait LayoutCalculator {
280280
}
281281

282282
let calculate_niche_filling_layout = || -> Option<TmpLayout> {
283-
if niche_optimize_enum {
283+
if dont_niche_optimize_enum {
284284
return None;
285285
}
286286

‎compiler/rustc_ast/src/tokenstream.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2525
use rustc_span::{Span, DUMMY_SP};
2626
use smallvec::{smallvec, SmallVec};
2727

28-
use std::{fmt, iter};
28+
use std::{fmt, iter, mem};
2929

3030
/// When the main Rust parser encounters a syntax-extension invocation, it
3131
/// parses the arguments to the invocation as a token tree. This is a very
@@ -410,8 +410,17 @@ impl TokenStream {
410410
t1.next().is_none() && t2.next().is_none()
411411
}
412412

413-
pub fn map_enumerated<F: FnMut(usize, &TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream {
414-
TokenStream(Lrc::new(self.0.iter().enumerate().map(|(i, tree)| f(i, tree)).collect()))
413+
/// Applies the supplied function to each `TokenTree` and its index in `self`, returning a new `TokenStream`
414+
///
415+
/// It is equivalent to `TokenStream::new(self.trees().cloned().enumerate().map(|(i, tt)| f(i, tt)).collect())`.
416+
pub fn map_enumerated_owned(
417+
mut self,
418+
mut f: impl FnMut(usize, TokenTree) -> TokenTree,
419+
) -> TokenStream {
420+
let owned = Lrc::make_mut(&mut self.0); // clone if necessary
421+
// rely on vec's in-place optimizations to avoid another allocation
422+
*owned = mem::take(owned).into_iter().enumerate().map(|(i, tree)| f(i, tree)).collect();
423+
self
415424
}
416425

417426
/// Create a token stream containing a single token with alone spacing.

0 commit comments

Comments
 (0)
Please sign in to comment.