1
Fork 0

Simplify creation of AutoBorrowMutability

This commit is contained in:
Maybe Waffle 2022-11-23 19:24:47 +00:00
parent 6486ba94a3
commit f9a332a48c
5 changed files with 34 additions and 48 deletions

View file

@ -159,6 +159,18 @@ pub enum AutoBorrowMutability {
Not,
}
impl AutoBorrowMutability {
/// Creates an `AutoBorrowMutability` from a mutability and allowance of two phase borrows.
///
/// Note that when `mutbl.is_not()`, `allow_two_phase_borrow` is ignored
pub fn new(mutbl: hir::Mutability, allow_two_phase_borrow: AllowTwoPhase) -> Self {
match mutbl {
hir::Mutability::Not => Self::Not,
hir::Mutability::Mut => Self::Mut { allow_two_phase_borrow },
}
}
}
impl From<AutoBorrowMutability> for hir::Mutability {
fn from(m: AutoBorrowMutability) -> Self {
match m {