rust/compiler
bors dde825db46 Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
..
rustc
rustc_apfloat Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_arena Add some comments. 2021-11-19 07:52:59 +11:00
rustc_ast Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr 2021-12-15 03:28:55 +00:00
rustc_ast_lowering Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00
rustc_ast_passes Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
rustc_ast_pretty Rollup merge of #91625 - est31:remove_indexes, r=oli-obk 2021-12-10 22:40:36 +01:00
rustc_attr re-format with new rustfmt 2021-11-30 13:08:41 -05:00
rustc_borrowck Remove in_band_lifetimes from borrowck 2021-12-15 08:39:21 +01:00
rustc_builtin_macros Rollup merge of #91172 - Ethiraric:ethiraric/fix90979, r=petrochenkov 2021-12-16 17:23:07 +01:00
rustc_codegen_cranelift Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk 2021-12-15 01:28:06 +01:00
rustc_codegen_gcc Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk 2021-12-15 01:28:06 +01:00
rustc_codegen_llvm Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm 2021-12-15 01:28:08 +01:00
rustc_codegen_ssa Rollup merge of #91885 - LegionMammal978:less-inband-codegen_ssa, r=workingjubilee 2021-12-15 10:56:59 +01:00
rustc_const_eval Auto merge of #91945 - matthiaskrgr:rollup-jszf9zp, r=matthiaskrgr 2021-12-15 03:28:55 +00:00
rustc_data_structures Auto merge of #91549 - fee1-dead:const_env, r=spastorino 2021-12-12 22:15:32 +00:00
rustc_driver fix clippy::single_char_pattern perf findings 2021-12-14 12:40:28 +01:00
rustc_error_codes Clarify and tidy up explanation of E0038 2021-11-30 09:25:17 -08:00
rustc_errors Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_expand Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, r=jackh726,pnkfelix 2021-12-15 08:36:19 +01:00
rustc_feature Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
rustc_fs_util
rustc_graphviz fix clippy::single_char_pattern perf findings 2021-12-14 12:40:28 +01:00
rustc_hir Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00
rustc_hir_pretty Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00
rustc_incremental Rollup merge of #91625 - est31:remove_indexes, r=oli-obk 2021-12-10 22:40:36 +01:00
rustc_index Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_infer Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_interface Rollup merge of #91880 - matthiaskrgr:clippy_perf_dec, r=jyn514 2021-12-15 10:56:58 +01:00
rustc_lexer Auto merge of #91393 - Julian-Wollersberger:lexer_optimization, r=petrochenkov 2021-12-03 13:20:14 +00:00
rustc_lint Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm 2021-12-15 01:28:08 +01:00
rustc_lint_defs Rollup merge of #91172 - Ethiraric:ethiraric/fix90979, r=petrochenkov 2021-12-16 17:23:07 +01:00
rustc_llvm Auto merge of #91284 - t6:freebsd-riscv64, r=Amanieu 2021-12-06 03:51:05 +00:00
rustc_macros Query modifier 2021-12-12 12:35:00 +08:00
rustc_metadata Rollup merge of #92001 - fee1-dead:dmbic-xcrate-fix, r=oli-obk 2021-12-16 17:23:13 +01:00
rustc_middle Auto merge of #91672 - b-naber:merge-normalize-erasing-regions-queries, r=jackh726 2021-12-17 02:03:10 +00:00
rustc_mir_build Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00
rustc_mir_dataflow Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_mir_transform Rollup merge of #91880 - matthiaskrgr:clippy_perf_dec, r=jyn514 2021-12-15 10:56:58 +01:00
rustc_monomorphize
rustc_parse Auto merge of #91962 - matthiaskrgr:rollup-2g082jw, r=matthiaskrgr 2021-12-15 12:41:42 +00:00
rustc_parse_format
rustc_passes Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00
rustc_plugin_impl replace dynamic library module with libloading 2021-12-06 12:03:47 -05:00
rustc_privacy Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
rustc_query_impl Query modifier 2021-12-12 12:35:00 +08:00
rustc_query_system Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_resolve Auto merge of #89836 - pierwill:fix-85142-crate-hash, r=wesleywiser 2021-12-16 02:21:30 +00:00
rustc_save_analysis Rollup merge of #91880 - matthiaskrgr:clippy_perf_dec, r=jyn514 2021-12-15 10:56:58 +01:00
rustc_serialize Auto merge of #91626 - klensy:json-less-alloc, r=petrochenkov 2021-12-13 07:30:38 +00:00
rustc_session fix clippy::single_char_pattern perf findings 2021-12-14 12:40:28 +01:00
rustc_span Auto merge of #89836 - pierwill:fix-85142-crate-hash, r=wesleywiser 2021-12-16 02:21:30 +00:00
rustc_symbol_mangling Remove in_band_lifetimes from rustc_symbol_mangling 2021-12-15 22:02:25 +00:00
rustc_target Revert "Set MACOSX_DEPLOYMENT_TARGET env var to default for linking if not set." 2021-12-13 21:31:48 +01:00
rustc_trait_selection Rollup merge of #91904 - SylvanB:remove_in_band_lifetimes_rustc_trait_selection, r=petrochenkov 2021-12-16 10:12:42 +01:00
rustc_traits get rid of normalize_generic_arg... queries 2021-12-13 23:05:25 +01:00
rustc_ty_utils Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk" 2021-12-12 12:34:46 +08:00
rustc_type_ir Fix HashStable implementation on InferTy 2021-12-13 20:36:17 -08:00
rustc_typeck Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa 2021-12-17 22:12:34 +00:00