Skip to content

Commit 4bb685e

Browse files
committed
Auto merge of rust-lang#95835 - Dylan-DPC:rollup-l5mf2ad, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#90066 (Add new ThinBox type for 1 stack pointer wide heap allocated trait objects) - rust-lang#95374 (assert_uninit_valid: ensure we detect at least arrays of uninhabited types) - rust-lang#95599 (Strict provenance lints) - rust-lang#95751 (Don't report numeric inference ambiguity when we have previous errors) - rust-lang#95764 ([macro_metavar_expr] Add tests to ensure the feature requirement) - rust-lang#95787 (reword panic vs result section to remove recoverable vs unrecoverable framing) - rust-lang#95797 (Remove explicit delimiter token trees from `Delimited`.) - rust-lang#95804 (rustdoc: Fix empty doc comment with backline ICE) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e980c62 + 8f4680e commit 4bb685e

40 files changed

+1029
-151
lines changed

compiler/rustc_ast/src/util/comments.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
5252
// when we try to compute the "horizontal trim".
5353
let lines = if kind == CommentKind::Block {
5454
// Whatever happens, we skip the first line.
55-
let mut i = if lines[0].trim_start().starts_with('*') { 0 } else { 1 };
55+
let mut i = lines
56+
.get(0)
57+
.map(|l| if l.trim_start().starts_with('*') { 0 } else { 1 })
58+
.unwrap_or(0);
5659
let mut j = lines.len();
5760

5861
while i < j && lines[i].trim().is_empty() {

compiler/rustc_expand/src/mbe.rs

+10-34
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,24 @@ use rustc_data_structures::sync::Lrc;
1717
use rustc_span::symbol::Ident;
1818
use rustc_span::Span;
1919

20-
/// Contains the sub-token-trees of a "delimited" token tree such as `(a b c)`. The delimiter itself
21-
/// might be `NoDelim`.
20+
/// Contains the sub-token-trees of a "delimited" token tree such as `(a b c)`. The delimiters
21+
/// might be `NoDelim`, but they are not represented explicitly.
2222
#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
2323
struct Delimited {
2424
delim: token::DelimToken,
25-
/// Note: This contains the opening and closing delimiters tokens (e.g. `(` and `)`). Note that
26-
/// these could be `NoDelim`. These token kinds must match `delim`, and the methods below
27-
/// debug_assert this.
28-
all_tts: Vec<TokenTree>,
25+
/// FIXME: #67062 has details about why this is sub-optimal.
26+
tts: Vec<TokenTree>,
2927
}
3028

3129
impl Delimited {
32-
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter. Panics if
33-
/// the delimiter is `NoDelim`.
34-
fn open_tt(&self) -> &TokenTree {
35-
let tt = self.all_tts.first().unwrap();
36-
debug_assert!(matches!(
37-
tt,
38-
&TokenTree::Token(token::Token { kind: token::OpenDelim(d), .. }) if d == self.delim
39-
));
40-
tt
30+
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
31+
fn open_tt(&self, span: DelimSpan) -> TokenTree {
32+
TokenTree::token(token::OpenDelim(self.delim), span.open)
4133
}
4234

43-
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter. Panics if
44-
/// the delimiter is `NoDelim`.
45-
fn close_tt(&self) -> &TokenTree {
46-
let tt = self.all_tts.last().unwrap();
47-
debug_assert!(matches!(
48-
tt,
49-
&TokenTree::Token(token::Token { kind: token::CloseDelim(d), .. }) if d == self.delim
50-
));
51-
tt
52-
}
53-
54-
/// Returns the tts excluding the outer delimiters.
55-
///
56-
/// FIXME: #67062 has details about why this is sub-optimal.
57-
fn inner_tts(&self) -> &[TokenTree] {
58-
// These functions are called for the assertions within them.
59-
let _open_tt = self.open_tt();
60-
let _close_tt = self.close_tt();
61-
&self.all_tts[1..self.all_tts.len() - 1]
35+
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
36+
fn close_tt(&self, span: DelimSpan) -> TokenTree {
37+
TokenTree::token(token::CloseDelim(self.delim), span.close)
6238
}
6339
}
6440

compiler/rustc_expand/src/mbe/macro_check.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn check_binders(
282282
// `MetaVarExpr` can not appear in the LHS of a macro arm
283283
TokenTree::MetaVarExpr(..) => {}
284284
TokenTree::Delimited(_, ref del) => {
285-
for tt in del.inner_tts() {
285+
for tt in &del.tts {
286286
check_binders(sess, node_id, tt, macros, binders, ops, valid);
287287
}
288288
}
@@ -345,7 +345,7 @@ fn check_occurrences(
345345
check_ops_is_prefix(sess, node_id, macros, binders, ops, dl.entire(), name);
346346
}
347347
TokenTree::Delimited(_, ref del) => {
348-
check_nested_occurrences(sess, node_id, del.inner_tts(), macros, binders, ops, valid);
348+
check_nested_occurrences(sess, node_id, &del.tts, macros, binders, ops, valid);
349349
}
350350
TokenTree::Sequence(_, ref seq) => {
351351
let ops = ops.push(seq.kleene);
@@ -432,20 +432,14 @@ fn check_nested_occurrences(
432432
{
433433
let macro_rules = state == NestedMacroState::MacroRulesNotName;
434434
state = NestedMacroState::Empty;
435-
let rest = check_nested_macro(
436-
sess,
437-
node_id,
438-
macro_rules,
439-
del.inner_tts(),
440-
&nested_macros,
441-
valid,
442-
);
435+
let rest =
436+
check_nested_macro(sess, node_id, macro_rules, &del.tts, &nested_macros, valid);
443437
// If we did not check the whole macro definition, then check the rest as if outside
444438
// the macro definition.
445439
check_nested_occurrences(
446440
sess,
447441
node_id,
448-
&del.inner_tts()[rest..],
442+
&del.tts[rest..],
449443
macros,
450444
binders,
451445
ops,

compiler/rustc_expand/src/mbe/macro_parser.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
151151
TokenTree::Token(token) => {
152152
locs.push(MatcherLoc::Token { token: token.clone() });
153153
}
154-
TokenTree::Delimited(_, delimited) => {
154+
TokenTree::Delimited(span, delimited) => {
155155
locs.push(MatcherLoc::Delimited);
156-
inner(sess, &delimited.all_tts, locs, next_metavar, seq_depth);
156+
inner(sess, &[delimited.open_tt(*span)], locs, next_metavar, seq_depth);
157+
inner(sess, &delimited.tts, locs, next_metavar, seq_depth);
158+
inner(sess, &[delimited.close_tt(*span)], locs, next_metavar, seq_depth);
157159
}
158160
TokenTree::Sequence(_, seq) => {
159161
// We can't determine `idx_first_after` and construct the final
@@ -293,7 +295,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
293295
.map(|tt| match tt {
294296
TokenTree::MetaVarDecl(..) => 1,
295297
TokenTree::Sequence(_, seq) => seq.num_captures,
296-
TokenTree::Delimited(_, delim) => count_metavar_decls(delim.inner_tts()),
298+
TokenTree::Delimited(_, delim) => count_metavar_decls(&delim.tts),
297299
TokenTree::Token(..) => 0,
298300
TokenTree::MetaVar(..) | TokenTree::MetaVarExpr(..) => unreachable!(),
299301
})

compiler/rustc_expand/src/mbe/macro_rules.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ fn generic_extension<'cx, 'tt>(
263263

264264
// Ignore the delimiters on the RHS.
265265
let rhs = match &rhses[i] {
266-
mbe::TokenTree::Delimited(_, delimited) => {
267-
delimited.inner_tts().to_vec().clone()
268-
}
266+
mbe::TokenTree::Delimited(_, delimited) => delimited.tts.to_vec(),
269267
_ => cx.span_bug(sp, "malformed macro rhs"),
270268
};
271269
let arm_span = rhses[i].span();
@@ -470,17 +468,16 @@ pub fn compile_declarative_macro(
470468
.iter()
471469
.map(|m| {
472470
if let MatchedTokenTree(ref tt) = *m {
473-
let mut tts = vec![];
474-
mbe::quoted::parse(
471+
let tt = mbe::quoted::parse(
475472
tt.clone().into(),
476473
true,
477474
&sess.parse_sess,
478475
def.id,
479476
features,
480477
edition,
481-
&mut tts,
482-
);
483-
let tt = tts.pop().unwrap();
478+
)
479+
.pop()
480+
.unwrap();
484481
valid &= check_lhs_nt_follows(&sess.parse_sess, features, &def, &tt);
485482
return tt;
486483
}
@@ -495,17 +492,16 @@ pub fn compile_declarative_macro(
495492
.iter()
496493
.map(|m| {
497494
if let MatchedTokenTree(ref tt) = *m {
498-
let mut tts = vec![];
499-
mbe::quoted::parse(
495+
return mbe::quoted::parse(
500496
tt.clone().into(),
501497
false,
502498
&sess.parse_sess,
503499
def.id,
504500
features,
505501
edition,
506-
&mut tts,
507-
);
508-
return tts.pop().unwrap();
502+
)
503+
.pop()
504+
.unwrap();
509505
}
510506
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
511507
})
@@ -544,7 +540,7 @@ pub fn compile_declarative_macro(
544540
// Ignore the delimiters around the matcher.
545541
match lhs {
546542
mbe::TokenTree::Delimited(_, delimited) => {
547-
mbe::macro_parser::compute_locs(&sess.parse_sess, delimited.inner_tts())
543+
mbe::macro_parser::compute_locs(&sess.parse_sess, &delimited.tts)
548544
}
549545
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"),
550546
}
@@ -576,7 +572,7 @@ fn check_lhs_nt_follows(
576572
// lhs is going to be like TokenTree::Delimited(...), where the
577573
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
578574
if let mbe::TokenTree::Delimited(_, delimited) = lhs {
579-
check_matcher(sess, features, def, delimited.inner_tts())
575+
check_matcher(sess, features, def, &delimited.tts)
580576
} else {
581577
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
582578
sess.span_diagnostic.span_err(lhs.span(), msg);
@@ -597,7 +593,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
597593
| TokenTree::MetaVarDecl(..)
598594
| TokenTree::MetaVarExpr(..) => (),
599595
TokenTree::Delimited(_, ref del) => {
600-
if !check_lhs_no_empty_seq(sess, del.inner_tts()) {
596+
if !check_lhs_no_empty_seq(sess, &del.tts) {
601597
return false;
602598
}
603599
}
@@ -692,9 +688,9 @@ impl FirstSets {
692688
| TokenTree::MetaVarExpr(..) => {
693689
first.replace_with(tt.clone());
694690
}
695-
TokenTree::Delimited(_span, ref delimited) => {
696-
build_recur(sets, delimited.inner_tts());
697-
first.replace_with(delimited.open_tt().clone());
691+
TokenTree::Delimited(span, ref delimited) => {
692+
build_recur(sets, &delimited.tts);
693+
first.replace_with(delimited.open_tt(span));
698694
}
699695
TokenTree::Sequence(sp, ref seq_rep) => {
700696
let subfirst = build_recur(sets, &seq_rep.tts);
@@ -758,8 +754,8 @@ impl FirstSets {
758754
first.add_one(tt.clone());
759755
return first;
760756
}
761-
TokenTree::Delimited(_span, ref delimited) => {
762-
first.add_one(delimited.open_tt().clone());
757+
TokenTree::Delimited(span, ref delimited) => {
758+
first.add_one(delimited.open_tt(span));
763759
return first;
764760
}
765761
TokenTree::Sequence(sp, ref seq_rep) => {
@@ -945,9 +941,9 @@ fn check_matcher_core(
945941
suffix_first = build_suffix_first();
946942
}
947943
}
948-
TokenTree::Delimited(_span, ref d) => {
949-
let my_suffix = TokenSet::singleton(d.close_tt().clone());
950-
check_matcher_core(sess, features, def, first_sets, d.inner_tts(), &my_suffix);
944+
TokenTree::Delimited(span, ref d) => {
945+
let my_suffix = TokenSet::singleton(d.close_tt(span));
946+
check_matcher_core(sess, features, def, first_sets, &d.tts, &my_suffix);
951947
// don't track non NT tokens
952948
last.replace_with_irrelevant();
953949

compiler/rustc_expand/src/mbe/quoted.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ pub(super) fn parse(
4545
node_id: NodeId,
4646
features: &Features,
4747
edition: Edition,
48-
result: &mut Vec<TokenTree>,
49-
) {
48+
) -> Vec<TokenTree> {
49+
// Will contain the final collection of `self::TokenTree`
50+
let mut result = Vec::new();
51+
5052
// For each token tree in `input`, parse the token into a `self::TokenTree`, consuming
5153
// additional trees if need be.
5254
let mut trees = input.trees();
@@ -113,6 +115,7 @@ pub(super) fn parse(
113115
_ => result.push(tree),
114116
}
115117
}
118+
result
116119
}
117120

118121
/// Asks for the `macro_metavar_expr` feature if it is not already declared
@@ -205,8 +208,7 @@ fn parse_tree(
205208
// If we didn't find a metavar expression above, then we must have a
206209
// repetition sequence in the macro (e.g. `$(pat)*`). Parse the
207210
// contents of the sequence itself
208-
let mut sequence = vec![];
209-
parse(tts, parsing_patterns, sess, node_id, features, edition, &mut sequence);
211+
let sequence = parse(tts, parsing_patterns, sess, node_id, features, edition);
210212
// Get the Kleene operator and optional separator
211213
let (separator, kleene) =
212214
parse_sep_and_kleene_op(&mut trees, delim_span.entire(), sess);
@@ -269,15 +271,13 @@ fn parse_tree(
269271

270272
// `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to
271273
// descend into the delimited set and further parse it.
272-
tokenstream::TokenTree::Delimited(span, delim, tts) => {
273-
let mut all_tts = vec![];
274-
// Add the explicit open and close delimiters, which
275-
// `tokenstream::TokenTree::Delimited` lacks.
276-
all_tts.push(TokenTree::token(token::OpenDelim(delim), span.open));
277-
parse(tts, parsing_patterns, sess, node_id, features, edition, &mut all_tts);
278-
all_tts.push(TokenTree::token(token::CloseDelim(delim), span.close));
279-
TokenTree::Delimited(span, Lrc::new(Delimited { delim, all_tts }))
280-
}
274+
tokenstream::TokenTree::Delimited(span, delim, tts) => TokenTree::Delimited(
275+
span,
276+
Lrc::new(Delimited {
277+
delim,
278+
tts: parse(tts, parsing_patterns, sess, node_id, features, edition),
279+
}),
280+
),
281281
}
282282
}
283283

compiler/rustc_expand/src/mbe/transcribe.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_errors::{pluralize, PResult};
1010
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
1111
use rustc_span::hygiene::{LocalExpnId, Transparency};
1212
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
13-
use rustc_span::{Span, DUMMY_SP};
13+
use rustc_span::Span;
1414

1515
use smallvec::{smallvec, SmallVec};
1616
use std::mem;
@@ -34,14 +34,8 @@ enum Frame {
3434

3535
impl Frame {
3636
/// Construct a new frame around the delimited set of tokens.
37-
fn new(mut tts: Vec<mbe::TokenTree>) -> Frame {
38-
// Need to add empty delimiters.
39-
let open_tt = mbe::TokenTree::token(token::OpenDelim(token::NoDelim), DUMMY_SP);
40-
let close_tt = mbe::TokenTree::token(token::CloseDelim(token::NoDelim), DUMMY_SP);
41-
tts.insert(0, open_tt);
42-
tts.push(close_tt);
43-
44-
let forest = Lrc::new(mbe::Delimited { delim: token::NoDelim, all_tts: tts });
37+
fn new(tts: Vec<mbe::TokenTree>) -> Frame {
38+
let forest = Lrc::new(mbe::Delimited { delim: token::NoDelim, tts });
4539
Frame::Delimited { forest, idx: 0, span: DelimSpan::dummy() }
4640
}
4741
}
@@ -52,7 +46,7 @@ impl Iterator for Frame {
5246
fn next(&mut self) -> Option<mbe::TokenTree> {
5347
match *self {
5448
Frame::Delimited { ref forest, ref mut idx, .. } => {
55-
let res = forest.inner_tts().get(*idx).cloned();
49+
let res = forest.tts.get(*idx).cloned();
5650
*idx += 1;
5751
res
5852
}
@@ -388,7 +382,7 @@ fn lockstep_iter_size(
388382
use mbe::TokenTree;
389383
match *tree {
390384
TokenTree::Delimited(_, ref delimited) => {
391-
delimited.inner_tts().iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
385+
delimited.tts.iter().fold(LockstepIterSize::Unconstrained, |size, tt| {
392386
size.with(lockstep_iter_size(tt, interpolations, repeats))
393387
})
394388
}

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ declare_features! (
505505
(active, static_nobundle, "1.16.0", Some(37403), None),
506506
/// Allows attributes on expressions and non-item statements.
507507
(active, stmt_expr_attributes, "1.6.0", Some(15701), None),
508+
/// Allows lints part of the strict provenance effort.
509+
(active, strict_provenance, "1.61.0", Some(95228), None),
508510
/// Allows the use of `#[target_feature]` on safe functions.
509511
(active, target_feature_11, "1.45.0", Some(69098), None),
510512
/// Allows using `#[thread_local]` on `static` items.

0 commit comments

Comments
 (0)