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.
This commit is contained in:
commit
c2a408840a
59 changed files with 901 additions and 232 deletions
|
@ -1097,6 +1097,7 @@ pub enum DesugaringKind {
|
|||
Async,
|
||||
Await,
|
||||
ForLoop(ForLoopLoc),
|
||||
LetElse,
|
||||
}
|
||||
|
||||
/// A location in the desugaring of a `for` loop
|
||||
|
@ -1117,6 +1118,7 @@ impl DesugaringKind {
|
|||
DesugaringKind::TryBlock => "`try` block",
|
||||
DesugaringKind::OpaqueTy => "`impl Trait`",
|
||||
DesugaringKind::ForLoop(_) => "`for` loop",
|
||||
DesugaringKind::LetElse => "`let...else`",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -744,6 +744,7 @@ symbols! {
|
|||
le,
|
||||
len,
|
||||
let_chains,
|
||||
let_else,
|
||||
lhs,
|
||||
lib,
|
||||
libc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue