about summary refs log tree commit diff
diff options
context:
space:
mode:
authornidnogg <henriquevt98@gmail.com>2022-08-16 19:02:51 -0300
committernidnogg <henriquevt98@gmail.com>2022-08-16 19:02:51 -0300
commitbe18a9bf75f6c92ee734838fd3eca9257556cf40 (patch)
tree8366748592987abdc08a76d33e7df29fab99bd0f
parent7e15fbab75ab919238ec86011fd54cba7ad78e68 (diff)
downloadrust-be18a9bf75f6c92ee734838fd3eca9257556cf40.tar.gz
rust-be18a9bf75f6c92ee734838fd3eca9257556cf40.zip
Migrated more diagnostics under transcribe.rs
-rw-r--r--compiler/rustc_error_messages/locales/en-US/expand.ftl6
-rw-r--r--compiler/rustc_expand/src/mbe/transcribe.rs26
2 files changed, 23 insertions, 9 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/expand.ftl b/compiler/rustc_error_messages/locales/en-US/expand.ftl
index 42519fd22ce..b25aaaa0e51 100644
--- a/compiler/rustc_error_messages/locales/en-US/expand.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/expand.ftl
@@ -6,3 +6,9 @@ expand_explain_doc_comment_inner =
 
 expand_expr_repeat_no_syntax_vars = 
     attempted to repeat an expression containing no syntax variables matched as repeating at this depth
+
+expand_must_repeat_once = 
+    this must repeat at least once
+
+count_repetition_misplaced =
+    `count` can not be placed inside the inner-most repetition
\ No newline at end of file
diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs
index 69090cb457e..4c8f7a59bba 100644
--- a/compiler/rustc_expand/src/mbe/transcribe.rs
+++ b/compiler/rustc_expand/src/mbe/transcribe.rs
@@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_errors::{pluralize, PResult};
 use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
+use rustc_macros::SessionDiagnostic;
 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};
@@ -61,6 +61,13 @@ struct NoSyntaxVarsExprRepeat {
     span: Span,
 }
 
+#[derive(SessionDiagnostic)]
+#[error(expand::must_repeat_once)]
+struct MustRepeatOnce {
+    #[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.
@@ -197,10 +204,7 @@ pub(super) fn transcribe<'a>(
                                 // FIXME: this really ought to be caught at macro definition
                                 // time... It happens when the Kleene operator in the matcher and
                                 // the body for the same meta-variable do not match.
-                                return Err(cx.struct_span_err(
-                                    sp.entire(),
-                                    "this must repeat at least once",
-                                ));
+                                return Err(cx.create_err(MustRepeatOnce { span: sp.entire() }));
                             }
                         } else {
                             // 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -424,6 +428,13 @@ fn lockstep_iter_size(
     }
 }
 
+#[derive(SessionDiagnostic)]
+#[error(expand::count_repetition_misplaced)]
+struct CountRepetitionMisplaced {
+    #[primary_span]
+    span: Span,
+}
+
 /// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
 /// given optional nested depth.
 ///
@@ -452,10 +463,7 @@ fn count_repetitions<'a>(
         match matched {
             MatchedTokenTree(_) | MatchedNonterminal(_) => {
                 if declared_lhs_depth == 0 {
-                    return Err(cx.struct_span_err(
-                        sp.entire(),
-                        "`count` can not be placed inside the inner-most repetition",
-                    ));
+                    return Err(cx.create_err( CountRepetitionMisplaced { span: sp.entire()} ));
                 }
                 match depth_opt {
                     None => Ok(1),