Skip to content

Commit 41e0e06

Browse files
Move inline_fluent to a proc macro
1 parent 71dc761 commit 41e0e06

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use syn::{LitStr, parse_macro_input};
2+
3+
use crate::diagnostics::message::Message;
4+
5+
pub(crate) fn inline_fluent(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
6+
let inline = parse_macro_input!(input as LitStr);
7+
let message =
8+
Message { attr_span: inline.span(), message_span: inline.span(), value: inline.value() };
9+
message.diag_message(None).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)