mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 03:57:37 +00:00

We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
81 lines
2.3 KiB
Rust
81 lines
2.3 KiB
Rust
// 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)
|
|
}
|
|
}
|