Skip to content

Commit c9b1a58

Browse files
committed
fluent: mandate slug names to be prefixed by crate name
1 parent d0ea1d7 commit c9b1a58

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interfac
1414
privacy_from_private_dep_in_public_interface =
1515
{$kind} `{$descr}` from private dependency '{$krate}' in public interface
1616
17-
private_in_public_lint =
17+
privacy_private_in_public_lint =
1818
{$vis_descr} {$kind} `{$descr}` in public interface (error {$kind ->
1919
[trait] E0445
2020
*[other] E0446

compiler/rustc_macros/src/diagnostics/fluent.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,23 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
205205
// The last case we error about above, but we want to fall back gracefully
206206
// so that only the error is being emitted and not also one about the macro
207207
// failing.
208-
let snake_name = Ident::new(
209-
// FIXME: should probably trim prefix, not replace all occurrences
210-
&name.replace('-', "_").replace(&format!("{}_", res.ident), ""),
211-
span,
212-
);
208+
let crate_prefix = format!("{}_", res.ident);
209+
210+
let snake_name = name.replace('-', "_");
211+
let snake_name = match snake_name.strip_prefix(&crate_prefix) {
212+
Some(rest) => Ident::new(rest, span),
213+
None => {
214+
Diagnostic::spanned(
215+
ident_span,
216+
Level::Error,
217+
format!("name `{name}` does not start with the crate name"),
218+
)
219+
.help(format!("prepend `{crate_prefix}` to the slug name: `{crate_prefix}{snake_name}`"))
220+
.emit();
221+
Ident::new(&snake_name, span)
222+
}
223+
};
224+
213225
constants.extend(quote! {
214226
pub const #snake_name: crate::DiagnosticMessage =
215227
crate::DiagnosticMessage::FluentIdentifier(

0 commit comments

Comments
 (0)