Skip to content

Commit d1457f9

Browse files
authored
Unrolled build for rust-lang#116328
Rollup merge of rust-lang#116328 - nnethercote:rustc_fluent_macro, r=davidtwco Factor out common token generation in `fluent_messages`. The failure and success cases are similar enough that they can share code. r? `@davidtwco`
2 parents e3c631b + 57397de commit d1457f9

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

compiler/rustc_fluent_macro/src/fluent.rs

+20-38
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,35 @@ fn invocation_relative_path_to_absolute(span: Span, path: &str) -> PathBuf {
4040
}
4141
}
4242

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 {
4545
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;
4749

4850
#[allow(non_upper_case_globals)]
4951
#[doc(hidden)]
52+
/// Auto-generated constants for type-checked references to Fluent messages.
5053
pub(crate) mod fluent_generated {
51-
pub mod #crate_name {
52-
}
54+
#body
5355

56+
/// Constants expected to exist by the diagnostic derive macros to use as default Fluent
57+
/// identifiers for different subdiagnostic kinds.
5458
pub mod _subdiag {
59+
/// Default for `#[help]`
5560
pub const help: crate::SubdiagnosticMessage =
5661
crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
62+
/// Default for `#[note]`
5763
pub const note: crate::SubdiagnosticMessage =
5864
crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
65+
/// Default for `#[warn]`
5966
pub const warn: crate::SubdiagnosticMessage =
6067
crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("warn"));
68+
/// Default for `#[label]`
6169
pub const label: crate::SubdiagnosticMessage =
6270
crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
71+
/// Default for `#[suggestion]`
6372
pub const suggestion: crate::SubdiagnosticMessage =
6473
crate::SubdiagnosticMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
6574
}
@@ -68,6 +77,11 @@ fn failed(crate_name: &Ident) -> proc_macro::TokenStream {
6877
.into()
6978
}
7079

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+
7185
/// See [rustc_fluent_macro::fluent_messages].
7286
pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
7387
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
311325
}
312326
}
313327

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) })
347329
}
348330

349331
fn variable_references<'a>(msg: &Message<&'a str>) -> Vec<&'a str> {

compiler/rustc_log/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
//! }
2424
//! ```
2525
//!
26-
//! Now `LOG=debug cargo run` will run your minimal main.rs and show
26+
//! Now `LOG=debug cargo +nightly run` will run your minimal main.rs and show
2727
//! rustc's debug logging. In a workflow like this, one might also add
2828
//! `std::env::set_var("LOG", "debug")` to the top of main so that `cargo
29-
//! run` by itself is sufficient to get logs.
29+
//! +nightly run` by itself is sufficient to get logs.
3030
//!
3131
//! The reason rustc_log is a tiny separate crate, as opposed to exposing the
3232
//! same things in rustc_driver only, is to enable the above workflow. If you

0 commit comments

Comments
 (0)