Code change:
<ins> error: expected `;`, found `#` --> $DIR/multiple-tail-expr-behind-cfg.rs:5:64 | LL |     #[cfg(feature = "validation")] |     ------------------------------ only `;` terminated statements or tail expressions are allowed after this attribute LL |     [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() |                                                                ^ expected `;` here LL |     #[cfg(not(feature = "validation"))] |     - unexpected token | help: add `;` here | LL |     [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>(); |                                                                + help: alternatively, consider surrounding the expression with a block | LL |     { [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() } |     +                                                             + help: it seems like you are trying to provide different expressions depending on `cfg`, consider using `if cfg!(..)` | LL ~     if cfg!(feature = "validation") { LL ~         [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() LL ~     } else if cfg!(not(feature = "validation")) { LL ~         String::new() LL +     } | error: expected `;`, found `#` --> $DIR/multiple-tail-expr-behind-cfg.rs:12:64 | LL |     #[attr] |     ------- only `;` terminated statements or tail expressions are allowed after this attribute LL |     [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() |                                                                ^ expected `;` here LL |     #[attr] |     - unexpected token | help: add `;` here | LL |     [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>(); |                                                                + help: alternatively, consider surrounding the expression with a block | LL |     { [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() } |     +                                                             + error: cannot find attribute `attr` in this scope --> $DIR/multiple-tail-expr-behind-cfg.rs:13:7 | LL |     #[attr] |       ^^^^ error: aborting due to 3 previous errors </ins>

Related discussion:
text: Error code: Metadata:
What is the issue you are reporting here ?
Well, I thought that compiler can understand that is related to the block of code, but it fails.
Can you post a minimal reproducible example that demonstrates your issue? Or at least mention exactly what you'd expect to happen and why. Even code that is cfged out is still required to parse successfully.
Let's show you what exactly problem I have. Full code: And I get this error:
You seem to already have posted this a month ago. What you're asking seems a rather big change to me, I'm not that familiar with how the compiler parser works but I believe it currently requires your program syntax to be correct before macros are expanded, which is not true for your example, so some fundamental changes would be needed.
Oh, damn, sorry. I totally forgot that I made a post. Well, if it's not a bug and parser works like this it is bad, anyway, exists alternative way to write like this. But for me my issue is a candidate to feature request or a bug. Anyway, I'm not a lang dev, so I don't know what scales of this defect (?).
The workaround for this is to wrap the expressions in a block:
I solved this issue exactly as you did.
Another way to do this is using the macro and . I personally thinks it is more clear, and should optimize the same.
Work is not the same, due to compile-time evaluating an expression that we pass in it and evaluates only it, but at the same time everything compiles what is inside of .