diff options
| author | Xiretza <xiretza@xiretza.xyz> | 2022-08-17 12:09:06 +0200 |
|---|---|---|
| committer | Xiretza <xiretza@xiretza.xyz> | 2022-08-22 08:42:44 +0200 |
| commit | c9b1a5874d06ca6c437ca8cca2224d546e8669ec (patch) | |
| tree | 26679898bc571ff18117e92207c16725a31e50cc | |
| parent | d0ea1d767925d53b2230e2ba81197821514781f0 (diff) | |
| download | rust-c9b1a5874d06ca6c437ca8cca2224d546e8669ec.tar.gz rust-c9b1a5874d06ca6c437ca8cca2224d546e8669ec.zip | |
fluent: mandate slug names to be prefixed by crate name
| -rw-r--r-- | compiler/rustc_error_messages/locales/en-US/privacy.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_macros/src/diagnostics/fluent.rs | 22 |
2 files changed, 18 insertions, 6 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/privacy.ftl b/compiler/rustc_error_messages/locales/en-US/privacy.ftl index 97050635f45..223092a74bd 100644 --- a/compiler/rustc_error_messages/locales/en-US/privacy.ftl +++ b/compiler/rustc_error_messages/locales/en-US/privacy.ftl @@ -14,7 +14,7 @@ privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interfac privacy_from_private_dep_in_public_interface = {$kind} `{$descr}` from private dependency '{$krate}' in public interface -private_in_public_lint = +privacy_private_in_public_lint = {$vis_descr} {$kind} `{$descr}` in public interface (error {$kind -> [trait] E0445 *[other] E0446 diff --git a/compiler/rustc_macros/src/diagnostics/fluent.rs b/compiler/rustc_macros/src/diagnostics/fluent.rs index 2e7652ad333..a222b9d5f12 100644 --- a/compiler/rustc_macros/src/diagnostics/fluent.rs +++ b/compiler/rustc_macros/src/diagnostics/fluent.rs @@ -205,11 +205,23 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok // The last case we error about above, but we want to fall back gracefully // so that only the error is being emitted and not also one about the macro // failing. - let snake_name = Ident::new( - // FIXME: should probably trim prefix, not replace all occurrences - &name.replace('-', "_").replace(&format!("{}_", res.ident), ""), - span, - ); + let crate_prefix = format!("{}_", res.ident); + + let snake_name = name.replace('-', "_"); + let snake_name = match snake_name.strip_prefix(&crate_prefix) { + Some(rest) => Ident::new(rest, span), + None => { + Diagnostic::spanned( + ident_span, + Level::Error, + format!("name `{name}` does not start with the crate name"), + ) + .help(format!("prepend `{crate_prefix}` to the slug name: `{crate_prefix}{snake_name}`")) + .emit(); + Ident::new(&snake_name, span) + } + }; + constants.extend(quote! { pub const #snake_name: crate::DiagnosticMessage = crate::DiagnosticMessage::FluentIdentifier( |
