rustc_utils/mir/
mutability.rs

1//! Utilities for [`Mutability`].
2
3use rustc_middle::mir::Mutability;
4
5pub trait MutabilityExt {
6  /// Returns true if `self` is equally or more permissive than `other`,
7  /// i.e. where `Not` is more permissive than `Mut`.
8  ///
9  /// This corresponds to the relation $\omega_1 \lesssim \omega_2$ in the Flowistry paper.
10  #[allow(clippy::wrong_self_convention)]
11  fn is_permissive_as(self, other: Self) -> bool;
12}
13
14impl MutabilityExt for Mutability {
15  fn is_permissive_as(self, other: Self) -> bool {
16    !matches!((self, other), (Mutability::Mut, Mutability::Not))
17  }
18}
19
20#[test]
21fn test_mutability() {
22  use Mutability::*;
23  let truth_table = [
24    (Not, Not, true),
25    (Not, Mut, true),
26    (Mut, Not, false),
27    (Mut, Mut, true),
28  ];
29  for (l, r, v) in truth_table {
30    assert_eq!(l.is_permissive_as(r), v);
31  }
32}