diff options
| author | bors <bors@rust-lang.org> | 2023-06-07 14:32:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-07 14:32:11 +0000 |
| commit | b2807b2bf3be9fbed9a0aadc97841c20a1ab5f79 (patch) | |
| tree | f8861cada9423965104c8fb57a7dbfdf1cd68a15 /compiler/rustc_expand/src | |
| parent | e94bda3bf13303671427363d1cd93ac5e089f090 (diff) | |
| parent | 90c361c8376e8ec9d63cbd78b6d68c9647eb32c1 (diff) | |
| download | rust-b2807b2bf3be9fbed9a0aadc97841c20a1ab5f79.tar.gz rust-b2807b2bf3be9fbed9a0aadc97841c20a1ab5f79.zip | |
Auto merge of #112383 - Dylan-DPC:rollup-et2z6nt, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #112076 (Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal) - #112122 (Add `-Ztrait-solver=next-coherence`) - #112251 (rustdoc: convert `if let Some()` that always matches to variable) - #112345 (fix(expand): prevent infinity loop in macro containing only "///") - #112359 (Respect `RUST_BACKTRACE` for delayed bugs) - #112382 (download-rustc: Fix `x test core` on MacOS) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_parser.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_rules.rs | 45 |
2 files changed, 36 insertions, 10 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 1c222fb4a89..f0e67cfd50e 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -249,6 +249,7 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> { } /// A single matcher position, representing the state of matching. +#[derive(Debug)] struct MatcherPos { /// The index into `TtParser::locs`, which represents the "dot". idx: usize, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index e4c65a2049b..ee9616a0f0a 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -628,6 +628,40 @@ fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree) // after parsing/expansion. we can report every error in every macro this way. } +fn is_empty_token_tree(sess: &ParseSess, seq: &mbe::SequenceRepetition) -> bool { + if seq.separator.is_some() { + false + } else { + let mut is_empty = true; + let mut iter = seq.tts.iter().peekable(); + while let Some(tt) = iter.next() { + match tt { + mbe::TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => {} + mbe::TokenTree::Token(t @ Token { kind: DocComment(..), .. }) => { + let mut now = t; + while let Some(&mbe::TokenTree::Token( + next @ Token { kind: DocComment(..), .. }, + )) = iter.peek() + { + now = next; + iter.next(); + } + let span = t.span.to(now.span); + sess.span_diagnostic.span_note_without_error( + span, + "doc comments are ignored in matcher position", + ); + } + mbe::TokenTree::Sequence(_, sub_seq) + if (sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore + || sub_seq.kleene.op == mbe::KleeneOp::ZeroOrOne) => {} + _ => is_empty = false, + } + } + is_empty + } +} + /// Checks that the lhs contains no repetition which could match an empty token /// tree, because then the matcher would hang indefinitely. fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool { @@ -644,16 +678,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool { } } TokenTree::Sequence(span, seq) => { - if seq.separator.is_none() - && seq.tts.iter().all(|seq_tt| match seq_tt { - TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => true, - TokenTree::Sequence(_, sub_seq) => { - sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore - || sub_seq.kleene.op == mbe::KleeneOp::ZeroOrOne - } - _ => false, - }) - { + if is_empty_token_tree(sess, seq) { let sp = span.entire(); sess.span_diagnostic.span_err(sp, "repetition matches empty token tree"); return false; |
