Skip to content

Commit 9605aa6

Browse files
Move inline_fluent to a proc macro
1 parent 6efa357 commit 9605aa6

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub use rustc_error_messages::{
6363
use rustc_hashes::Hash128;
6464
use rustc_lint_defs::LintExpectationId;
6565
pub use rustc_lint_defs::{Applicability, listify, pluralize};
66+
pub use rustc_macros::inline_fluent;
6667
use rustc_macros::{Decodable, Encodable};
6768
pub use rustc_span::ErrorGuaranteed;
6869
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker, catch_fatal_errors};

compiler/rustc_errors/src/translation.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,3 @@ impl Translator {
9090
}
9191
}
9292
}
93-
94-
/// This macro creates a translatable `DiagMessage` from a literal string.
95-
/// It should be used in places where a translatable message is needed, but struct diagnostics are undesired.
96-
///
97-
/// This is a macro because in the future we may want to globally register these messages.
98-
#[macro_export]
99-
macro_rules! inline_fluent {
100-
($inline: literal) => {
101-
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed($inline))
102-
};
103-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use quote::quote;
2+
use syn::{LitStr, parse_macro_input};
3+
4+
pub(crate) fn inline_fluent(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
5+
let inline = parse_macro_input!(input as LitStr);
6+
quote! {
7+
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(#inline))
8+
}
9+
.into()
10+
}

compiler/rustc_macros/src/diagnostics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
mod diagnostic;
22
mod diagnostic_builder;
33
mod error;
4+
mod inline_fluent;
45
mod message;
56
mod subdiagnostic;
67
mod utils;
78

89
use diagnostic::{DiagnosticDerive, LintDiagnosticDerive};
10+
pub(super) use inline_fluent::inline_fluent;
911
use proc_macro2::TokenStream;
1012
use subdiagnostic::SubdiagnosticDerive;
1113
use synstructure::Structure;

compiler/rustc_macros/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ decl_derive!(
241241
applicability)] => diagnostics::subdiagnostic_derive
242242
);
243243

244+
/// This macro creates a translatable `DiagMessage` from a fluent format string.
245+
/// It should be used in places where a translatable message is needed, but struct diagnostics are undesired.
246+
///
247+
/// This macro statically checks that the message is valid Fluent, but not that variables in the Fluent message actually exist.
248+
#[proc_macro]
249+
pub fn inline_fluent(input: TokenStream) -> TokenStream {
250+
diagnostics::inline_fluent(input)
251+
}
252+
244253
decl_derive! {
245254
[PrintAttribute] =>
246255
/// Derives `PrintAttribute` for `AttributeKind`.

0 commit comments

Comments
 (0)