rust/compiler
Manish Goregaokar dc003dd49e
Rollup merge of #88546 - scrabsha:scrabsha/closure-missing-braces, r=estebank
Emit proper errors when on missing closure braces

This commit focuses on emitting clean errors for the following syntax
error:

```
Some(42).map(|a|
    dbg!(a);
    a
);
```

Previous implementation tried to recover after parsing the closure body
(the `dbg` expression) by replacing the next `;` with a `,`, which made
the next expression belong to the next function argument. As such, the
following errors were emitted (among others):
  - the semicolon token was not expected,
  - a is not in scope,
  - Option::map is supposed to take one argument, not two.

This commit allows us to gracefully handle this situation by adding
giving the parser the ability to remember when it has just parsed a
closure body inside a function call. When this happens, we can treat the
unexpected `;` specifically and try to parse as much statements as
possible in order to eat the whole block. When we can't parse statements
anymore, we generate a clean error indicating that the braces are
missing, and return an ExprKind::Err.

Closes #88065.

r? `@estebank`
2021-09-10 08:23:17 -07:00
..
rustc rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_apfloat rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_arena Remove unused arena macro args 2021-08-30 13:09:38 +02:00
rustc_ast Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_ast_lowering Change is_unsized to add_implicitly_sized 2021-09-07 18:08:46 -04:00
rustc_ast_passes Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_ast_pretty Add let-else to AST 2021-08-30 20:17:45 -05:00
rustc_attr Remove Session.used_attrs and move logic to CheckAttrVisitor 2021-08-21 13:27:27 -05:00
rustc_borrowck Fix two uses of span_note when the source is not available 2021-09-09 21:17:05 +02:00
rustc_builtin_macros Rollup merge of #87441 - ibraheemdev:i-86865, r=cjgillot 2021-09-10 08:23:15 -07:00
rustc_codegen_cranelift Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
rustc_codegen_llvm Auto merge of #88499 - eddyb:layout-off, r=nagisa 2021-09-05 16:14:41 +00:00
rustc_codegen_ssa Auto merge of #88161 - michaelwoerister:fix-whole-archive-no-bundle, r=petrochenkov 2021-09-07 12:31:11 +00:00
rustc_const_eval Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_data_structures Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_driver Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
rustc_error_codes Update E0785.md 2021-08-30 22:18:55 -07:00
rustc_errors Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_expand Rollup merge of #87441 - ibraheemdev:i-86865, r=cjgillot 2021-09-10 08:23:15 -07:00
rustc_feature Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_fs_util rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_graphviz rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_hir Don't move ?Trait bounds to param bounds if they're in where clauses 2021-09-07 18:08:46 -04:00
rustc_hir_pretty Don't move ?Trait bounds to param bounds if they're in where clauses 2021-09-07 18:08:46 -04:00
rustc_incremental Auto merge of #83214 - cjgillot:dep-map, r=michaelwoerister 2021-09-06 23:58:16 +00:00
rustc_index Suggested changes 2021-08-27 16:21:25 -07:00
rustc_infer Use index newtyping for TyVid 2021-09-06 22:38:06 -04:00
rustc_interface Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
rustc_lexer Fix more “a”/“an” typos 2021-08-22 17:27:18 +02:00
rustc_lint Auto merge of #88435 - cjgillot:no-walk-crate, r=Aaron1011 2021-09-05 21:40:34 +00:00
rustc_lint_defs Tracking issue for UNSUPPORTED_CALLING_CONVENTIONS 2021-08-27 20:47:00 +03:00
rustc_llvm RustWrapper: adapt to LLVM change 0f45c16f2caa 2021-08-26 10:40:27 -04:00
rustc_macros Rollup merge of #86123 - Aaron1011:query-span, r=cjgillot 2021-08-19 19:30:04 +02:00
rustc_metadata Auto merge of #88538 - bjorn3:no_session_in_crate_loader, r=petrochenkov 2021-09-04 07:17:12 +00:00
rustc_middle Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_mir_build Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_mir_dataflow Rebase fallout. 2021-09-08 20:40:30 +02:00
rustc_mir_transform Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_monomorphize Rebase fallout. 2021-09-08 20:40:30 +02:00
rustc_parse Emit proper errors on missing closure braces 2021-09-09 17:44:40 +02:00
rustc_parse_format rfc3052: Remove authors field from Cargo manifests 2021-07-29 14:56:05 -07:00
rustc_passes Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_plugin_impl Remove Session.used_attrs and move logic to CheckAttrVisitor 2021-08-21 13:27:27 -05:00
rustc_privacy Rename walk_crate. 2021-09-02 19:23:11 +02:00
rustc_query_impl Auto merge of #83214 - cjgillot:dep-map, r=michaelwoerister 2021-09-06 23:58:16 +00:00
rustc_query_system Remove redundant Span in QueryJobInfo 2021-09-01 11:10:58 -07:00
rustc_resolve Move confused_type_with_std_module to ResolverOutputs 2021-09-06 11:20:59 -05:00
rustc_save_analysis Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00
rustc_serialize Fix more “a”/“an” typos 2021-08-22 16:35:29 +02:00
rustc_session Revert "Remove optimization_fuel_crate from Session" 2021-09-08 17:36:41 +02:00
rustc_span Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
rustc_symbol_mangling Rollup merge of #85534 - csmoe:demagnle-assert, r=michaelwoerister 2021-08-29 16:25:28 +02:00
rustc_target Auto merge of #88499 - eddyb:layout-off, r=nagisa 2021-09-05 16:14:41 +00:00
rustc_trait_selection Use index newtyping for TyVid 2021-09-06 22:38:06 -04:00
rustc_traits Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth 2021-08-27 01:07:17 +00:00
rustc_ty_utils Auto merge of #88371 - Manishearth:rollup-pkkjsme, r=Manishearth 2021-08-27 01:07:17 +00:00
rustc_type_ir Use index newtyping for TyVid 2021-09-06 22:38:06 -04:00
rustc_typeck Bump stage0 compiler to 1.56 2021-09-08 20:51:05 -04:00