mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Migrated more diagnostics under transcribe.rs
This commit is contained in:
parent
7e15fbab75
commit
be18a9bf75
@ -6,3 +6,9 @@ expand_explain_doc_comment_inner =
|
||||
|
||||
expand_expr_repeat_no_syntax_vars =
|
||||
attempted to repeat an expression containing no syntax variables matched as repeating at this depth
|
||||
|
||||
expand_must_repeat_once =
|
||||
this must repeat at least once
|
||||
|
||||
count_repetition_misplaced =
|
||||
`count` can not be placed inside the inner-most repetition
|
@ -7,9 +7,9 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{pluralize, PResult};
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_span::hygiene::{LocalExpnId, Transparency};
|
||||
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_span::Span;
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
@ -61,6 +61,13 @@ struct NoSyntaxVarsExprRepeat {
|
||||
span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(expand::must_repeat_once)]
|
||||
struct MustRepeatOnce {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
}
|
||||
|
||||
/// This can do Macro-By-Example transcription.
|
||||
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
|
||||
/// invocation. We are assuming we already know there is a match.
|
||||
@ -197,10 +204,7 @@ pub(super) fn transcribe<'a>(
|
||||
// FIXME: this really ought to be caught at macro definition
|
||||
// time... It happens when the Kleene operator in the matcher and
|
||||
// the body for the same meta-variable do not match.
|
||||
return Err(cx.struct_span_err(
|
||||
sp.entire(),
|
||||
"this must repeat at least once",
|
||||
));
|
||||
return Err(cx.create_err(MustRepeatOnce { span: sp.entire() }));
|
||||
}
|
||||
} else {
|
||||
// 0 is the initial counter (we have done 0 repetitions so far). `len`
|
||||
@ -424,6 +428,13 @@ fn lockstep_iter_size(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(expand::count_repetition_misplaced)]
|
||||
struct CountRepetitionMisplaced {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
}
|
||||
|
||||
/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
|
||||
/// given optional nested depth.
|
||||
///
|
||||
@ -452,10 +463,7 @@ fn count_repetitions<'a>(
|
||||
match matched {
|
||||
MatchedTokenTree(_) | MatchedNonterminal(_) => {
|
||||
if declared_lhs_depth == 0 {
|
||||
return Err(cx.struct_span_err(
|
||||
sp.entire(),
|
||||
"`count` can not be placed inside the inner-most repetition",
|
||||
));
|
||||
return Err(cx.create_err( CountRepetitionMisplaced { span: sp.entire()} ));
|
||||
}
|
||||
match depth_opt {
|
||||
None => Ok(1),
|
||||
|
Loading…
Reference in New Issue
Block a user