From 7e15fbab75ab919238ec86011fd54cba7ad78e68 Mon Sep 17 00:00:00 2001 From: nidnogg Date: Tue, 16 Aug 2022 18:34:13 -0300 Subject: [PATCH] Added first migration for repeated expressions without syntax vars --- .../rustc_error_messages/locales/en-US/expand.ftl | 3 +++ compiler/rustc_expand/src/mbe/transcribe.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/expand.ftl b/compiler/rustc_error_messages/locales/en-US/expand.ftl index bdfa22e77eb..42519fd22ce 100644 --- a/compiler/rustc_error_messages/locales/en-US/expand.ftl +++ b/compiler/rustc_error_messages/locales/en-US/expand.ftl @@ -3,3 +3,6 @@ expand_explain_doc_comment_outer = expand_explain_doc_comment_inner = inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match + +expand_expr_repeat_no_syntax_vars = + attempted to repeat an expression containing no syntax variables matched as repeating at this depth diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index e47ea83ac38..69090cb457e 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -9,6 +9,7 @@ use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_span::hygiene::{LocalExpnId, Transparency}; use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent}; +use rustc_macros::SessionDiagnostic; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; @@ -53,6 +54,13 @@ fn next(&mut self) -> Option<&'a mbe::TokenTree> { } } +#[derive(SessionDiagnostic)] +#[error(expand::expr_repeat_no_syntax_vars)] +struct NoSyntaxVarsExprRepeat { + #[primary_span] + span: Span, +} + /// This can do Macro-By-Example transcription. /// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the /// invocation. We are assuming we already know there is a match. @@ -165,11 +173,7 @@ pub(super) fn transcribe<'a>( seq @ mbe::TokenTree::Sequence(_, delimited) => { match lockstep_iter_size(&seq, interp, &repeats) { LockstepIterSize::Unconstrained => { - return Err(cx.struct_span_err( - seq.span(), /* blame macro writer */ - "attempted to repeat an expression containing no syntax variables \ - matched as repeating at this depth", - )); + return Err(cx.create_err(NoSyntaxVarsExprRepeat { span: seq.span() })); } LockstepIterSize::Contradiction(msg) => {