@@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
77use rustc_data_structures:: fx:: FxHashMap ;
88use rustc_errors:: { pluralize, PResult } ;
99use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed } ;
10+ use rustc_macros:: SessionDiagnostic ;
1011use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
1112use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
12- use rustc_macros:: SessionDiagnostic ;
1313use rustc_span:: Span ;
1414
1515use smallvec:: { smallvec, SmallVec } ;
@@ -61,6 +61,13 @@ struct NoSyntaxVarsExprRepeat {
6161 span : Span ,
6262}
6363
64+ #[ derive( SessionDiagnostic ) ]
65+ #[ error( expand:: must_repeat_once) ]
66+ struct MustRepeatOnce {
67+ #[ primary_span]
68+ span : Span ,
69+ }
70+
6471/// This can do Macro-By-Example transcription.
6572/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
6673/// invocation. We are assuming we already know there is a match.
@@ -197,10 +204,7 @@ pub(super) fn transcribe<'a>(
197204 // FIXME: this really ought to be caught at macro definition
198205 // time... It happens when the Kleene operator in the matcher and
199206 // 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 ( ) } ) ) ;
204208 }
205209 } else {
206210 // 0 is the initial counter (we have done 0 repetitions so far). `len`
@@ -424,6 +428,13 @@ fn lockstep_iter_size(
424428 }
425429}
426430
431+ #[ derive( SessionDiagnostic ) ]
432+ #[ error( expand:: count_repetition_misplaced) ]
433+ struct CountRepetitionMisplaced {
434+ #[ primary_span]
435+ span : Span ,
436+ }
437+
427438/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
428439/// given optional nested depth.
429440///
@@ -452,10 +463,7 @@ fn count_repetitions<'a>(
452463 match matched {
453464 MatchedTokenTree ( _) | MatchedNonterminal ( _) => {
454465 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 ( ) } ) ) ;
459467 }
460468 match depth_opt {
461469 None => Ok ( 1 ) ,
0 commit comments