Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ca92de

Browse files
committedJul 7, 2024
Auto merge of #127454 - matthiaskrgr:rollup-k3vfen2, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #127179 (Print `TypeId` as hex for debugging) - #127189 (LinkedList's Cursor: method to get a ref to the cursor's list) - #127236 (doc: update config file path in platform-support/wasm32-wasip1-threads.md) - #127297 (Improve std::Path's Hash quality by avoiding prefix collisions) - #127308 (Attribute cleanups) - #127354 (Describe Sized requirements for mem::offset_of) - #127409 (Emit a wrap expr span_bug only if context is not tainted) - #127447 (once_lock: make test not take as long in Miri) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 959a2eb + b564c51 commit 0ca92de

File tree

22 files changed

+190
-134
lines changed

22 files changed

+190
-134
lines changed
 

‎compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use crate::{AssocItem, Expr, ForeignItem, Item, NodeId};
1010
use crate::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
1111
use crate::{AttrVec, Attribute, Stmt, StmtKind};
1212

13-
use rustc_span::Span;
14-
1513
use std::fmt;
1614
use std::marker::PhantomData;
1715

@@ -91,37 +89,6 @@ impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {
9189
}
9290
}
9391

94-
/// A trait for AST nodes having a span.
95-
pub trait HasSpan {
96-
fn span(&self) -> Span;
97-
}
98-
99-
macro_rules! impl_has_span {
100-
($($T:ty),+ $(,)?) => {
101-
$(
102-
impl HasSpan for $T {
103-
fn span(&self) -> Span {
104-
self.span
105-
}
106-
}
107-
)+
108-
};
109-
}
110-
111-
impl_has_span!(AssocItem, Block, Expr, ForeignItem, Item, Pat, Path, Stmt, Ty, Visibility);
112-
113-
impl<T: AstDeref<Target: HasSpan>> HasSpan for T {
114-
fn span(&self) -> Span {
115-
self.ast_deref().span()
116-
}
117-
}
118-
119-
impl HasSpan for AttrItem {
120-
fn span(&self) -> Span {
121-
self.span()
122-
}
123-
}
124-
12592
/// A trait for AST nodes having (or not having) collected tokens.
12693
pub trait HasTokens {
12794
fn tokens(&self) -> Option<&LazyAttrTokenStream>;

‎compiler/rustc_ast/src/attr/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ impl Attribute {
202202
}
203203
}
204204

