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"); +}