//! Built-in attributes and `cfg` flag gating.
-use AttributeType::*;
use AttributeGate::*;
+use AttributeType::*;
use crate::{Features, Stability};
-use rustc_data_structures::fx::FxHashMap;
-use syntax_pos::symbol::{Symbol, sym};
use lazy_static::lazy_static;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_span::symbol::{sym, Symbol};
type GateFn = fn(&Features) -> bool;
macro_rules! cfg_fn {
($field: ident) => {
- (|features| { features.$field }) as GateFn
- }
+ (|features| features.$field) as GateFn
+ };
}
pub type GatedCfg = (Symbol, Symbol, GateFn);
impl std::fmt::Debug for AttributeGate {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match *self {
- Self::Gated(ref stab, name, expl, _) =>
- write!(fmt, "Gated({:?}, {}, {})", stab, name, expl),
- Self::Ungated => write!(fmt, "Ungated")
+ Self::Gated(ref stab, name, expl, _) => {
+ write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
+ }
+ Self::Ungated => write!(fmt, "Ungated"),
}
}
}
macro_rules! rustc_attr {
(TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => {
rustc_attr!(
- $attr, $typ, $tpl,
- concat!("the `#[", stringify!($attr), "]` attribute is just used for rustc unit tests \
+ $attr,
+ $typ,
+ $tpl,
+ concat!(
+ "the `#[",
+ stringify!($attr),
+ "]` attribute is just used for rustc unit tests \
and will never be stable",
),
)
};
($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
- (sym::$attr, $typ, $tpl,
- Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)))
+ (
+ sym::$attr,
+ $typ,
+ $tpl,
+ Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
+ )
};
}
macro_rules! experimental {
($attr:ident) => {
concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
- }
+ };
}
const IMPL_DETAIL: &str = "internal implementation detail";
pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);
/// Attributes that have a special meaning to rustc or rustdoc.
+#[rustfmt::skip]
pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================
// Stable attributes:
"the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
which contains compiler-rt intrinsics and will never be stable",
),
- gated!(
- sanitizer_runtime, Whitelisted, template!(Word),
- "the `#[sanitizer_runtime]` attribute is used to identify crates that contain the runtime \
- of a sanitizer and will never be stable",
- ),
gated!(
profiler_runtime, Whitelisted, template!(Word),
"the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \