rustc_utils/mir/
mutability.rs1use rustc_middle::mir::Mutability;
4
5pub trait MutabilityExt {
6 #[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}