if we go to this page
we will see this structure
BlockExpression →
{
InnerAttribute*
Statements?
}
Statements →
Statement+
| Statement+ ExpressionWithoutBlock
| ExpressionWithoutBlock
but it is impossible to put an attribute such #![allow(unused_variables)] inside a macro like this
macro_rules! show_block {
($b:block) => {
println!("Result: {}", $b);
};
}
fn main() {
show_block!({
#![allow(unused_assignments)]
});
}
are attributes not meant to be used with macros ????
then why is the reference mentioning them ????
BlockExpression →
{
InnerAttribute*
Statements?
}
it says inner and then statement am i reading it correctly ????
i followed this link
RUST FRAGMENTS
and click on blockexpression
here * block: a BlockExpression
This is not a matter of macros; the program
fn main() {
println!("Result: {}", {
#![allow(unused_assignments)]
0
});
}
fails to compile, with "error[E0658]: attributes on expressions are experimental", linking to https://github.com/rust-lang/rust/issues/15701 .
For obvious reasons, there are all sorts of programs which are syntactically valid (can be parsed) but fail to compile. I'd just place this case in that bucket.
and when would it be fixed ?
HJVT
March 25, 2026, 5:28pm
4
Whenever somebody interested in fixing this comes by and fixes it.
It's a desired feature but needs design work. It won't be landing tomorrow or anything like that.
In the meanwhile, you can probably use some sort of workaround.
println!("Result: {}", {{
#![allow(unused_assignments)]
0
}});
println!("Result: {}", ({
#![allow(unused_assignments)]
0
},).0);
it doesn't bother me anyways i just wanted to ask
Well that's why it's still not implemented.
hi_sam
March 27, 2026, 10:31am
9
As so far im concerned, it's not possible to use inner attribute inside macro logic. They're mainly used for crates / module system. (im new to rust)