Skip to content

Commit 8add965

Browse files
committed
Make expand_meta_var_dif_seq_matchers translatable
1 parent f13094e commit 8add965

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ expand_malformed_feature_attribute =
109109
malformed `feature` attribute input
110110
.expected = expected just one word
111111
112-
expand_meta_var_dif_seq_matchers = {$msg}
112+
expand_meta_var_dif_seq_matchers =
113+
meta-variable `{$var1_id}` repeats {$var1_len} {$var1_len ->
114+
[one] time
115+
*[count] times
116+
}, but `{$var2_id}` repeats {$var2_len} {$var2_len ->
117+
[one] time
118+
*[count] times
119+
}
113120
114121
expand_meta_var_expr_unrecognized_var =
115122
variable `{$key}` is not recognized in meta-variable expression

compiler/rustc_expand/src/errors.rs

Lines changed: 4 additions & 1 deletion
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

Lines changed: 18 additions & 20 deletions
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};
@@ -200,14 +200,18 @@ pub(super) fn transcribe<'a>(
200200
.create_err(NoSyntaxVarsExprRepeat { span: seq.span() }));
201201
}
202202

203-
LockstepIterSize::Contradiction(msg) => {
203+
LockstepIterSize::Contradiction { var1_id, var1_len, var2_id, var2_len } => {
204204
// FIXME: this really ought to be caught at macro definition time... It
205205
// happens when two meta-variables are used in the same repetition in a
206206
// sequence, but they come from different sequence matchers and repeat
207207
// different amounts.
208-
return Err(cx
209-
.dcx()
210-
.create_err(MetaVarsDifSeqMatchers { span: seq.span(), msg }));
208+
return Err(cx.dcx().create_err(MetaVarsDifSeqMatchers {
209+
span: seq.span(),
210+
var1_id,
211+
var1_len,
212+
var2_id,
213+
var2_len,
214+
}));
211215
}
212216

213217
LockstepIterSize::Constraint(len, _) => {
@@ -447,7 +451,7 @@ enum LockstepIterSize {
447451
Constraint(usize, MacroRulesNormalizedIdent),
448452

449453
/// Two `Constraint`s on the same sequence had different lengths. This is an error.
450-
Contradiction(String),
454+
Contradiction { var1_id: String, var1_len: usize, var2_id: String, var2_len: usize },
451455
}
452456

453457
impl LockstepIterSize {
@@ -458,23 +462,17 @@ impl LockstepIterSize {
458462
fn with(self, other: LockstepIterSize) -> LockstepIterSize {
459463
match self {
460464
LockstepIterSize::Unconstrained => other,
461-
LockstepIterSize::Contradiction(_) => self,
465+
LockstepIterSize::Contradiction { .. } => self,
462466
LockstepIterSize::Constraint(l_len, l_id) => match other {
463467
LockstepIterSize::Unconstrained => self,
464-
LockstepIterSize::Contradiction(_) => other,
468+
LockstepIterSize::Contradiction { .. } => other,
465469
LockstepIterSize::Constraint(r_len, _) if l_len == r_len => self,
466-
LockstepIterSize::Constraint(r_len, r_id) => {
467-
let msg = format!(
468-
"meta-variable `{}` repeats {} time{}, but `{}` repeats {} time{}",
469-
l_id,
470-
l_len,
471-
pluralize!(l_len),
472-
r_id,
473-
r_len,
474-
pluralize!(r_len),
475-
);
476-
LockstepIterSize::Contradiction(msg)
477-
}
470+
LockstepIterSize::Constraint(r_len, r_id) => LockstepIterSize::Contradiction {
471+
var1_id: l_id.to_string(),
472+
var1_len: l_len,
473+
var2_id: r_id.to_string(),
474+
var2_len: r_len,
475+
},
478476
},
479477
}
480478
}

0 commit comments

Comments
 (0)