Skip to content

Commit c6f9a9c

Browse files
committed
Moved structs to rustc_expand::errors, added several more migrations, fixed slug name
1 parent 72ce216 commit c6f9a9c

File tree

5 files changed

+70
-36
lines changed

5 files changed

+70
-36
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ expand_expr_repeat_no_syntax_vars =
1010
expand_must_repeat_once =
1111
this must repeat at least once
1212
13-
count_repetition_misplaced =
14-
`count` can not be placed inside the inner-most repetition
13+
expand_count_repetition_misplaced =
14+
`count` can not be placed inside the inner-most repetition
15+
16+
expand_meta_var_expr_unrecognized_var =
17+
variable `{$key}` is not recognized in meta-variable expression
18+
19+
expand_var_still_repeating =
20+
variable '{$ident}' is still repeating at this depth
21+
22+
expand_meta_var_dif_seq_matchers = {$msg}

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_error_messages::FluentValue;
88
use rustc_hir as hir;
99
use rustc_lint_defs::{Applicability, LintExpectationId};
1010
use rustc_span::edition::LATEST_STABLE_EDITION;
11-
use rustc_span::symbol::{Ident, Symbol};
11+
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1212
use rustc_span::{edition::Edition, Span, DUMMY_SP};
1313
use std::borrow::Cow;
1414
use std::fmt;
@@ -87,6 +87,7 @@ into_diagnostic_arg_using_display!(
8787
hir::Target,
8888
Edition,
8989
Ident,
90+
MacroRulesNormalizedIdent,
9091
);
9192

9293
impl IntoDiagnosticArg for bool {

compiler/rustc_expand/src/errors.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::Span;
3+
use rustc_span::symbol::{MacroRulesNormalizedIdent};
4+
5+
#[derive(SessionDiagnostic)]
6+
#[error(expand::expr_repeat_no_syntax_vars)]
7+
pub(crate) struct NoSyntaxVarsExprRepeat {
8+
#[primary_span]
9+
pub span: Span,
10+
}
11+
12+
#[derive(SessionDiagnostic)]
13+
#[error(expand::must_repeat_once)]
14+
pub(crate) struct MustRepeatOnce {
15+
#[primary_span]
16+
pub span: Span,
17+
}
18+
19+
#[derive(SessionDiagnostic)]
20+
#[error(expand::count_repetition_misplaced)]
21+
pub(crate) struct CountRepetitionMisplaced {
22+
#[primary_span]
23+
pub span: Span,
24+
}
25+
26+
#[derive(SessionDiagnostic)]
27+
#[error(expand::meta_var_expr_unrecognized_var)]
28+
pub(crate) struct MetaVarExprUnrecognizedVar {
29+
#[primary_span]
30+
pub span: Span,
31+
pub key: MacroRulesNormalizedIdent,
32+
}
33+
34+
#[derive(SessionDiagnostic)]
35+
#[error(expand::var_still_repeating)]
36+
pub(crate) struct VarStillRepeating {
37+
#[primary_span]
38+
pub span: Span,
39+
pub ident: MacroRulesNormalizedIdent,
40+
}
41+
42+
#[derive(SessionDiagnostic)]
43+
#[error(expand::var_still_repeating)]
44+
pub(crate) struct MetaVarsDifSeqMatchers {
45+
#[primary_span]
46+
pub span: Span,
47+
pub msg: String,
48+
}
49+
50+

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod base;
2525
pub mod build;
2626
#[macro_use]
2727
pub mod config;
28+
pub mod errors;
2829
pub mod expand;
2930
pub mod module;
3031
pub mod proc_macro;

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use crate::base::ExtCtxt;
2+
use crate::errors::{
3+
CountRepetitionMisplaced, MetaVarExprUnrecognizedVar, MetaVarsDifSeqMatchers, MustRepeatOnce,
4+
NoSyntaxVarsExprRepeat, VarStillRepeating,
5+
};
26
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, MatchedTokenTree, NamedMatch};
37
use crate::mbe::{self, MetaVarExpr};
48
use rustc_ast::mut_visit::{self, MutVisitor};
@@ -7,7 +11,6 @@ use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree};
711
use rustc_data_structures::fx::FxHashMap;
812
use rustc_errors::{pluralize, PResult};
913
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
10-
use rustc_macros::SessionDiagnostic;
1114
use rustc_span::hygiene::{LocalExpnId, Transparency};
1215
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
1316
use rustc_span::Span;
@@ -54,20 +57,6 @@ impl<'a> Iterator for Frame<'a> {
5457
}
5558
}
5659

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-
7160
/// This can do Macro-By-Example transcription.
7261
/// - `interp` is a map of meta-variables to the tokens (non-terminals) they matched in the
7362
/// invocation. We are assuming we already know there is a match.
@@ -188,7 +177,7 @@ pub(super) fn transcribe<'a>(
188177
// happens when two meta-variables are used in the same repetition in a
189178
// sequence, but they come from different sequence matchers and repeat
190179
// different amounts.
191-
return Err(cx.struct_span_err(seq.span(), &msg));
180+
return Err(cx.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
192181
}
193182

194183
LockstepIterSize::Constraint(len, _) => {
@@ -247,10 +236,7 @@ pub(super) fn transcribe<'a>(
247236
}
248237
MatchedSeq(..) => {
249238
// 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 }));
254240
}
255241
}
256242
} else {
@@ -428,13 +414,6 @@ fn lockstep_iter_size(
428414
}
429415
}
430416

431-
#[derive(SessionDiagnostic)]
432-
#[error(expand::count_repetition_misplaced)]
433-
struct CountRepetitionMisplaced {
434-
#[primary_span]
435-
span: Span,
436-
}
437-
438417
/// Used solely by the `count` meta-variable expression, counts the outer-most repetitions at a
439418
/// given optional nested depth.
440419
///
@@ -511,12 +490,7 @@ where
511490
{
512491
let span = ident.span;
513492
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 }))
520494
}
521495

522496
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For

0 commit comments

Comments
 (0)