about summary refs log tree commit diff
path: root/compiler/rustc_hir
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2024-12-13 12:19:46 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2024-12-14 20:31:07 +0000
commit8a4e5d7444c4d43097c2ca0d1b8e64be9dbeddfa (patch)
treef9ca6a3756cf0bb0e520702d99f2064231e95223 /compiler/rustc_hir
parent3a64bef2ba54542d3440634602e088c2597d9ed2 (diff)
downloadrust-8a4e5d7444c4d43097c2ca0d1b8e64be9dbeddfa.tar.gz
rust-8a4e5d7444c4d43097c2ca0d1b8e64be9dbeddfa.zip
Add some convenience helper methods on `hir::Safety`
Diffstat (limited to 'compiler/rustc_hir')
-rw-r--r--compiler/rustc_hir/src/hir.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 365e4cbb556..b6cdf224fb2 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -3401,6 +3401,19 @@ impl Safety {
             Self::Safe => "",
         }
     }
+
+    #[inline]
+    pub fn is_unsafe(self) -> bool {
+        !self.is_safe()
+    }
+
+    #[inline]
+    pub fn is_safe(self) -> bool {
+        match self {
+            Self::Unsafe => false,
+            Self::Safe => true,
+        }
+    }
 }
 
 impl fmt::Display for Safety {
@@ -3445,7 +3458,7 @@ impl FnHeader {
     }
 
     pub fn is_unsafe(&self) -> bool {
-        matches!(&self.safety, Safety::Unsafe)
+        self.safety.is_unsafe()
     }
 }