Borrow guard patterns for the body of the guard
This commit is contained in:
parent
7db4c0277d
commit
d08efdec1c
4 changed files with 57 additions and 26 deletions
|
@ -1323,6 +1323,20 @@ pub enum Guard<'hir> {
|
|||
IfLet(&'hir Let<'hir>),
|
||||
}
|
||||
|
||||
impl<'hir> Guard<'hir> {
|
||||
/// Returns the body of the guard
|
||||
///
|
||||
/// In other words, returns the e in either of the following:
|
||||
///
|
||||
/// - `if e`
|
||||
/// - `if let x = e`
|
||||
pub fn body(&self) -> &'hir Expr<'hir> {
|
||||
match self {
|
||||
Guard::If(e) | Guard::IfLet(_, e) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct ExprField<'hir> {
|
||||
#[stable_hasher(ignore)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue