rust/compiler/rustc_passes/src
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
..
liveness Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
check_attr.rs Update invalid crate attributes, add help message 2021-12-03 18:38:32 +00:00
check_const.rs Allow features like const_try in d_m_b_i_c 2021-11-24 15:57:44 +08:00
dead.rs only check for automatically_derived on impls, not individual methods 2021-10-02 09:53:51 -04:00
diagnostic_items.rs Introduce get_diagnostic_name 2021-10-06 08:40:28 -05:00
entry.rs Avoid more invocations of hir_crate query. 2021-09-29 23:16:47 +02:00
hir_id_validator.rs Do not store visibility in *ItemRef. 2021-09-20 00:29:53 +02:00
hir_stats.rs Rename walk_crate. 2021-09-02 19:23:11 +02:00
intrinsicck.rs make #[target_feature] work with asm register classes 2021-10-07 15:42:18 -04:00
lang_items.rs Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
layout_test.rs Avoid more invocations of hir_crate query. 2021-09-29 23:16:47 +02:00
lib.rs Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
lib_features.rs Remove eval_always for lib_features. 2021-11-28 21:13:36 +01:00
liveness.rs let-else: add hir::Let and type check it like a hir::Local 2021-12-13 14:02:19 +11:00
loops.rs Do not suggest using a break label when one is already present 2021-01-21 21:43:29 -08:00
naked_functions.rs Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
reachable.rs Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
region.rs Fix rebase and clippy tests 2021-12-13 17:09:16 +00:00
stability.rs Remove eval_always for lib_features. 2021-11-28 21:13:36 +01:00
upvars.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
weak_lang_items.rs Suggest to specify a target triple when eh_personality lang item is missing 2021-12-14 00:04:15 +11:00