Skip to content

Commit 7e15fba

Browse files
committed
Added first migration for repeated expressions without syntax vars
1 parent a39bdb1 commit 7e15fba

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

compiler/rustc_error_messages/locales/en-US/expand.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ expand_explain_doc_comment_outer =
33
44
expand_explain_doc_comment_inner =
55
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
6+
7+
expand_expr_repeat_no_syntax_vars =
8+
attempted to repeat an expression containing no syntax variables matched as repeating at this depth

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_errors::{pluralize, PResult};
99
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
1010
use rustc_span::hygiene::{LocalExpnId, Transparency};
1111
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
12+
use rustc_macros::SessionDiagnostic;
1213
use rustc_span::Span;
1314

1415
use smallvec::{smallvec, SmallVec};
@@ -53,6 +54,13 @@ impl<'a> Iterator for Frame<'a> {
5354
}
5455
}
5556

57+
#[derive(SessionDiagnostic)]
58+
#[error(expand::expr_repeat_no_syntax_vars)]
59+
struct NoSyntaxVarsExprRepeat {
60+
#[primary_span]
61+
span: Span,
62+
}
63+
5664
/// This can do Macro-By-Example transcription.
5765
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
5866
/// invocation. We are assuming we already know there is a match.
@@ -165,11 +173,7 @@ pub(super) fn transcribe<'a>(
165173
seq @ mbe::TokenTree::Sequence(_, delimited) => {
166174
match lockstep_iter_size(&seq, interp, &repeats) {
167175
LockstepIterSize::Unconstrained => {
168-
return Err(cx.struct_span_err(
169-
seq.span(), /* blame macro writer */
170-
"attempted to repeat an expression containing no syntax variables \
171-
matched as repeating at this depth",
172-
));
176+
return Err(cx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
173177
}
174178

175179
LockstepIterSize::Contradiction(msg) => {

0 commit comments

Comments
 (0)