Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
Implement if-let match guards Implements rust-lang/rfcs#2294 (tracking issue: #51114). I probably should do a few more things before this can be merged: - [x] Add tests (added basic tests, more advanced tests could be done in the future?) - [x] Add lint for exhaustive if-let guard (comparable to normal if-let statements) - [x] Fix clippy However since this is a nightly feature maybe it's fine to land this and do those steps in follow-up PRs. Thanks a lot `@matthewjasper` ❤️ for helping me with lowering to MIR! Would you be interested in reviewing this? r? `@ghost` for now
This commit is contained in:
commit
1e1ba7c936
27 changed files with 360 additions and 81 deletions
|
@ -1160,6 +1160,7 @@ pub struct Arm<'hir> {
|
|||
#[derive(Debug, HashStable_Generic)]
|
||||
pub enum Guard<'hir> {
|
||||
If(&'hir Expr<'hir>),
|
||||
IfLet(&'hir Pat<'hir>, &'hir Expr<'hir>),
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
|
@ -1721,6 +1722,8 @@ pub enum MatchSource {
|
|||
IfDesugar { contains_else_clause: bool },
|
||||
/// An `if let _ = _ { .. }` (optionally with `else { .. }`).
|
||||
IfLetDesugar { contains_else_clause: bool },
|
||||
/// An `if let _ = _ => { .. }` match guard.
|
||||
IfLetGuardDesugar,
|
||||
/// A `while _ { .. }` (which was desugared to a `loop { match _ { .. } }`).
|
||||
WhileDesugar,
|
||||
/// A `while let _ = _ { .. }` (which was desugared to a
|
||||
|
@ -1739,7 +1742,7 @@ impl MatchSource {
|
|||
use MatchSource::*;
|
||||
match self {
|
||||
Normal => "match",
|
||||
IfDesugar { .. } | IfLetDesugar { .. } => "if",
|
||||
IfDesugar { .. } | IfLetDesugar { .. } | IfLetGuardDesugar => "if",
|
||||
WhileDesugar | WhileLetDesugar => "while",
|
||||
ForLoopDesugar => "for",
|
||||
TryDesugar => "?",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue