1
1
use crate :: base:: ExtCtxt ;
2
+ use crate :: errors:: {
3
+ CountRepetitionMisplaced , MetaVarExprUnrecognizedVar , MetaVarsDifSeqMatchers , MustRepeatOnce ,
4
+ NoSyntaxVarsExprRepeat , VarStillRepeating ,
5
+ } ;
2
6
use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , MatchedTokenTree , NamedMatch } ;
3
7
use crate :: mbe:: { self , MetaVarExpr } ;
4
8
use rustc_ast:: mut_visit:: { self , MutVisitor } ;
@@ -165,19 +169,15 @@ pub(super) fn transcribe<'a>(
165
169
seq @ mbe:: TokenTree :: Sequence ( _, delimited) => {
166
170
match lockstep_iter_size ( & seq, interp, & repeats) {
167
171
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 ( ) } ) ) ;
173
173
}
174
174
175
175
LockstepIterSize :: Contradiction ( msg) => {
176
176
// FIXME: this really ought to be caught at macro definition time... It
177
177
// happens when two meta-variables are used in the same repetition in a
178
178
// sequence, but they come from different sequence matchers and repeat
179
179
// different amounts.
180
- return Err ( cx. struct_span_err ( seq. span ( ) , & msg) ) ;
180
+ return Err ( cx. create_err ( MetaVarsDifSeqMatchers { span : seq. span ( ) , msg } ) ) ;
181
181
}
182
182
183
183
LockstepIterSize :: Constraint ( len, _) => {
@@ -193,10 +193,7 @@ pub(super) fn transcribe<'a>(
193
193
// FIXME: this really ought to be caught at macro definition
194
194
// time... It happens when the Kleene operator in the matcher and
195
195
// 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 ( ) } ) ) ;
200
197
}
201
198
} else {
202
199
// 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -239,10 +236,7 @@ pub(super) fn transcribe<'a>(
239
236
}
240
237
MatchedSeq ( ..) => {
241
238
// 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 } ) ) ;
246
240
}
247
241
}
248
242
} else {
@@ -448,10 +442,7 @@ fn count_repetitions<'a>(
448
442
match matched {
449
443
MatchedTokenTree ( _) | MatchedNonterminal ( _) => {
450
444
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 ( ) } ) ) ;
455
446
}
456
447
match depth_opt {
457
448
None => Ok ( 1 ) ,
@@ -499,12 +490,7 @@ where
499
490
{
500
491
let span = ident. span ;
501
492
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 } ) )
508
494
}
509
495
510
496
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
0 commit comments