Conditional compilation during monomorphisation

Has a feature of conditional compilation during monomorphisation been considered?

I'd like to compile something like this:

fn<A: Foo> blah(a: A) { #[conditional(A: Debug)] debug!("blah called with {:?}", a);

#[conditional(A: !Debug)]
debug!("blah called with a value of type {}", type_name::<A>);

}

This is a form of specialization, but more compact, and flexible to some extent

I think this would work similar to Tracking Issue for downcast_trait · Issue #144361 · rust-lang/rust · GitHub.

Of course the syntax is different, but the idea of branching in a function based on traits a generic implements it is the same.

1 Like

This is effectively a form of specialization, with all the soundness issues it has.

2 Likes