about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-11-09 17:44:11 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-11-10 12:21:05 +0100
commited640c6a27aca3b2446ab8d6f00df0a2d78f1192 (patch)
tree16c570be6f3cdb3cb4d20dde9588d59d00ed502b /src/libsyntax
parent57a5f92bef4b459005920f1aeff05a52c7e356b0 (diff)
downloadrust-ed640c6a27aca3b2446ab8d6f00df0a2d78f1192.tar.gz
rust-ed640c6a27aca3b2446ab8d6f00df0a2d78f1192.zip
Merge hir::Mutability into ast::Mutability.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index b57d2238991..b0f83f03f62 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -733,6 +733,30 @@ pub enum Mutability {
     Immutable,
 }
 
+impl Mutability {
+    /// Returns `MutMutable` only if both `self` and `other` are mutable.
+    pub fn and(self, other: Self) -> Self {
+        match self {
+            Mutability::Mutable => other,
+            Mutability::Immutable => Mutability::Immutable,
+        }
+    }
+
+    pub fn invert(self) -> Self {
+        match self {
+            Mutability::Mutable => Mutability::Immutable,
+            Mutability::Immutable => Mutability::Mutable,
+        }
+    }
+
+    pub fn prefix_str(&self) -> &'static str {
+        match self {
+            Mutability::Mutable => "mut ",
+            Mutability::Immutable => "",
+        }
+    }
+}
+
 #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
 pub enum BinOpKind {
     /// The `+` operator (addition)