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 } ;
@@ -165,19 +169,15 @@ pub(super) fn transcribe<'a>(
165169 seq @ mbe:: TokenTree :: Sequence ( _, delimited) => {
166170 match lockstep_iter_size ( & seq, interp, & repeats) {
167171 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- ) ) ;
172+ return Err ( cx. create_err ( NoSyntaxVarsExprRepeat { span : seq. span ( ) } ) ) ;
173173 }
174174
175175 LockstepIterSize :: Contradiction ( msg) => {
176176 // FIXME: this really ought to be caught at macro definition time... It
177177 // happens when two meta-variables are used in the same repetition in a
178178 // sequence, but they come from different sequence matchers and repeat
179179 // different amounts.
180- return Err ( cx. struct_span_err ( seq. span ( ) , & msg) ) ;
180+ return Err ( cx. create_err ( MetaVarsDifSeqMatchers { span : seq. span ( ) , msg } ) ) ;
181181 }
182182
183183 LockstepIterSize :: Constraint ( len, _) => {
@@ -193,10 +193,7 @@ pub(super) fn transcribe<'a>(
193193 // FIXME: this really ought to be caught at macro definition
194194 // time... It happens when the Kleene operator in the matcher and
195195 // the body for the same meta-variable do not match.
196- return Err ( cx. struct_span_err (
197- sp. entire ( ) ,
198- "this must repeat at least once" ,
199- ) ) ;
196+ return Err ( cx. create_err ( MustRepeatOnce { span : sp. entire ( ) } ) ) ;
200197 }
201198 } else {
202199 // 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -239,10 +236,7 @@ pub(super) fn transcribe<'a>(
239236 }
240237 MatchedSeq ( ..) => {
241238 // We were unable to descend far enough. This is an error.
242- return Err ( cx. struct_span_err (
243- sp, /* blame the macro writer */
244- & format ! ( "variable '{}' is still repeating at this depth" , ident) ,
245- ) ) ;
239+ return Err ( cx. create_err ( VarStillRepeating { span : sp, ident } ) ) ;
246240 }
247241 }
248242 } else {
@@ -448,10 +442,7 @@ fn count_repetitions<'a>(
448442 match matched {
449443 MatchedTokenTree ( _) | MatchedNonterminal ( _) => {
450444 if declared_lhs_depth == 0 {
451- return Err ( cx. struct_span_err (
452- sp. entire ( ) ,
453- "`count` can not be placed inside the inner-most repetition" ,
454- ) ) ;
445+ return Err ( cx. create_err ( CountRepetitionMisplaced { span : sp. entire ( ) } ) ) ;
455446 }
456447 match depth_opt {
457448 None => Ok ( 1 ) ,
@@ -499,12 +490,7 @@ where
499490{
500491 let span = ident. span ;
501492 let key = MacroRulesNormalizedIdent :: new ( ident) ;
502- interp. get ( & key) . ok_or_else ( || {
503- cx. struct_span_err (
504- span,
505- & format ! ( "variable `{}` is not recognized in meta-variable expression" , key) ,
506- )
507- } )
493+ interp. get ( & key) . ok_or_else ( || cx. create_err ( MetaVarExprUnrecognizedVar { span, key } ) )
508494}
509495
510496/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
0 commit comments