11use crate :: base:: ExtCtxt ;
2+ use crate :: errors:: {
3+ CountRepetitionMisplaced , MetaVarExprUnrecognizedVar , MetaVarsDifSeqMatchers , MustRepeatOnce ,
4+ NoSyntaxVarsExprRepeat , VarStillRepeating ,
5+ } ;
26use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , MatchedTokenTree , NamedMatch } ;
37use crate :: mbe:: { self , MetaVarExpr } ;
48use rustc_ast:: mut_visit:: { self , MutVisitor } ;
@@ -7,7 +11,6 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
711use rustc_data_structures:: fx:: FxHashMap ;
812use rustc_errors:: { pluralize, PResult } ;
913use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed } ;
10- use rustc_macros:: SessionDiagnostic ;
1114use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
1215use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
1316use rustc_span:: Span ;
@@ -54,20 +57,6 @@ impl<'a> Iterator for Frame<'a> {
5457 }
5558}
5659
57- #[ derive( SessionDiagnostic ) ]
58- #[ error( expand:: expr_repeat_no_syntax_vars) ]
59- struct NoSyntaxVarsExprRepeat {
60- #[ primary_span]
61- span : Span ,
62- }
63-
64- #[ derive( SessionDiagnostic ) ]
65- #[ error( expand:: must_repeat_once) ]
66- struct MustRepeatOnce {
67- #[ primary_span]
68- span : Span ,
69- }
70-
7160/// This can do Macro-By-Example transcription.
7261/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
7362/// invocation. We are assuming we already know there is a match.
@@ -188,7 +177,7 @@ pub(super) fn transcribe<'a>(
188177 // happens when two meta-variables are used in the same repetition in a
189178 // sequence, but they come from different sequence matchers and repeat
190179 // different amounts.
191- return Err ( cx. struct_span_err ( seq. span ( ) , & msg) ) ;
180+ return Err ( cx. create_err ( MetaVarsDifSeqMatchers { span : seq. span ( ) , msg } ) ) ;
192181 }
193182
194183 LockstepIterSize :: Constraint ( len, _) => {
@@ -247,10 +236,7 @@ pub(super) fn transcribe<'a>(
247236 }
248237 MatchedSeq ( ..) => {
249238 // We were unable to descend far enough. This is an error.
250- return Err ( cx. struct_span_err (
251- sp, /* blame the macro writer */
252- & format ! ( "variable '{}' is still repeating at this depth" , ident) ,
253- ) ) ;
239+ return Err ( cx. create_err ( VarStillRepeating { span : sp, ident } ) ) ;
254240 }
255241 }
256242 } else {
@@ -428,13 +414,6 @@ fn lockstep_iter_size(
428414 }
429415}
430416
431- #[ derive( SessionDiagnostic ) ]
432- #[ error( expand:: count_repetition_misplaced) ]
433- struct CountRepetitionMisplaced {
434- #[ primary_span]
435- span : Span ,
436- }
437-
438417/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
439418/// given optional nested depth.
440419///
@@ -511,12 +490,7 @@ where
511490{
512491 let span = ident. span ;
513492 let key = MacroRulesNormalizedIdent :: new ( ident) ;
514- interp. get ( & key) . ok_or_else ( || {
515- cx. struct_span_err (
516- span,
517- & format ! ( "variable `{}` is not recognized in meta-variable expression" , key) ,
518- )
519- } )
493+ interp. get ( & key) . ok_or_else ( || cx. create_err ( MetaVarExprUnrecognizedVar { span, key } ) )
520494}
521495
522496/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
0 commit comments