mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
72 lines
2.0 KiB
Rust
72 lines
2.0 KiB
Rust
#![cfg_attr(feature = "nightly", feature(never_type))]
|
|
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
|
|
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
|
|
|
#[cfg(feature = "nightly")]
|
|
#[macro_use]
|
|
extern crate rustc_macros;
|
|
|
|
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 `""` (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)
|
|
}
|
|
}
|