Closed
Description
Currently, some constructs like pattern matching using stringify!
on the left hand side of a match arm are not applicable, since the macro doesn't produce string literals - it produces expressions instead.
Example
#![feature(macro_rules)]
macro_rules! my_match {
($to_match:ident, $($var:ident,)*) => {
match $to_match {
$(
stringify!($var) => { // error: non-pattern macro in pattern position: stringify
$var = 42;
}
)*
_ => {
fail!("Failure");
}
}
}
}
fn main() {
let a_var = 32;
let b_var = 43;
let c_var = 44;
let to_match = "a_var";
my_match! { to_match,
a_var,
b_var,
c_var,
};
}
Such macros could be useful for code similiar to the above.
Metadata
Metadata
Assignees
Labels
No labels