// tidy-alphabetical-start #![cfg_attr(feature = "nightly", allow(internal_features))] #![cfg_attr(feature = "nightly", feature(never_type))] #![cfg_attr(feature = "nightly", feature(rustc_attrs))] // tidy-alphabetical-end #[cfg(feature = "nightly")] use rustc_macros::{Decodable, Encodable, HashStable_NoContext}; pub mod visit; /// The movability of a coroutine / closure literal: /// whether a coroutine contains self-references, causing it to be `!Unpin`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] pub enum Movability { /// May contain self-references, `!Unpin`. Static, /// Must not contain self-references, `Unpin`. Movable, } #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] pub enum Mutability { // N.B. Order is deliberate, so that Not < Mut Not, Mut, } impl Mutability { pub fn invert(self) -> Self { match self { Mutability::Mut => Mutability::Not, Mutability::Not => Mutability::Mut, } } /// Returns `""` (empty string) or `"mut "` depending on the mutability. pub fn prefix_str(self) -> &'static str { match self { Mutability::Mut => "mut ", Mutability::Not => "", } } /// Returns `"&"` or `"&mut "` depending on the mutability. pub fn ref_prefix_str(self) -> &'static str { match self { Mutability::Not => "&", Mutability::Mut => "&mut ", } } /// Returns `"const"` or `"mut"` depending on the mutability. pub fn ptr_str(self) -> &'static str { match self { Mutability::Not => "const", Mutability::Mut => "mut", } } /// Returns `""` (empty string) or `"mutably "` depending on the mutability. pub fn mutably_str(self) -> &'static str { match self { Mutability::Not => "", Mutability::Mut => "mutably ", } } /// Return `true` if self is mutable pub fn is_mut(self) -> bool { matches!(self, Self::Mut) } /// Return `true` if self is **not** mutable pub fn is_not(self) -> bool { matches!(self, Self::Not) } }