You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh, and I'm not sure if this is an option for you, but if the rust playground link shows how you'll actually call the macro (with a single identifier, like get_msg!(x)), then you could possibly rewrite the macro as follows and the code will still compile after rustfmt removes the braces {}:
macro_rules! get_msg {
- ($module:path) => {+ ($module:ident) => {
// this works but the braces in the import get lost on format
let message = {
use $module::{MESSAGE};
MESSAGE
};
// this would be nicer but doesn't work
// let message = $module::MESSAGE;
println!("{}", message);
};
}
In a macro that takes a path as an argument:
The braces around
MESSAGE
are required, and the code fails to compile without them. However, rustfmt removes them.Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ca5ee49a37c35354f67d82d6303c7f5a
The text was updated successfully, but these errors were encountered: