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B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0=CC=B0?= =?UTF-8?q?=CC=B0=CC=B0=CC=B0=CC=B0=EF=BF=BD=C5=98=C2=A7=C5=AE=20=C3=82?= =?UTF-8?q?=C2=A3=E2=95=9F=C2=A9=E8=88=90=C3=A6=C3=98=C2=A2=C2=A3=C3=B0s?= =?UTF-8?q?=C3=9E=C2=A5=C2=BF=E2=80=94?= Date: Mon, 1 Sep 2025 05:08:29 +0000 Subject: [PATCH] Fix ninja BuildAction name sanitization (#4291) rust commit 8296ad0 changes the output of std::any::type_name to include regions such as lifetime and generic arguments, which results in invalid Ninja rule names being generated, such as `CargoBuild<_>`. --- CONTRIBUTORS | 1 + build/ninja_gen/src/action.rs | 42 ++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2571fc27b..5f12e1956 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -239,6 +239,7 @@ jcznk Thomas Rixen Siyuan Mattuwu Yan Lee Doughty +memchr ******************** diff --git a/build/ninja_gen/src/action.rs b/build/ninja_gen/src/action.rs index 97d77de95..14f08deb5 100644 --- a/build/ninja_gen/src/action.rs +++ b/build/ninja_gen/src/action.rs @@ -49,6 +49,46 @@ pub trait BuildAction { } fn name(&self) -> &'static str { - std::any::type_name::().split("::").last().unwrap() + std::any::type_name::() + .split("::") + .last() + .unwrap() + .split('<') + .next() + .unwrap() } } + +#[cfg(test)] +trait TestBuildAction {} + +#[cfg(test)] +impl BuildAction for T { + fn command(&self) -> &str { + "test" + } + fn files(&mut self, _build: &mut impl FilesHandle) {} +} + +#[allow(dead_code, unused_variables)] +#[test] +fn should_strip_regions_in_type_name() { + struct Bare; + impl TestBuildAction for Bare {} + assert_eq!(Bare {}.name(), "Bare"); + + struct WithLifeTime<'a>(&'a str); + impl TestBuildAction for WithLifeTime<'_> {} + assert_eq!(WithLifeTime("test").name(), "WithLifeTime"); + + struct WithMultiLifeTime<'a, 'b>(&'a str, &'b str); + impl TestBuildAction for WithMultiLifeTime<'_, '_> {} + assert_eq!( + WithMultiLifeTime("test", "test").name(), + "WithMultiLifeTime" + ); + + struct WithGeneric(T); + impl TestBuildAction for WithGeneric {} + assert_eq!(WithGeneric(3).name(), "WithGeneric"); +}