Possible postfix macro use case: `.unwrap_dbg!(...)`

I think most people in favor of postfix macros have converged on the idea that postfix macros act like functions with respect to how it treats the receiver.

That is, conceptually, postfix macros would have a $self capture, and that captures the name of a temporary binding which the receiver is bound to. Example (using arbitrarily bad declaration syntax):

macro $self.unwrap_dbg!( $($tts:tt)* ) => { ... }

fallible(foo, bar).unwrap_dbg!(foo, bar);

// is semantically similar to

macro unwrap_dbg!( $self:ident, $($tts:tt)* ) => { ... }

match fallible(foo, bar) {
    __receiver => unwrap_dbg!(__receiver, foo, bar),
};

Anything else breaks the sanctity of "what code does" outside a macro invocation. Some trickery might be required such that $self refers to a temporary with the same semantics as if it hadn't been passed through a match rebind, but doing so seems feasible, and I plan to propose said semantics separately as a new capture type for macros.

15 Likes