@@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
7
7
use rustc_data_structures:: fx:: FxHashMap ;
8
8
use rustc_errors:: { pluralize, PResult } ;
9
9
use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed } ;
10
+ use rustc_macros:: SessionDiagnostic ;
10
11
use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
11
12
use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
12
- use rustc_macros:: SessionDiagnostic ;
13
13
use rustc_span:: Span ;
14
14
15
15
use smallvec:: { smallvec, SmallVec } ;
@@ -61,6 +61,13 @@ struct NoSyntaxVarsExprRepeat {
61
61
span : Span ,
62
62
}
63
63
64
+ #[ derive( SessionDiagnostic ) ]
65
+ #[ error( expand:: must_repeat_once) ]
66
+ struct MustRepeatOnce {
67
+ #[ primary_span]
68
+ span : Span ,
69
+ }
70
+
64
71
/// This can do Macro-By-Example transcription.
65
72
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
66
73
/// invocation. We are assuming we already know there is a match.
@@ -197,10 +204,7 @@ pub(super) fn transcribe<'a>(
197
204
// FIXME: this really ought to be caught at macro definition
198
205
// time... It happens when the Kleene operator in the matcher and
199
206
// the body for the same meta-variable do not match.
200
- return Err ( cx. struct_span_err (
201
- sp. entire ( ) ,
202
- "this must repeat at least once" ,
203
- ) ) ;
207
+ return Err ( cx. create_err ( MustRepeatOnce { span : sp. entire ( ) } ) ) ;
204
208
}
205
209
} else {
206
210
// 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -424,6 +428,13 @@ fn lockstep_iter_size(
424
428
}
425
429
}
426
430
431
+ #[ derive( SessionDiagnostic ) ]
432
+ #[ error( expand:: count_repetition_misplaced) ]
433
+ struct CountRepetitionMisplaced {
434
+ #[ primary_span]
435
+ span : Span ,
436
+ }
437
+
427
438
/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
428
439
/// given optional nested depth.
429
440
///
@@ -452,10 +463,7 @@ fn count_repetitions<'a>(
452
463
match matched {
453
464
MatchedTokenTree ( _) | MatchedNonterminal ( _) => {
454
465
if declared_lhs_depth == 0 {
455
- return Err ( cx. struct_span_err (
456
- sp. entire ( ) ,
457
- "`count` can not be placed inside the inner-most repetition" ,
458
- ) ) ;
466
+ return Err ( cx. create_err ( CountRepetitionMisplaced { span : sp. entire ( ) } ) ) ;
459
467
}
460
468
match depth_opt {
461
469
None => Ok ( 1 ) ,
0 commit comments