From 38b364b29d67e8518614d19e18d822786f94d220 Mon Sep 17 00:00:00 2001 From: binarycat Date: Fri, 28 Feb 2025 21:14:06 -0600 Subject: [PATCH 1/2] rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME fixes #137815 --- compiler/rustc_fluent_macro/src/fluent.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs index d4604c27e6da3..b04fd1b48f7ad 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -78,8 +78,8 @@ fn failed(crate_name: &Ident) -> proc_macro::TokenStream { /// See [rustc_fluent_macro::fluent_messages]. pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let crate_name = std::env::var("CARGO_PKG_NAME") - // If `CARGO_PKG_NAME` is missing, then we're probably running in a test, so use + let crate_name = std::env::var("CARGO_CRATE_NAME") + // If `CARGO_CRATE_NAME` is missing, then we're probably running in a test, so use // `no_crate`. .unwrap_or_else(|_| "no_crate".to_string()) .replace("rustc_", ""); From d1d0b9b8e199bd229457d9680233f71ca56bf36f Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 3 Mar 2025 15:29:19 -0600 Subject: [PATCH 2/2] add run-make test for rustc_fluent_macro with hypens in package name --- .../run-make/rustc_fluent_macro-hyphen-package/Cargo.toml | 4 ++++ .../rustc_fluent_macro-hyphen-package/messages.ftl | 1 + tests/run-make/rustc_fluent_macro-hyphen-package/rmake.rs | 8 ++++++++ .../run-make/rustc_fluent_macro-hyphen-package/src/lib.rs | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 tests/run-make/rustc_fluent_macro-hyphen-package/Cargo.toml create mode 100644 tests/run-make/rustc_fluent_macro-hyphen-package/messages.ftl create mode 100644 tests/run-make/rustc_fluent_macro-hyphen-package/rmake.rs create mode 100644 tests/run-make/rustc_fluent_macro-hyphen-package/src/lib.rs diff --git a/tests/run-make/rustc_fluent_macro-hyphen-package/Cargo.toml b/tests/run-make/rustc_fluent_macro-hyphen-package/Cargo.toml new file mode 100644 index 0000000000000..3592174b8a0cb --- /dev/null +++ b/tests/run-make/rustc_fluent_macro-hyphen-package/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "some-name" +version = "0.0.0" +edition = "2024" diff --git a/tests/run-make/rustc_fluent_macro-hyphen-package/messages.ftl b/tests/run-make/rustc_fluent_macro-hyphen-package/messages.ftl new file mode 100644 index 0000000000000..08fadca590efb --- /dev/null +++ b/tests/run-make/rustc_fluent_macro-hyphen-package/messages.ftl @@ -0,0 +1 @@ +some_name_whatever_message = hello diff --git a/tests/run-make/rustc_fluent_macro-hyphen-package/rmake.rs b/tests/run-make/rustc_fluent_macro-hyphen-package/rmake.rs new file mode 100644 index 0000000000000..4b28e7c6cd7b5 --- /dev/null +++ b/tests/run-make/rustc_fluent_macro-hyphen-package/rmake.rs @@ -0,0 +1,8 @@ +use run_make_support::external_deps::cargo::cargo; + +// test to make sure that `rustc_fluent_macro` correctly handles +// packages that have hyphens in their package name. + +fn main() { + cargo().arg("build").arg("--manifest-path=./Cargo.toml").run(); +} diff --git a/tests/run-make/rustc_fluent_macro-hyphen-package/src/lib.rs b/tests/run-make/rustc_fluent_macro-hyphen-package/src/lib.rs new file mode 100644 index 0000000000000..8d85587a4fca9 --- /dev/null +++ b/tests/run-make/rustc_fluent_macro-hyphen-package/src/lib.rs @@ -0,0 +1,7 @@ +#![feature(rustc_private)] + +extern crate rustc_driver; +extern crate rustc_errors; +extern crate rustc_fluent_macro; + +rustc_fluent_macro::fluent_messages!("../messages.ftl");