about summary refs log tree commit diff
path: root/compiler/rustc_middle
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2022-11-26 17:47:23 +0100
committerGitHub <noreply@github.com>2022-11-26 17:47:23 +0100
commita2e485c25c5c9f3ca30a1ab6162dc322d6eb8800 (patch)
tree71f4fcb4b1cda40d24b76f6f9cf136b5b84ceec4 /compiler/rustc_middle
parent579c993b35a02dc439b74bba18b0a14f77911c95 (diff)
parente143fa21566b4ff32fe8a140642d8037a03a237f (diff)
downloadrust-a2e485c25c5c9f3ca30a1ab6162dc322d6eb8800.tar.gz
rust-a2e485c25c5c9f3ca30a1ab6162dc322d6eb8800.zip
Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors
Use the power of adding helper function to simplify code w/ `Mutability`

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_middle')
-rw-r--r--compiler/rustc_middle/src/ty/adjustment.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs
index b8e6f0258d0..7036c4a7b27 100644
--- a/compiler/rustc_middle/src/ty/adjustment.rs
+++ b/compiler/rustc_middle/src/ty/adjustment.rs
@@ -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 {