rustc_ast_ir/
lib.rs

1// tidy-alphabetical-start
2#![cfg_attr(feature = "nightly", allow(internal_features))]
3#![cfg_attr(feature = "nightly", feature(never_type))]
4#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
5#![warn(unreachable_pub)]
6// tidy-alphabetical-end
7
8#[cfg(feature = "nightly")]
9use rustc_macros::{Decodable, Encodable, HashStable_NoContext};
10
11pub mod visit;
12
13/// The movability of a coroutine / closure literal:
14/// whether a coroutine contains self-references, causing it to be `!Unpin`.
15#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
16#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
17pub enum Movability {
18    /// May contain self-references, `!Unpin`.
19    Static,
20    /// Must not contain self-references, `Unpin`.
21    Movable,
22}
23
24#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
25#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
26pub enum Mutability {
27    // N.B. Order is deliberate, so that Not < Mut
28    Not,
29    Mut,
30}
31
32impl Mutability {
33    pub fn invert(self) -> Self {
34        match self {
35            Mutability::Mut => Mutability::Not,
36            Mutability::Not => Mutability::Mut,
37        }
38    }
39
40    /// Returns `""` (empty string) or `"mut "` depending on the mutability.
41    pub fn prefix_str(self) -> &'static str {
42        match self {
43            Mutability::Mut => "mut ",
44            Mutability::Not => "",
45        }
46    }
47
48    /// Returns `"&"` or `"&mut "` depending on the mutability.
49    pub fn ref_prefix_str(self) -> &'static str {
50        match self {
51            Mutability::Not => "&",
52            Mutability::Mut => "&mut ",
53        }
54    }
55
56    /// Returns `"const"` or `"mut"` depending on the mutability.
57    pub fn ptr_str(self) -> &'static str {
58        match self {
59            Mutability::Not => "const",
60            Mutability::Mut => "mut",
61        }
62    }
63
64    /// Returns `""` (empty string) or `"mutably "` depending on the mutability.
65    pub fn mutably_str(self) -> &'static str {
66        match self {
67            Mutability::Not => "",
68            Mutability::Mut => "mutably ",
69        }
70    }
71
72    /// Return `true` if self is mutable
73    pub fn is_mut(self) -> bool {
74        matches!(self, Self::Mut)
75    }
76
77    /// Return `true` if self is **not** mutable
78    pub fn is_not(self) -> bool {
79        matches!(self, Self::Not)
80    }
81}
82
83#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
84#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
85pub enum Pinnedness {
86    Not,
87    Pinned,
88}