mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-20 10:55:14 +00:00
![]() When encountering code that seems like it might be trying to have multiple tail expressions depending on `cfg` information, suggest alternatives that will success to parse. ```rust fn foo() -> String { #[cfg(feature = "validation")] [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() #[cfg(not(feature = "validation"))] String::new() } ``` ``` 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 + } | ``` Fix #106020. |
||
---|---|---|
.. | ||
attr-bad-meta-2.rs | ||
attr-bad-meta-2.stderr | ||
attr-bad-meta-3.rs | ||
attr-bad-meta-3.stderr | ||
attr-bad-meta.rs | ||
attr-bad-meta.stderr | ||
attr-before-eof.rs | ||
attr-before-eof.stderr | ||
attr-dangling-in-fn.rs | ||
attr-dangling-in-fn.stderr | ||
attr-dangling-in-mod.rs | ||
attr-dangling-in-mod.stderr | ||
attr-stmt-expr-attr-bad.rs | ||
attr-stmt-expr-attr-bad.stderr | ||
attr-with-a-semicolon.rs | ||
attr-with-a-semicolon.stderr | ||
attr.rs | ||
attr.stderr | ||
attribute-with-no-generics-in-parameter-list.rs | ||
attribute-with-no-generics-in-parameter-list.stderr | ||
attrs-after-extern-mod.rs | ||
attrs-after-extern-mod.stderr | ||
multiple-tail-expr-behind-cfg.rs | ||
multiple-tail-expr-behind-cfg.stderr |