diff options
| author | Michael Goulet <michael@errs.io> | 2023-11-19 19:14:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-19 19:14:34 -0800 |
| commit | e6a3ca0c657a6c37e309fd8c9f0cc41d13478e20 (patch) | |
| tree | 53e315e7ca754f21b822604e74cab8e3c2993816 /tests/rustdoc-js-std/macro-print.js | |
| parent | 6d33e900d840445b5fccfad3c0c46ec347292d0b (diff) | |
| parent | a16722d2210caa5eea941ffa20837859e249fd05 (diff) | |
| download | rust-e6a3ca0c657a6c37e309fd8c9f0cc41d13478e20.tar.gz rust-e6a3ca0c657a6c37e309fd8c9f0cc41d13478e20.zip | |
Rollup merge of #117988 - estebank:issue-106020, r=cjgillot
Handle attempts to have multiple `cfg`d tail expressions
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.
r? `@oli-obk`
Diffstat (limited to 'tests/rustdoc-js-std/macro-print.js')
0 files changed, 0 insertions, 0 deletions
