@@ -40,26 +40,35 @@ fn invocation_relative_path_to_absolute(span: Span, path: &str) -> PathBuf {
40
40
}
41
41
}
42
42
43
- /// Tokens to be returned when the macro cannot proceed .
44
- fn failed ( crate_name : & Ident ) -> proc_macro:: TokenStream {
43
+ /// Final tokens .
44
+ fn finish ( body : TokenStream , resource : TokenStream ) -> proc_macro:: TokenStream {
45
45
quote ! {
46
- pub static DEFAULT_LOCALE_RESOURCE : & ' static str = "" ;
46
+ /// Raw content of Fluent resource for this crate, generated by `fluent_messages` macro,
47
+ /// imported by `rustc_driver` to include all crates' resources in one bundle.
48
+ pub static DEFAULT_LOCALE_RESOURCE : & ' static str = #resource;
47
49
48
50
#[ allow( non_upper_case_globals) ]
49
51
#[ doc( hidden) ]
52
+ /// Auto-generated constants for type-checked references to Fluent messages.
50
53
pub ( crate ) mod fluent_generated {
51
- pub mod #crate_name {
52
- }
54
+ #body
53
55
56
+ /// Constants expected to exist by the diagnostic derive macros to use as default Fluent
57
+ /// identifiers for different subdiagnostic kinds.
54
58
pub mod _subdiag {
59
+ /// Default for `#[help]`
55
60
pub const help: crate :: SubdiagnosticMessage =
56
61
crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "help" ) ) ;
62
+ /// Default for `#[note]`
57
63
pub const note: crate :: SubdiagnosticMessage =
58
64
crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "note" ) ) ;
65
+ /// Default for `#[warn]`
59
66
pub const warn: crate :: SubdiagnosticMessage =
60
67
crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "warn" ) ) ;
68
+ /// Default for `#[label]`
61
69
pub const label: crate :: SubdiagnosticMessage =
62
70
crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "label" ) ) ;
71
+ /// Default for `#[suggestion]`
63
72
pub const suggestion: crate :: SubdiagnosticMessage =
64
73
crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "suggestion" ) ) ;
65
74
}
@@ -68,6 +77,11 @@ fn failed(crate_name: &Ident) -> proc_macro::TokenStream {
68
77
. into ( )
69
78
}
70
79
80
+ /// Tokens to be returned when the macro cannot proceed.
81
+ fn failed ( crate_name : & Ident ) -> proc_macro:: TokenStream {
82
+ finish ( quote ! { pub mod #crate_name { } } , quote ! { "" } )
83
+ }
84
+
71
85
/// See [rustc_fluent_macro::fluent_messages].
72
86
pub ( crate ) fn fluent_messages ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
73
87
let crate_name = std:: env:: var ( "CARGO_PKG_NAME" )
@@ -311,39 +325,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
311
325
}
312
326
}
313
327
314
- quote ! {
315
- /// Raw content of Fluent resource for this crate, generated by `fluent_messages` macro,
316
- /// imported by `rustc_driver` to include all crates' resources in one bundle.
317
- pub static DEFAULT_LOCALE_RESOURCE : & ' static str = include_str!( #relative_ftl_path) ;
318
-
319
- #[ allow( non_upper_case_globals) ]
320
- #[ doc( hidden) ]
321
- /// Auto-generated constants for type-checked references to Fluent messages.
322
- pub ( crate ) mod fluent_generated {
323
- #constants
324
-
325
- /// Constants expected to exist by the diagnostic derive macros to use as default Fluent
326
- /// identifiers for different subdiagnostic kinds.
327
- pub mod _subdiag {
328
- /// Default for `#[help]`
329
- pub const help: crate :: SubdiagnosticMessage =
330
- crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "help" ) ) ;
331
- /// Default for `#[note]`
332
- pub const note: crate :: SubdiagnosticMessage =
333
- crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "note" ) ) ;
334
- /// Default for `#[warn]`
335
- pub const warn: crate :: SubdiagnosticMessage =
336
- crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "warn" ) ) ;
337
- /// Default for `#[label]`
338
- pub const label: crate :: SubdiagnosticMessage =
339
- crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "label" ) ) ;
340
- /// Default for `#[suggestion]`
341
- pub const suggestion: crate :: SubdiagnosticMessage =
342
- crate :: SubdiagnosticMessage :: FluentAttr ( std:: borrow:: Cow :: Borrowed ( "suggestion" ) ) ;
343
- }
344
- }
345
- }
346
- . into ( )
328
+ finish ( constants, quote ! { include_str!( #relative_ftl_path) } )
347
329
}
348
330
349
331
fn variable_references < ' a > ( msg : & Message < & ' a str > ) -> Vec < & ' a str > {
0 commit comments