Skip to content

Commit be18a9b

Browse files
committed
Migrated more diagnostics under transcribe.rs
1 parent 7e15fba commit be18a9b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

compiler/rustc_error_messages/locales/en-US/expand.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ expand_explain_doc_comment_inner =
66
77
expand_expr_repeat_no_syntax_vars =
88
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
9+
10+
expand_must_repeat_once =
11+
this must repeat at least once
12+
13+
count_repetition_misplaced =
14+
`count` can not be placed inside the inner-most repetition

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_errors::{pluralize, PResult};
99
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
10+
use rustc_macros::SessionDiagnostic;
1011
use rustc_span::hygiene::{LocalExpnId, Transparency};
1112
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
12-
use rustc_macros::SessionDiagnostic;
1313
use rustc_span::Span;
1414

1515
use 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

Comments
 (0)