205-
pub fn tokens(&self) -> TokenStream {
205+
// Named `get_tokens` to distinguish it from the `<Attribute as HasTokens>::tokens` method.
206+
pub fn get_tokens(&self) -> TokenStream {
206207
match &self.kind {
207208
AttrKind::Normal(normal) => TokenStream::new(
208209
normal

‎compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod tokenstream;
4444
pub mod visit;
4545

4646
pub use self::ast::*;
47-
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasSpan, HasTokens};
47+
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
4848

4949
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5050

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ fn visit_attr_tt<T: MutVisitor>(tt: &mut AttrTokenTree, vis: &mut T) {
704704
visit_attr_tts(tts, vis);
705705
visit_delim_span(dspan, vis);
706706
}
707-
AttrTokenTree::Attributes(AttributesData { attrs, tokens }) => {
707+
AttrTokenTree::AttrsTarget(AttrsTarget { attrs, tokens }) => {
708708
visit_attrs(attrs, vis);
709709
visit_lazy_tts_opt_mut(Some(tokens), vis);
710710
}

‎compiler/rustc_ast/src/tokenstream.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! ownership of the original.
1515
1616
use crate::ast::{AttrStyle, StmtKind};
17-
use crate::ast_traits::{HasAttrs, HasSpan, HasTokens};
17+
use crate::ast_traits::{HasAttrs, HasTokens};
1818
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
1919
use crate::AttrVec;
2020

@@ -170,8 +170,8 @@ pub enum AttrTokenTree {
170170
Delimited(DelimSpan, DelimSpacing, Delimiter, AttrTokenStream),
171171
/// Stores the attributes for an attribute target,
172172
/// along with the tokens for that attribute target.
173-
/// See `AttributesData` for more information
174-
Attributes(AttributesData),
173+
/// See `AttrsTarget` for more information
174+
AttrsTarget(AttrsTarget),
175175
}
176176

177177
impl AttrTokenStream {
@@ -180,7 +180,7 @@ impl AttrTokenStream {
180180
}
181181

182182
/// Converts this `AttrTokenStream` to a plain `Vec<TokenTree>`.
183-
/// During conversion, `AttrTokenTree::Attributes` get 'flattened'
183+
/// During conversion, `AttrTokenTree::AttrsTarget` get 'flattened'
184184
/// back to a `TokenStream` of the form `outer_attr attr_target`.
185185
/// If there are inner attributes, they are inserted into the proper
186186
/// place in the attribute target tokens.
@@ -199,13 +199,13 @@ impl AttrTokenStream {
199199
TokenStream::new(stream.to_token_trees()),
200200
))
201201
}
202-
AttrTokenTree::Attributes(data) => {
203-
let idx = data
202+
AttrTokenTree::AttrsTarget(target) => {
203+
let idx = target
204204
.attrs
205205
.partition_point(|attr| matches!(attr.style, crate::AttrStyle::Outer));
206-
let (outer_attrs, inner_attrs) = data.attrs.split_at(idx);
206+
let (outer_attrs, inner_attrs) = target.attrs.split_at(idx);
207207

208-
let mut target_tokens = data.tokens.to_attr_token_stream().to_token_trees();
208+
let mut target_tokens = target.tokens.to_attr_token_stream().to_token_trees();
209209
if !inner_attrs.is_empty() {
210210
let mut found = false;
211211
// Check the last two trees (to account for a trailing semi)
@@ -227,7 +227,7 @@ impl AttrTokenStream {
227227

228228
let mut stream = TokenStream::default();
229229
for inner_attr in inner_attrs {
230-
stream.push_stream(inner_attr.tokens());
230+
stream.push_stream(inner_attr.get_tokens());
231231
}
232232
stream.push_stream(delim_tokens.clone());
233233
*tree = TokenTree::Delimited(*span, *spacing, *delim, stream);
@@ -242,7 +242,7 @@ impl AttrTokenStream {
242242
);
243243
}
244244
for attr in outer_attrs {
245-
res.extend(attr.tokens().0.iter().cloned());
245+
res.extend(attr.get_tokens().0.iter().cloned());
246246
}
247247
res.extend(target_tokens);
248248
}
@@ -262,7 +262,7 @@ impl AttrTokenStream {
262262
/// have an `attrs` field containing the `#[cfg(FALSE)]` attr,
263263
/// and a `tokens` field storing the (unparsed) tokens `struct Foo {}`
264264
#[derive(Clone, Debug, Encodable, Decodable)]
265-
pub struct AttributesData {
265+
pub struct AttrsTarget {
266266
/// Attributes, both outer and inner.
267267
/// These are stored in the original order that they were parsed in.
268268
pub attrs: AttrVec,
@@ -436,17 +436,17 @@ impl TokenStream {
436436
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
437437
}
438438

439-
pub fn from_ast(node: &(impl HasAttrs + HasSpan + HasTokens + fmt::Debug)) -> TokenStream {
439+
pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
440440
let Some(tokens) = node.tokens() else {
441-
panic!("missing tokens for node at {:?}: {:?}", node.span(), node);
441+
panic!("missing tokens for node: {:?}", node);
442442
};
443443
let attrs = node.attrs();
444444
let attr_stream = if attrs.is_empty() {
445445
tokens.to_attr_token_stream()
446446
} else {
447-
let attr_data =
448-
AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
449-
AttrTokenStream::new(vec![AttrTokenTree::Attributes(attr_data)])
447+
let target =
448+
AttrsTarget { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
449+
AttrTokenStream::new(vec![AttrTokenTree::AttrsTarget(target)])
450450
};
451451
TokenStream::new(attr_stream.to_token_trees())
452452
}
@@ -765,6 +765,7 @@ mod size_asserts {
765765
static_assert_size!(AttrTokenStream, 8);
766766
static_assert_size!(AttrTokenTree, 32);
767767
static_assert_size!(LazyAttrTokenStream, 8);
768+
static_assert_size!(Option<LazyAttrTokenStream>, 8); // must be small, used in many AST nodes
768769
static_assert_size!(TokenStream, 8);
769770
static_assert_size!(TokenTree, 32);
770771
// tidy-alphabetical-end

‎compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl CfgEval<'_> {
193193

194194
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
195195
// to the captured `AttrTokenStream` (specifically, we capture
196-
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
196+
// `AttrTokenTree::AttrsTarget` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
197197
let mut parser = Parser::new(&self.0.sess.psess, orig_tokens, None);
198198
parser.capture_cfg = true;
199199
match parse_annotatable_with(&mut parser) {

‎compiler/rustc_expand/src/config.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> StripUnconfigured<'a> {
172172
fn configure_tokens(&self, stream: &AttrTokenStream) -> AttrTokenStream {
173173
fn can_skip(stream: &AttrTokenStream) -> bool {
174174
stream.0.iter().all(|tree| match tree {
175-
AttrTokenTree::Attributes(_) => false,
175+
AttrTokenTree::AttrsTarget(_) => false,
176176
AttrTokenTree::Token(..) => true,
177177
AttrTokenTree::Delimited(.., inner) => can_skip(inner),
178178
})
@@ -185,22 +185,22 @@ impl<'a> StripUnconfigured<'a> {
185185
let trees: Vec<_> = stream
186186
.0
187187
.iter()
188-
.flat_map(|tree| match tree.clone() {
189-
AttrTokenTree::Attributes(mut data) => {
190-
data.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
188+
.filter_map(|tree| match tree.clone() {
189+
AttrTokenTree::AttrsTarget(mut target) => {
190+
target.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));
191191

192-
if self.in_cfg(&data.attrs) {
193-
data.tokens = LazyAttrTokenStream::new(
194-
self.configure_tokens(&data.tokens.to_attr_token_stream()),
192+
if self.in_cfg(&target.attrs) {
193+
target.tokens = LazyAttrTokenStream::new(
194+
self.configure_tokens(&target.tokens.to_attr_token_stream()),
195195
);
196-
Some(AttrTokenTree::Attributes(data)).into_iter()
196+
Some(AttrTokenTree::AttrsTarget(target))
197197
} else {
198-
None.into_iter()
198+
None
199199
}
200200
}
201201
AttrTokenTree::Delimited(sp, spacing, delim, mut inner) => {
202202
inner = self.configure_tokens(&inner);
203-
Some(AttrTokenTree::Delimited(sp, spacing, delim, inner)).into_iter()
203+
Some(AttrTokenTree::Delimited(sp, spacing, delim, inner))
204204
}
205205
AttrTokenTree::Token(
206206
Token {
@@ -220,9 +220,7 @@ impl<'a> StripUnconfigured<'a> {
220220
) => {
221221
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tree);
222222
}
223-
AttrTokenTree::Token(token, spacing) => {
224-
Some(AttrTokenTree::Token(token, spacing)).into_iter()
225-
}
223+
AttrTokenTree::Token(token, spacing) => Some(AttrTokenTree::Token(token, spacing)),
226224
})
227225
.collect();
228226
AttrTokenStream::new(trees)
@@ -294,7 +292,7 @@ impl<'a> StripUnconfigured<'a> {
294292
attr: &Attribute,
295293
(item, item_span): (ast::AttrItem, Span),
296294
) -> Attribute {
297-
let orig_tokens = attr.tokens();
295+
let orig_tokens = attr.get_tokens();
298296

299297
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
300298
// and producing an attribute of the form `#[attr]`. We
@@ -310,12 +308,11 @@ impl<'a> StripUnconfigured<'a> {
310308
else {
311309
panic!("Bad tokens for attribute {attr:?}");
312310
};
313-
let pound_span = pound_token.span;
314311

315312
// We don't really have a good span to use for the synthesized `[]`
316313
// in `#[attr]`, so just use the span of the `#` token.
317314
let bracket_group = AttrTokenTree::Delimited(
318-
DelimSpan::from_single(pound_span),
315+
DelimSpan::from_single(pound_token.span),
319316
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
320317
Delimiter::Bracket,
321318
item.tokens

‎compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
734734
// struct; however, when EUV is run during typeck, it
735735
// may not. This will generate an error earlier in typeck,
736736
// so we can just ignore it.
737-
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
737+
if self.cx.tainted_by_errors().is_ok() {
738+
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
739+
}
738740
}
739741
}
740742

‎compiler/rustc_parse/src/parser/attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'a> Parser<'a> {
282282
pub fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> {
283283
let mut attrs = ast::AttrVec::new();
284284
loop {
285-
let start_pos: u32 = self.num_bump_calls.try_into().unwrap();
285+
let start_pos = self.num_bump_calls;
286286
// Only try to parse if it is an inner attribute (has `!`).
287287
let attr = if self.check(&token::Pound) && self.look_ahead(1, |t| t == &token::Not) {
288288
Some(self.parse_attribute(InnerAttrPolicy::Permitted)?)
@@ -303,7 +303,7 @@ impl<'a> Parser<'a> {
303303
None
304304
};
305305
if let Some(attr) = attr {
306-
let end_pos: u32 = self.num_bump_calls.try_into().unwrap();
306+
let end_pos = self.num_bump_calls;
307307
// If we are currently capturing tokens, mark the location of this inner attribute.
308308
// If capturing ends up creating a `LazyAttrTokenStream`, we will include
309309
// this replace range with it, removing the inner attribute from the final
@@ -313,7 +313,7 @@ impl<'a> Parser<'a> {
313313
// corresponding macro).
314314
let range = start_pos..end_pos;
315315
if let Capturing::Yes = self.capture_state.capturing {
316-
self.capture_state.inner_attr_ranges.insert(attr.id, (range, vec![]));
316+
self.capture_state.inner_attr_ranges.insert(attr.id, (range, None));
317317
}
318318
attrs.push(attr);
319319
} else {

‎compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
22
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
3-
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, AttributesData, DelimSpacing};
3+
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, AttrsTarget, DelimSpacing};
44
use rustc_ast::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, ToAttrTokenStream};
55
use rustc_ast::{self as ast};
66
use rustc_ast::{AttrVec, Attribute, HasAttrs, HasTokens};
77
use rustc_errors::PResult;
88
use rustc_session::parse::ParseSess;
99
use rustc_span::{sym, Span, DUMMY_SP};
1010

11-
use std::ops::Range;
1211
use std::{iter, mem};
1312

1413
/// A wrapper type to ensure that the parser handles outer attributes correctly.
@@ -88,7 +87,6 @@ fn has_cfg_or_cfg_attr(attrs: &[Attribute]) -> bool {
8887
//
8988
// This also makes `Parser` very cheap to clone, since
9089
// there is no intermediate collection buffer to clone.
91-
#[derive(Clone)]
9290
struct LazyAttrTokenStreamImpl {
9391
start_token: (Token, Spacing),
9492
cursor_snapshot: TokenCursor,
@@ -146,24 +144,23 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
146144
// start position, we ensure that any replace range which encloses
147145
// another replace range will capture the *replaced* tokens for the inner
148146
// range, not the original tokens.
149-
for (range, new_tokens) in replace_ranges.into_iter().rev() {
147+
for (range, target) in replace_ranges.into_iter().rev() {
150148
assert!(!range.is_empty(), "Cannot replace an empty range: {range:?}");
151-
// Replace ranges are only allowed to decrease the number of tokens.
152-
assert!(
153-
range.len() >= new_tokens.len(),
154-
"Range {range:?} has greater len than {new_tokens:?}"
155-
);
156-
157-
// Replace any removed tokens with `FlatToken::Empty`.
158-
// This keeps the total length of `tokens` constant throughout the
159-
// replacement process, allowing us to use all of the `ReplaceRanges` entries
160-
// without adjusting indices.
161-
let filler = iter::repeat((FlatToken::Empty, Spacing::Alone))
162-
.take(range.len() - new_tokens.len());
163149

150+
// Replace the tokens in range with zero or one `FlatToken::AttrsTarget`s, plus
151+
// enough `FlatToken::Empty`s to fill up the rest of the range. This keeps the
152+
// total length of `tokens` constant throughout the replacement process, allowing
153+
// us to use all of the `ReplaceRanges` entries without adjusting indices.
154+
let target_len = target.is_some() as usize;
164155
tokens.splice(
165156
(range.start as usize)..(range.end as usize),
166-
new_tokens.into_iter().chain(filler),
157+
target
158+
.into_iter()
159+
.map(|target| (FlatToken::AttrsTarget(target), Spacing::Alone))
160+
.chain(
161+
iter::repeat((FlatToken::Empty, Spacing::Alone))
162+
.take(range.len() - target_len),
163+
),
167164
);
168165
}
169166
make_attr_token_stream(tokens.into_iter(), self.break_last_token)
@@ -316,7 +313,7 @@ impl<'a> Parser<'a> {
316313
.iter()
317314
.cloned()
318315
.chain(inner_attr_replace_ranges.iter().cloned())
319-
.map(|(range, tokens)| ((range.start - start_pos)..(range.end - start_pos), tokens))
316+
.map(|(range, data)| ((range.start - start_pos)..(range.end - start_pos), data))
320317
.collect()
321318
};
322319

@@ -346,18 +343,14 @@ impl<'a> Parser<'a> {
346343
&& matches!(self.capture_state.capturing, Capturing::Yes)
347344
&& has_cfg_or_cfg_attr(final_attrs)
348345
{
349-
let attr_data = AttributesData { attrs: final_attrs.iter().cloned().collect(), tokens };
346+
assert!(!self.break_last_token, "Should not have unglued last token with cfg attr");
350347

351-
// Replace the entire AST node that we just parsed, including attributes,
352-
// with a `FlatToken::AttrTarget`. If this AST node is inside an item
353-
// that has `#[derive]`, then this will allow us to cfg-expand this
354-
// AST node.
348+
// Replace the entire AST node that we just parsed, including attributes, with
349+
// `target`. If this AST node is inside an item that has `#[derive]`, then this will
350+
// allow us to cfg-expand this AST node.
355351
let start_pos = if has_outer_attrs { attrs.start_pos } else { start_pos };
356-
let new_tokens = vec![(FlatToken::AttrTarget(attr_data), Spacing::Alone)];
357-
358-
assert!(!self.break_last_token, "Should not have unglued last token with cfg attr");
359-
let range: Range<u32> = (start_pos.try_into().unwrap())..(end_pos.try_into().unwrap());
360-
self.capture_state.replace_ranges.push((range, new_tokens));
352+
let target = AttrsTarget { attrs: final_attrs.iter().cloned().collect(), tokens };
353+
self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
361354
self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
362355
}
363356

@@ -419,11 +412,11 @@ fn make_attr_token_stream(
419412
.expect("Bottom token frame is missing!")
420413
.inner
421414
.push(AttrTokenTree::Token(token, spacing)),
422-
FlatToken::AttrTarget(data) => stack
415+
FlatToken::AttrsTarget(target) => stack
423416
.last_mut()
424417
.expect("Bottom token frame is missing!")
425418
.inner
426-
.push(AttrTokenTree::Attributes(data)),
419+
.push(AttrTokenTree::AttrsTarget(target)),
427420
FlatToken::Empty => {}
428421
}
429422
token_and_spacing = iter.next();

‎compiler/rustc_parse/src/parser/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use path::PathStyle;
2020

2121
use rustc_ast::ptr::P;
2222
use rustc_ast::token::{self, Delimiter, IdentIsRaw, Nonterminal, Token, TokenKind};
23-
use rustc_ast::tokenstream::{AttributesData, DelimSpacing, DelimSpan, Spacing};
23+
use rustc_ast::tokenstream::{AttrsTarget, DelimSpacing, DelimSpan, Spacing};
2424
use rustc_ast::tokenstream::{TokenStream, TokenTree, TokenTreeCursor};
2525
use rustc_ast::util::case::Case;
2626
use rustc_ast::{
@@ -203,13 +203,13 @@ struct ClosureSpans {
203203
}
204204

205205
/// Indicates a range of tokens that should be replaced by
206-
/// the tokens in the provided vector. This is used in two
206+
/// the tokens in the provided `AttrsTarget`. This is used in two
207207
/// places during token collection:
208208
///
209209
/// 1. During the parsing of an AST node that may have a `#[derive]`
210210
/// attribute, we parse a nested AST node that has `#[cfg]` or `#[cfg_attr]`
211211
/// In this case, we use a `ReplaceRange` to replace the entire inner AST node
212-
/// with `FlatToken::AttrTarget`, allowing us to perform eager cfg-expansion
212+
/// with `FlatToken::AttrsTarget`, allowing us to perform eager cfg-expansion
213213
/// on an `AttrTokenStream`.
214214
///
215215
/// 2. When we parse an inner attribute while collecting tokens. We
@@ -219,7 +219,7 @@ struct ClosureSpans {
219219
/// the first macro inner attribute to invoke a proc-macro).
220220
/// When create a `TokenStream`, the inner attributes get inserted
221221
/// into the proper place in the token stream.
222-
type ReplaceRange = (Range<u32>, Vec<(FlatToken, Spacing)>);
222+
type ReplaceRange = (Range<u32>, Option<AttrsTarget>);
223223

224224
/// Controls how we capture tokens. Capturing can be expensive,
225225
/// so we try to avoid performing capturing in cases where
@@ -1608,11 +1608,10 @@ enum FlatToken {
16081608
/// A token - this holds both delimiter (e.g. '{' and '}')
16091609
/// and non-delimiter tokens
16101610
Token(Token),
1611-
/// Holds the `AttributesData` for an AST node. The
1612-
/// `AttributesData` is inserted directly into the
1613-
/// constructed `AttrTokenStream` as
1614-
/// an `AttrTokenTree::Attributes`.
1615-
AttrTarget(AttributesData),
1611+
/// Holds the `AttrsTarget` for an AST node. The `AttrsTarget` is inserted
1612+
/// directly into the constructed `AttrTokenStream` as an
1613+
/// `AttrTokenTree::AttrsTarget`.
1614+
AttrsTarget(AttrsTarget),
16161615
/// A special 'empty' token that is ignored during the conversion
16171616
/// to an `AttrTokenStream`. This is used to simplify the
16181617
/// handling of replace ranges.

‎compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17441744
) {
17451745
self.r.dcx().emit_err(errors::LendingIteratorReportError {
17461746
lifetime: lifetime.ident.span,
1747-
ty: ty.span(),
1747+
ty: ty.span,
17481748
});
17491749
} else {
17501750
self.r.dcx().emit_err(errors::AnonymousLivetimeNonGatReportError {

‎library/alloc/src/collections/linked_list.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,14 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> {
14951495
pub fn back(&self) -> Option<&'a T> {
14961496
self.list.back()
14971497
}
1498+
1499+
/// Provides a reference to the cursor's parent list.
1500+
#[must_use]
1501+
#[inline(always)]
1502+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1503+
pub fn as_list(&self) -> &'a LinkedList<T, A> {
1504+
self.list
1505+
}
14981506
}
14991507

15001508
impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
@@ -1605,6 +1613,18 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
16051613
pub fn as_cursor(&self) -> Cursor<'_, T, A> {
16061614
Cursor { list: self.list, current: self.current, index: self.index }
16071615
}
1616+
1617+
/// Provides a read-only reference to the cursor's parent list.
1618+
///
1619+
/// The lifetime of the returned reference is bound to that of the
1620+
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
1621+
/// `CursorMut` is frozen for the lifetime of the reference.
1622+
#[must_use]
1623+
#[inline(always)]
1624+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1625+
pub fn as_list(&self) -> &LinkedList<T, A> {
1626+
self.list
1627+
}
16081628
}
16091629

16101630
// Now the list editing operations

‎library/core/src/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl hash::Hash for TypeId {
673673
#[stable(feature = "rust1", since = "1.0.0")]
674674
impl fmt::Debug for TypeId {
675675
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
676-
f.debug_tuple("TypeId").field(&self.as_u128()).finish()
676+
write!(f, "TypeId({:#034x})", self.as_u128())
677677
}
678678
}
679679

‎library/core/src/mem/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,20 @@ impl<T> SizedTypeProperties for T {}
12661266
/// // ^^^ error[E0616]: field `private` of struct `Struct` is private
12671267
/// ```
12681268
///
1269+
/// Only [`Sized`] fields are supported, but the container may be unsized:
1270+
/// ```
1271+
/// # use core::mem;
1272+
/// #[repr(C)]
1273+
/// pub struct Struct {
1274+
/// a: u8,
1275+
/// b: [u8],
1276+
/// }
1277+
///
1278+
/// assert_eq!(mem::offset_of!(Struct, a), 0); // OK
1279+
/// // assert_eq!(mem::offset_of!(Struct, b), 1);
1280+
/// // ^^^ error[E0277]: doesn't have a size known at compile-time
1281+
/// ```
1282+
///
12691283
/// Note that type layout is, in general, [subject to change and
12701284
/// platform-specific](https://doc.rust-lang.org/reference/type-layout.html). If
12711285
/// layout stability is required, consider using an [explicit `repr` attribute].

‎library/std/src/path.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,15 +3192,19 @@ impl Hash for Path {
31923192
let bytes = &bytes[prefix_len..];
31933193

31943194
let mut component_start = 0;
3195-
let mut bytes_hashed = 0;
3195+
// track some extra state to avoid prefix collisions.
3196+
// ["foo", "bar"] and ["foobar"], will have the same payload bytes
3197+
// but result in different chunk_bits
3198+
let mut chunk_bits: usize = 0;
31963199

31973200
for i in 0..bytes.len() {
31983201
let is_sep = if verbatim { is_verbatim_sep(bytes[i]) } else { is_sep_byte(bytes[i]) };
31993202
if is_sep {
32003203
if i > component_start {
32013204
let to_hash = &bytes[component_start..i];
3205+
chunk_bits = chunk_bits.wrapping_add(to_hash.len());
3206+
chunk_bits = chunk_bits.rotate_right(2);
32023207
h.write(to_hash);
3203-
bytes_hashed += to_hash.len();
32043208
}
32053209

32063210
// skip over separator and optionally a following CurDir item
@@ -3221,11 +3225,12 @@ impl Hash for Path {
32213225

32223226
if component_start < bytes.len() {
32233227
let to_hash = &bytes[component_start..];
3228+
chunk_bits = chunk_bits.wrapping_add(to_hash.len());
3229+
chunk_bits = chunk_bits.rotate_right(2);
32243230
h.write(to_hash);
3225-
bytes_hashed += to_hash.len();
32263231
}
32273232

3228-
h.write_usize(bytes_hashed);
3233+
h.write_usize(chunk_bits);
32293234
}
32303235
}
32313236

‎library/std/src/path/tests.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,20 @@ pub fn test_compare() {
16191619
relative_from: Some("")
16201620
);
16211621

1622+
tc!("foo//", "foo",
1623+
eq: true,
1624+
starts_with: true,
1625+
ends_with: true,
1626+
relative_from: Some("")
1627+
);
1628+
1629+
tc!("foo///", "foo",
1630+
eq: true,
1631+
starts_with: true,
1632+
ends_with: true,
1633+
relative_from: Some("")
1634+
);
1635+
16221636
tc!("foo/.", "foo",
16231637
eq: true,
16241638
starts_with: true,
@@ -1633,13 +1647,34 @@ pub fn test_compare() {
16331647
relative_from: Some("")
16341648
);
16351649

1650+
tc!("foo/.//bar", "foo/bar",
1651+
eq: true,
1652+
starts_with: true,
1653+
ends_with: true,
1654+
relative_from: Some("")
1655+
);
1656+
1657+
tc!("foo//./bar", "foo/bar",
1658+
eq: true,
1659+
starts_with: true,
1660+
ends_with: true,
1661+
relative_from: Some("")
1662+
);
1663+
16361664
tc!("foo/bar", "foo",
16371665
eq: false,
16381666
starts_with: true,
16391667
ends_with: false,
16401668
relative_from: Some("bar")
16411669
);
16421670

1671+
tc!("foo/bar", "foobar",
1672+
eq: false,
1673+
starts_with: false,
1674+
ends_with: false,
1675+
relative_from: None
1676+
);
1677+
16431678
tc!("foo/bar/baz", "foo/bar",
16441679
eq: false,
16451680
starts_with: true,

‎library/std/src/sync/once_lock.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,21 @@ use crate::sync::Once;
8080
/// static LIST: OnceList<u32> = OnceList::new();
8181
/// static COUNTER: AtomicU32 = AtomicU32::new(0);
8282
///
83-
/// let vec = (0..thread::available_parallelism().unwrap().get()).map(|_| thread::spawn(|| {
84-
/// while let i @ 0..=1000 = COUNTER.fetch_add(1, Ordering::Relaxed) {
85-
/// LIST.push(i);
83+
/// # const LEN: u32 = if cfg!(miri) { 50 } else { 1000 };
84+
/// # /*
85+
/// const LEN: u32 = 1000;
86+
/// # */
87+
/// thread::scope(|s| {
88+
/// for _ in 0..thread::available_parallelism().unwrap().get() {
89+
/// s.spawn(|| {
90+
/// while let i @ 0..LEN = COUNTER.fetch_add(1, Ordering::Relaxed) {
91+
/// LIST.push(i);
92+
/// }
93+
/// });
8694
/// }
87-
/// })).collect::<Vec<thread::JoinHandle<_>>>();
88-
/// vec.into_iter().for_each(|handle| handle.join().unwrap());
95+
/// });
8996
///
90-
/// for i in 0..=1000 {
97+
/// for i in 0..LEN {
9198
/// assert!(LIST.contains(&i));
9299
/// }
93100
///

‎src/doc/rustc/src/platform-support/wasm32-wasip1-threads.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ flag, for example:
107107

108108
Users need to install or built wasi-sdk since release 20.0
109109
https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-20
110-
and specify path to *wasi-root* `.cargo/config.toml`
110+
and specify path to *wasi-root* `config.toml`
111111

112112
```toml
113113
[target.wasm32-wasip1-threads]

‎tests/crashes/127332.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Regression test for ICE #127332
2+
3+
// Tests that we do not ICE when a with expr is
4+
// not a struct but something else like an enum
5+
6+
fn main() {
7+
let x = || {
8+
enum Foo {
9+
A { x: u32 },
10+
}
11+
let orig = Foo::A { x: 5 };
12+
Foo::A { x: 6, ..orig };
13+
//~^ ERROR functional record update syntax requires a struct
14+
};
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0436]: functional record update syntax requires a struct
2+
--> $DIR/ice-with-expr-not-struct-127332.rs:12:26
3+
|
4+
LL | Foo::A { x: 6, ..orig };
5+
| ^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0436`.

0 commit comments

Comments
 (0)
Please sign in to comment.