]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #87688 - camsteffen:let-else, r=cjgillot
authorbors <bors@rust-lang.org>
Wed, 1 Sep 2021 01:02:42 +0000 (01:02 +0000)
committerbors <bors@rust-lang.org>
Wed, 1 Sep 2021 01:02:42 +0000 (01:02 +0000)
commitc2a408840ad18f74280805535f0b7193528ff3df
tree5d8815373247ba476a90946678a2c19e713f8780
parenta3956106d12cebec91be0637759e29ab6908b4cd
parent3ff1d6bbf427cfb3d504092c93f261b49577170e
Auto merge of #87688 - camsteffen:let-else, r=cjgillot

Introduce `let...else`

Tracking issue: #87335

The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect.

Overall, I believe this PR is feature-complete with regard to the RFC.
compiler/rustc_ast_lowering/src/lib.rs