[Pre-Pre RFC] Escaping repetition operators in delimiter position

Right now there isn't a way to use +, *, or ? as a delimiter in a declarative macro. This sucks since + and * are binary operators which mean they effectively behave as a delimiter in many contexts and being able to match syntax within a macro to the rest of the language or even outside of it is incredibly useful. I propose that escaping a repetition character that is in the delimiter position will do just that, escape the repetition character.

Now while there are a ton of hacky ways to get around this, having official support and making it not hacky will open it up in certain places and generally increase code readability.

Example:

use core::num::*;
use core::ops::*;
trait Foo {
    fn foo(self) -> u32;
}
macro_rules! foo_for_generic_wrapper {
    ($W:ident<T$(: $($constraint:ident)\++>)?) => {
         impl<T> Foo for $t<T>
         $(where T: $($constraint)\++)?
         {
              fn foo(self) -> u32 {
                    self.0.foo()
              }
         }
    };
}
foo_for_generic_wrapper!(Wrapping<T>);
foo_for_generic_wrapper!(Saturating<T>);
// pretend ZeroablePrimitive is exposed
foo_for_generic_wrapper!(NonZero<T: ZeroablePrimitive>);
struct FourFunction<T: 
    Add<Self, Output=Self>
    + Sub<Self, Output=Self>
    + Mul<Self, Output=Self>
    + Div<Self, Output=Self>
>(T);
foo_for_generic_wrapper!(FourFunction<T: 
    Add<Self, Output=Self>
    + Sub<Self, Output=Self>
    + Mul<Self, Output=Self>
    + Div<Self, Output=Self>
>);

Previous discussion:

5 Likes