Skip to content

Commit bbb83e5

Browse files
committed
Make expand_meta_var_dif_seq_matchers translatable
1 parent 3558ad9 commit bbb83e5

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

compiler/rustc_expand/messages.ftl

+8-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ expand_malformed_feature_attribute =
102102
malformed `feature` attribute input
103103
.expected = expected just one word
104104
105-
expand_meta_var_dif_seq_matchers = {$msg}
105+
expand_meta_var_dif_seq_matchers =
106+
meta-variable `{$var1_id}` repeats {$var1_len} {$var1_len ->
107+
[one] time
108+
*[count] times
109+
}, but `{$var2_id}` repeats {$var2_len} {$var2_len ->
110+
[one] time
111+
*[count] times
112+
}
106113
107114
expand_meta_var_expr_unrecognized_var =
108115
variable `{$key}` is not recognized in meta-variable expression

compiler/rustc_expand/src/errors.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ pub(crate) struct VarStillRepeating {
4949
pub(crate) struct MetaVarsDifSeqMatchers {
5050
#[primary_span]
5151
pub span: Span,
52-
pub msg: String,
52+
pub var1_id: String,
53+
pub var1_len: usize,
54+
pub var2_id: String,
55+
pub var2_len: usize,
5356
}
5457

5558
#[derive(Diagnostic)]

compiler/rustc_expand/src/mbe/transcribe.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
99
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1010
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
1111
use rustc_data_structures::fx::FxHashMap;
12-
use rustc_errors::{pluralize, Diag, PResult};
12+
use rustc_errors::{Diag, PResult};
1313
use rustc_parse::parser::ParseNtResult;
1414
use rustc_span::hygiene::{LocalExpnId, Transparency};
1515
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
@@ -206,14 +206,18 @@ pub(super) fn transcribe<'a>(
206206
.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
207207
}
208208

209-
LockstepIterSize::Contradiction(msg) => {
209+
LockstepIterSize::Contradiction { var1_id, var1_len, var2_id, var2_len } => {
210210
// FIXME: this really ought to be caught at macro definition time... It
211211
// happens when two meta-variables are used in the same repetition in a
212212
// sequence, but they come from different sequence matchers and repeat
213213
// different amounts.
214-
return Err(cx
215-
.dcx()
216-
.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
214+
return Err(cx.dcx().create_err(MetaVarsDifSeqMatchers {
215+
span: seq.span(),
216+
var1_id,
217+
var1_len,
218+
var2_id,
219+
var2_len,
220+
}));
217221
}
218222

219223
LockstepIterSize::Constraint(len, _) => {
@@ -459,7 +463,7 @@ enum LockstepIterSize {
459463
Constraint(usize, MacroRulesNormalizedIdent),
460464

461465
/// Two `Constraint`s on the same sequence had different lengths. This is an error.
462-
Contradiction(String),
466+
Contradiction { var1_id: String, var1_len: usize, var2_id: String, var2_len: usize },
463467
}
464468

465469
impl LockstepIterSize {
@@ -470,23 +474,17 @@ impl LockstepIterSize {
470474
fn with(self, other: LockstepIterSize) -> LockstepIterSize {
471475
match self {
472476
LockstepIterSize::Unconstrained => other,
473-
LockstepIterSize::Contradiction(_) => self,
477+
LockstepIterSize::Contradiction { .. } => self,
474478
LockstepIterSize::Constraint(l_len, l_id) => match other {
475479
LockstepIterSize::Unconstrained => self,
476-
LockstepIterSize::Contradiction(_) => other,
480+
LockstepIterSize::Contradiction { .. } => other,
477481
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self,
478-
LockstepIterSize::Constraint(r_len, r_id) => {
479-
let msg = format!(
480-
"meta-variable `{}` repeats {} time{}, but `{}` repeats {} time{}",
481-
l_id,
482-
l_len,
483-
pluralize!(l_len),
484-
r_id,
485-
r_len,
486-
pluralize!(r_len),
487-
);
488-
LockstepIterSize::Contradiction(msg)
489-
}
482+
LockstepIterSize::Constraint(r_len, r_id) => LockstepIterSize::Contradiction {
483+
var1_id: l_id.to_string(),
484+
var1_len: l_len,
485+
var2_id: r_id.to_string(),
486+
var2_len: r_len,
487+
},
490488
},
491489
}
492490
}

0 commit comments

Comments
 (0)