Skip to content

Commit 0afb03e

Browse files
committed
make "invalid fragment specifier" translatable
1 parent a84bb95 commit 0afb03e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ expand_invalid_cfg_multiple_predicates = multiple `cfg` predicates are specified
6161
expand_invalid_cfg_no_parens = `cfg` is not followed by parentheses
6262
expand_invalid_cfg_no_predicate = `cfg` predicate is not specified
6363
expand_invalid_cfg_predicate_literal = `cfg` predicate key cannot be a literal
64+
65+
expand_invalid_fragment_specifier =
66+
invalid fragment specifier `{$name}`
67+
.help = {$help}
68+
6469
expand_macro_body_stability =
6570
macros cannot have body stability attributes
6671
.label = invalid body stability attribute

compiler/rustc_expand/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,13 @@ pub struct DuplicateMatcherBinding {
408408
#[label(expand_label2)]
409409
pub prev: Span,
410410
}
411+
412+
#[derive(Diagnostic)]
413+
#[diag(expand_invalid_fragment_specifier)]
414+
#[help]
415+
pub struct InvalidFragmentSpecifier {
416+
#[primary_span]
417+
pub span: Span,
418+
pub name: String,
419+
pub help: String,
420+
}

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use crate::mbe::macro_parser::count_metavar_decls;
23
use crate::mbe::{Delimited, KleeneOp, KleeneToken, MetaVarExpr, SequenceRepetition, TokenTree};
34

@@ -81,14 +82,13 @@ pub(super) fn parse(
8182
})
8283
.unwrap_or_else(
8384
|| {
84-
let msg = format!(
85-
"invalid fragment specifier `{}`",
86-
frag.name
85+
sess.dcx().emit_err(
86+
errors::InvalidFragmentSpecifier {
87+
span,
88+
name: frag.name.to_string(),
89+
help: VALID_FRAGMENT_NAMES_MSG.into(),
90+
},
8791
);
88-
sess.dcx()
89-
.struct_span_err(span, msg)
90-
.with_help(VALID_FRAGMENT_NAMES_MSG)
91-
.emit();
9292
token::NonterminalKind::Ident
9393
},
9494
);

0 commit comments

Comments
 (0)