Skip to content

Commit 3a917cd

Browse files
committed
make "invalid fragment specifier" translatable
1 parent a84bb95 commit 3a917cd

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

compiler/rustc_expand/messages.ftl

+5
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 `{$fragment}`
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

+10
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 fragment: Ident,
419+
pub help: String,
420+
}

compiler/rustc_expand/src/mbe/quoted.rs

+9-9
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

@@ -60,11 +61,11 @@ pub(super) fn parse(
6061
Some(&tokenstream::TokenTree::Token(Token { kind: token::Colon, span }, _)) => {
6162
match trees.next() {
6263
Some(tokenstream::TokenTree::Token(token, _)) => match token.ident() {
63-
Some((frag, _)) => {
64+
Some((fragment, _)) => {
6465
let span = token.span.with_lo(start_sp.lo());
6566

6667
let kind =
67-
token::NonterminalKind::from_symbol(frag.name, || {
68+
token::NonterminalKind::from_symbol(fragment.name, || {
6869
// FIXME(#85708) - once we properly decode a foreign
6970
// crate's `SyntaxContext::root`, then we can replace
7071
// this with just `span.edition()`. A
@@ -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+
fragment,
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)