Borrow guard patterns for the body of the guard

This commit is contained in:
Eric Holk 2022-05-17 15:36:39 -07:00
parent 7db4c0277d
commit d08efdec1c
4 changed files with 57 additions and 26 deletions

View file

@ -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)]