rust/compiler
Michael Goulet e6a3ca0c65
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`
2023-11-19 19:14:34 -08:00
..
rustc Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_abi Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_arena Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_ast Auto merge of #114292 - estebank:issue-71039, r=b-naber 2023-11-17 20:57:12 +00:00
rustc_ast_lowering Rollup merge of #117549 - DaniPopes:more-copied, r=b-naber 2023-11-17 23:04:22 +01:00
rustc_ast_passes Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
rustc_ast_pretty More detail when expecting expression but encountering bad macro argument 2023-11-16 16:19:04 +00:00
rustc_attr Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_baked_icu_data Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_borrowck Auto merge of #117944 - lcnr:region-refactor-uwu, r=BoxyUwU 2023-11-17 14:27:20 +00:00
rustc_builtin_macros Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
rustc_codegen_cranelift Merge commit 'def04540a4e2541b995195c752c751295606a388' into sync_cg_clif-2023-11-16 2023-11-16 21:15:07 +00:00
rustc_codegen_gcc Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_codegen_llvm Auto merge of #117500 - RalfJung:aggregate-abi, r=davidtwco 2023-11-19 18:42:20 +00:00
rustc_codegen_ssa Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillot 2023-11-19 19:14:33 -08:00
rustc_const_eval Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillot 2023-11-19 19:14:33 -08:00
rustc_data_structures Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_driver_impl Auto merge of #118002 - nnethercote:unify-input-no-input, r=bjorn3 2023-11-18 16:43:47 +00:00
rustc_error_codes Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_error_messages Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_errors Remove unnecessary .collect() 2023-11-19 17:50:47 +00:00
rustc_expand More detail when expecting expression but encountering bad macro argument 2023-11-16 16:19:04 +00:00
rustc_feature Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_fluent_macro Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_fs_util Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_graphviz Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_hir Add suggestion to THIR unsafe_op_in_unsafe_fn lint 2023-11-06 16:23:09 +00:00
rustc_hir_analysis Rollup merge of #117828 - Nilstrieb:astconv-hashmaps, r=petrochenkov 2023-11-19 19:14:32 -08:00
rustc_hir_pretty Fix remaining uses of CaptureBy::Value 2023-11-04 19:48:44 +01:00
rustc_hir_typeck fix rebase 2023-11-19 18:07:22 +00:00
rustc_incremental Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_index Begin nightly-ifying rustc_type_ir 2023-11-18 00:20:00 +00:00
rustc_index_macros Begin nightly-ifying rustc_type_ir 2023-11-18 00:20:00 +00:00
rustc_infer Rollup merge of #117549 - DaniPopes:more-copied, r=b-naber 2023-11-17 23:04:22 +01:00
rustc_interface Make Compiler::sess private. 2023-11-17 17:30:41 +11:00
rustc_lexer Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_lint catch pinned must_use types in unused_must_use 2023-11-18 20:04:50 -08:00
rustc_lint_defs Auto merge of #116930 - RalfJung:raw-ptr-match, r=davidtwco 2023-11-08 20:42:32 +00:00
rustc_llvm Auto merge of #117875 - Mark-Simulacrum:bootstrap-bump, r=clubby789 2023-11-16 12:45:27 +00:00
rustc_log rustc_log: provide a way to init logging based on the values, not names, of the env vars 2023-11-11 15:24:33 +01:00
rustc_macros Don't sort span_suggestions, leave that to caller 2023-11-19 17:50:45 +00:00
rustc_metadata rename bound region instantiation 2023-11-17 09:29:48 +00:00
rustc_middle Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillot 2023-11-19 19:14:33 -08:00
rustc_mir_build Rollup merge of #117832 - RalfJung:interpret-shift, r=cjgillot 2023-11-19 19:14:33 -08:00
rustc_mir_dataflow rename BorrowKind::Shallow to Fake 2023-11-08 22:55:28 +01:00
rustc_mir_transform Auto merge of #116828 - compiler-errors:nightlyify-rustc_type_ir, r=jackh726 2023-11-19 22:55:15 +00:00
rustc_monomorphize Minimize pub usage in source_map.rs. 2023-11-02 19:35:00 +11:00
rustc_parse Rollup merge of #117988 - estebank:issue-106020, r=cjgillot 2023-11-19 19:14:34 -08:00
rustc_parse_format Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstrieb 2023-11-15 14:55:35 +00:00
rustc_passes Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
rustc_privacy Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_query_impl Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_query_system Reduce exposure of things. 2023-11-16 16:49:22 +11:00
rustc_resolve fix rebase 2023-11-19 18:07:22 +00:00
rustc_serialize Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_session change smir to StableMir 2023-11-17 13:28:07 +03:00
rustc_smir use new apis and add new function 2023-11-17 23:28:17 +03:00
rustc_span Remove option_payload_ptr; redundant to offset_of 2023-11-16 22:56:25 +00:00
rustc_symbol_mangling Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
rustc_target Auto merge of #117500 - RalfJung:aggregate-abi, r=davidtwco 2023-11-19 18:42:20 +00:00
rustc_trait_selection Auto merge of #117742 - weiznich:turn_overlapping_diagnostic_options_into_warnings, r=compiler-errors 2023-11-18 02:57:09 +00:00
rustc_traits Remove -Zperf-stats. 2023-11-13 09:45:20 +11:00
rustc_transmute Clean up rustc_*/Cargo.toml. 2023-10-30 08:46:02 +11:00
rustc_ty_utils Auto merge of #117500 - RalfJung:aggregate-abi, r=davidtwco 2023-11-19 18:42:20 +00:00
rustc_type_ir Begin nightly-ifying rustc_type_ir 2023-11-18 00:20:00 +00:00
stable_mir use new apis and add new function 2023-11-17 23:28:17 +03:00