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 } ;
@@ -7,7 +11,6 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
7
11
use rustc_data_structures:: fx:: FxHashMap ;
8
12
use rustc_errors:: { pluralize, PResult } ;
9
13
use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed } ;
10
- use rustc_macros:: SessionDiagnostic ;
11
14
use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
12
15
use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
13
16
use rustc_span:: Span ;
@@ -54,20 +57,6 @@ impl<'a> Iterator for Frame<'a> {
54
57
}
55
58
}
56
59
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
-
71
60
/// This can do Macro-By-Example transcription.
72
61
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
73
62
/// invocation. We are assuming we already know there is a match.
@@ -188,7 +177,7 @@ pub(super) fn transcribe<'a>(
188
177
// happens when two meta-variables are used in the same repetition in a
189
178
// sequence, but they come from different sequence matchers and repeat
190
179
// different amounts.
191
- return Err ( cx. struct_span_err ( seq. span ( ) , & msg) ) ;
180
+ return Err ( cx. create_err ( MetaVarsDifSeqMatchers { span : seq. span ( ) , msg } ) ) ;
192
181
}
193
182
194
183
LockstepIterSize :: Constraint ( len, _) => {
@@ -247,10 +236,7 @@ pub(super) fn transcribe<'a>(
247
236
}
248
237
MatchedSeq ( ..) => {
249
238
// 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 } ) ) ;
254
240
}
255
241
}
256
242
} else {
@@ -428,13 +414,6 @@ fn lockstep_iter_size(
428
414
}
429
415
}
430
416
431
- #[ derive( SessionDiagnostic ) ]
432
- #[ error( expand:: count_repetition_misplaced) ]
433
- struct CountRepetitionMisplaced {
434
- #[ primary_span]
435
- span : Span ,
436
- }
437
-
438
417
/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
439
418
/// given optional nested depth.
440
419
///
@@ -511,12 +490,7 @@ where
511
490
{
512
491
let span = ident. span ;
513
492
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 } ) )
520
494
}
521
495
522
496
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
0 commit comments