Files
rust/tests/ui
bors af1eea3f0a 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
..
2021-12-13 14:02:41 +11:00
2021-08-11 14:21:33 +00:00
2021-12-13 00:00:51 +00:00
2021-12-13 00:00:51 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-06-18 16:11:32 +08:00
2021-06-18 16:11:32 +08:00
2021-06-18 16:11:32 +08:00
2020-01-07 18:38:12 +09:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-07 18:38:12 +09:00
2019-12-21 16:20:30 +01:00
2021-08-11 14:21:33 +00:00
2021-12-13 00:00:51 +00:00
2021-12-13 00:00:51 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2019-11-07 17:11:06 +01:00
2019-11-07 17:11:06 +01:00
2019-11-07 17:11:06 +01:00
2019-11-07 17:11:06 +01:00
2019-11-07 17:11:06 +01:00
2020-01-12 19:54:17 +08:00
2020-01-12 19:54:17 +08:00
2020-02-23 22:36:15 -08:00
2021-08-11 14:21:33 +00:00
2021-12-13 17:09:16 +00:00
2020-01-31 20:21:10 +01:00
2020-04-20 15:47:08 -04:00
2020-01-07 18:38:12 +09:00
2019-12-24 03:06:52 +07:00
2019-12-24 03:06:52 +07:00
2020-01-04 11:20:11 -06:00
2020-01-04 11:20:11 -06:00
2019-10-15 09:58:11 +02:00
2020-01-26 07:01:16 +09:00
2020-01-07 18:38:12 +09:00
2019-08-01 22:20:08 +09:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-14 08:32:33 +09:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2019-10-15 09:58:11 +02:00
2021-08-11 14:21:33 +00:00
2020-01-07 18:38:12 +09:00
2020-04-23 16:30:06 -07:00
2021-08-11 14:21:33 +00:00
2020-04-26 18:00:51 +03:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-07 18:38:12 +09:00
2019-12-31 09:22:35 -08:00
2021-08-11 14:21:33 +00:00
2021-06-04 08:05:54 -04:00
2021-12-13 00:00:51 +00:00
2021-12-13 00:00:51 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-26 07:01:16 +09:00
2020-01-07 18:38:12 +09:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2019-12-18 18:59:43 +02:00
2020-03-20 22:52:53 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-20 10:56:02 +09:00
2019-10-15 09:58:11 +02:00
2019-10-15 09:58:11 +02:00
2019-11-10 15:52:59 +02:00
2021-12-12 12:34:21 +00:00
2021-12-12 12:34:21 +00:00
2021-07-27 16:26:50 -04:00
2021-07-27 16:26:50 -04:00
2019-11-25 18:12:52 +03:00
2019-11-25 18:12:52 +03:00
2020-01-07 18:38:12 +09:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2019-12-27 22:07:55 +09:00
2019-12-27 22:07:55 +09:00
2021-03-03 11:23:29 +01:00
2021-08-11 14:21:33 +00:00
2019-08-14 19:34:50 +02:00
2019-08-14 19:34:50 +02:00
2019-08-14 19:35:17 +02:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2020-01-07 18:38:12 +09:00
2020-03-29 22:22:36 +02:00
2020-03-10 18:00:37 -04:00
2020-03-10 18:00:37 -04:00
2019-05-08 09:24:24 +02:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2021-08-11 14:21:33 +00:00
2019-10-02 22:38:00 +07:00