I am really confused

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.

1 Like

and when would it be fixed ?

Whenever somebody interested in fixing this comes by and fixes it.

3 Likes

it seems nobody wants to

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);
1 Like

it doesn't bother me anyways i just wanted to ask

Well that's why it's still not implemented.

3 Likes

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)