rust/compiler
bors ddb6cc8524 Auto merge of #97474 - compiler-errors:if-cond-and-block, r=oli-obk
Improve parsing errors and suggestions for bad `if` statements

1. Parses `if {}` as `if <err> {}` (block-like conditions that are missing a "then" block), and `if true && {}` as `if true && <err> {}` (unfinished binary operation), which is a more faithful recovery and leads to better typeck errors later on.
1. Points out the span of the condition if we don't see a "then" block after it, to help the user understand what is being parsed as a condition (and by elimination, what isn't).
1. Allow `if cond token else { }` to be fixed properly to `if cond { token } else { }`.
1. Fudge with the error messages a bit. This is somewhat arbitrary and I can revert my rewordings if they're useless.

----

Also this PR addresses a strange parsing regression (1.20 -> 1.21) where we chose to reject this piece of code somewhat arbitrarily, even though we should parse it fine:

```rust
fn main() {
    if { if true { return } else { return }; } {}
}
```

For context, all of these other expressions parse correctly:

```rust
fn main() {
    if { if true { return } else { return } } {}
    if { return; } {}
    if { return } {}
    if { return if true { } else { }; } {}
}
```

The parser used a heuristic to determine if the "the parsed `if` condition makes sense as a condition" that did like a one-expr-deep reachability analysis. This should not be handled by the parser though.
2022-06-15 02:58:44 +00:00
..
rustc Rollup merge of #97385 - oli-obk:smir-tool-lib, r=pnkfelix 2022-06-14 07:47:24 +09:00
rustc_apfloat Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_arena mark FIXMES for all the places found that are probably offset_from 2022-03-29 20:18:28 -04:00
rustc_ast Revert b983e42936. 2022-06-10 08:35:03 +10:00
rustc_ast_lowering remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
rustc_ast_passes remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
rustc_ast_pretty Revert #96682. 2022-06-02 11:22:16 +10:00
rustc_attr remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
rustc_borrowck Rename the ConstS::val field as kind. 2022-06-14 13:06:44 +10:00
rustc_builtin_macros remove unnecessary to_string and String::new for tool_only_span_suggestion 2022-06-13 16:01:16 +09:00
rustc_codegen_cranelift implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_codegen_gcc Add llvm.type.checked.load intrinsic 2022-06-14 14:50:52 +02:00
rustc_codegen_llvm Add metadata generation for vtables when using VFE 2022-06-14 14:50:52 +02:00
rustc_codegen_ssa Auto merge of #96285 - flip1995:pk-vfe, r=nagisa 2022-06-14 21:37:11 +00:00
rustc_const_eval rebase 2022-06-14 17:57:51 +02:00
rustc_data_structures Integrate measureme's hardware performance counter support. 2022-06-13 07:56:47 +00:00
rustc_driver Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis 2022-06-07 05:04:14 +00:00
rustc_error_codes Add comment for internal error codes 2022-06-12 19:52:49 -03:00
rustc_error_messages Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_errors Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_expand remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
rustc_feature Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Address comments 2022-06-11 16:38:48 -07:00
rustc_hir_pretty Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
rustc_incremental Revert dc08bc51f2. 2022-06-10 11:58:29 +10:00
rustc_index Auto merge of #97862 - SparrowLii:superset, r=lcnr 2022-06-09 07:13:46 +00:00
rustc_infer implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_interface Add -Zvirtual-function-elimination flag 2022-06-14 14:50:51 +02:00
rustc_lexer Reduce max hash in raw strings from u16 to u8 2022-03-23 22:13:55 +01:00
rustc_lint Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_lint_defs Use serde_json for json error messages 2022-06-03 16:46:19 +00:00
rustc_llvm Add metadata generation for vtables when using VFE 2022-06-14 14:50:52 +02:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros Auto merge of #94732 - nnethercote:infallible-encoder, r=bjorn3 2022-06-08 10:24:12 +00:00
rustc_metadata Auto merge of #95880 - cjgillot:def-ident-span, r=petrochenkov 2022-06-11 20:08:48 +00:00
rustc_middle rebase 2022-06-14 17:57:51 +02:00
rustc_mir_build rebase 2022-06-14 16:12:28 +02:00
rustc_mir_dataflow implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_mir_transform implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_monomorphize implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_parse Improve parsing errors and suggestions for bad if statements 2022-06-13 20:53:48 -07:00
rustc_parse_format Make rustc_parse_format compile on stable 2022-05-03 11:26:58 +02:00
rustc_passes Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_plugin_impl Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_privacy Folding revamp. 2022-06-08 09:24:03 +10:00
rustc_query_impl Integrate measureme's hardware performance counter support. 2022-06-13 07:56:47 +00:00
rustc_query_system Revert dc08bc51f2. 2022-06-10 11:58:29 +10:00
rustc_resolve remove unnecessary to_string and String::new for tool_only_span_suggestion 2022-06-13 16:01:16 +09:00
rustc_save_analysis Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_serialize Revert dc08bc51f2. 2022-06-10 11:58:29 +10:00
rustc_session Auto merge of #96285 - flip1995:pk-vfe, r=nagisa 2022-06-14 21:37:11 +00:00
rustc_smir Rustfmt 2022-06-02 10:29:00 +00:00
rustc_span Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk 2022-06-14 10:35:31 +02:00
rustc_symbol_mangling Auto merge of #96285 - flip1995:pk-vfe, r=nagisa 2022-06-14 21:37:11 +00:00
rustc_target Add Apple WatchOS compile targets 2022-06-13 16:08:53 +01:00
rustc_trait_selection rebase 2022-06-14 17:57:51 +02:00
rustc_traits implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_ty_utils implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_type_ir Revert b983e42936. 2022-06-10 08:35:03 +10:00
rustc_typeck Rollup merge of #97935 - nnethercote:rename-ConstS-val-as-kind, r=lcnr 2022-06-14 10:35:29 +02:00