2019-08-22 18:32:31 +02:00
//! Built-in attributes and `cfg` flag gating.
2022-06-16 19:39:39 +04:00
use std ::sync ::LazyLock ;
2024-07-29 08:13:50 +10:00
2021-09-05 16:30:37 -07:00
use AttributeDuplicates ::* ;
2019-08-22 18:32:31 +02:00
use AttributeGate ::* ;
2019-12-24 17:44:51 -05:00
use AttributeType ::* ;
2025-06-20 09:49:15 +02:00
use rustc_attr_data_structures ::EncodeCrossCrate ;
2019-12-24 17:44:51 -05:00
use rustc_data_structures ::fx ::FxHashMap ;
2025-04-12 19:58:19 +02:00
use rustc_span ::edition ::Edition ;
2024-12-13 10:29:23 +11:00
use rustc_span ::{ Symbol , sym } ;
2019-08-22 18:32:31 +02:00
2025-06-06 11:11:42 +02:00
use crate ::Features ;
2019-11-30 02:34:18 +01:00
2019-08-22 18:37:28 +02:00
type GateFn = fn ( & Features ) -> bool ;
2019-11-30 01:57:53 +01:00
pub type GatedCfg = ( Symbol , Symbol , GateFn ) ;
2019-08-22 18:37:28 +02:00
/// `cfg(...)`'s that are feature gated.
2019-11-30 01:57:53 +01:00
const GATED_CFGS : & [ GatedCfg ] = & [
2019-08-22 18:32:31 +02:00
// (name in cfg, feature, function to check if the feature is enabled)
2024-10-23 07:29:25 +01:00
( sym ::overflow_checks , sym ::cfg_overflow_checks , Features ::cfg_overflow_checks ) ,
( sym ::ub_checks , sym ::cfg_ub_checks , Features ::cfg_ub_checks ) ,
2024-12-02 20:35:13 +00:00
( sym ::contract_checks , sym ::cfg_contract_checks , Features ::cfg_contract_checks ) ,
2024-10-23 07:29:25 +01:00
( sym ::target_thread_local , sym ::cfg_target_thread_local , Features ::cfg_target_thread_local ) ,
2020-09-20 12:09:22 +02:00
(
sym ::target_has_atomic_equal_alignment ,
2022-02-09 18:14:35 +00:00
sym ::cfg_target_has_atomic_equal_alignment ,
2024-10-23 07:29:25 +01:00
Features ::cfg_target_has_atomic_equal_alignment ,
) ,
(
sym ::target_has_atomic_load_store ,
sym ::cfg_target_has_atomic ,
Features ::cfg_target_has_atomic ,
) ,
( sym ::sanitize , sym ::cfg_sanitize , Features ::cfg_sanitize ) ,
( sym ::version , sym ::cfg_version , Features ::cfg_version ) ,
( sym ::relocation_model , sym ::cfg_relocation_model , Features ::cfg_relocation_model ) ,
( sym ::sanitizer_cfi_generalize_pointers , sym ::cfg_sanitizer_cfi , Features ::cfg_sanitizer_cfi ) ,
( sym ::sanitizer_cfi_normalize_integers , sym ::cfg_sanitizer_cfi , Features ::cfg_sanitizer_cfi ) ,
2024-04-14 13:52:58 +01:00
// this is consistent with naming of the compiler flag it's for
2024-10-23 07:29:25 +01:00
( sym ::fmt_debug , sym ::fmt_debug , Features ::fmt_debug ) ,
2024-10-17 13:00:35 +02:00
( sym ::emscripten_wasm_eh , sym ::cfg_emscripten_wasm_eh , Features ::cfg_emscripten_wasm_eh ) ,
2025-04-24 22:11:23 +00:00
(
sym ::target_has_reliable_f16 ,
sym ::cfg_target_has_reliable_f16_f128 ,
Features ::cfg_target_has_reliable_f16_f128 ,
) ,
(
sym ::target_has_reliable_f16_math ,
sym ::cfg_target_has_reliable_f16_f128 ,
Features ::cfg_target_has_reliable_f16_f128 ,
) ,
(
sym ::target_has_reliable_f128 ,
sym ::cfg_target_has_reliable_f16_f128 ,
Features ::cfg_target_has_reliable_f16_f128 ,
) ,
(
sym ::target_has_reliable_f128_math ,
sym ::cfg_target_has_reliable_f16_f128 ,
Features ::cfg_target_has_reliable_f16_f128 ,
) ,
2019-08-22 18:32:31 +02:00
] ;
2019-11-30 01:57:53 +01:00
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
pub fn find_gated_cfg ( pred : impl Fn ( Symbol ) -> bool ) -> Option < & 'static GatedCfg > {
GATED_CFGS . iter ( ) . find ( | ( cfg_sym , .. ) | pred ( * cfg_sym ) )
2019-08-22 18:32:31 +02:00
}
// If you change this, please modify `src/doc/unstable-book` as well. You must
// move that documentation into the relevant place in the other docs, and
// remove the chapter on the flag.
#[ derive(Copy, Clone, PartialEq, Debug) ]
pub enum AttributeType {
/// Normal, builtin attribute that is consumed
/// by the compiler before the unused_attribute check
Normal ,
/// Builtin attribute that is only allowed at the crate level
CrateLevel ,
}
2024-04-20 23:54:50 -05:00
#[ derive(Copy, Clone, PartialEq, Debug) ]
pub enum AttributeSafety {
/// Normal attribute that does not need `#[unsafe(...)]`
Normal ,
2025-04-12 19:58:19 +02:00
/// Unsafe attribute that requires safety obligations to be discharged.
///
/// An error is emitted when `#[unsafe(...)]` is omitted, except when the attribute's edition
/// is less than the one stored in `unsafe_since`. This handles attributes that were safe in
/// earlier editions, but become unsafe in later ones.
Unsafe { unsafe_since : Option < Edition > } ,
2024-04-20 23:54:50 -05:00
}
2025-05-18 18:35:13 +02:00
#[ derive(Clone, Debug, Copy) ]
2019-08-22 18:32:31 +02:00
pub enum AttributeGate {
2025-05-18 18:35:13 +02:00
/// A gated attribute which requires a feature gate to be enabled.
Gated {
/// The feature gate, for example `#![feature(rustc_attrs)]` for rustc_* attributes.
feature : Symbol ,
/// The error message displayed when an attempt is made to use the attribute without its feature gate.
message : & 'static str ,
/// Check function to be called during the `PostExpansionVisitor` pass.
check : fn ( & Features ) -> bool ,
/// Notes to be displayed when an attempt is made to use the attribute without its feature gate.
notes : & 'static [ & 'static str ] ,
} ,
2019-08-22 18:32:31 +02:00
/// Ungated attribute, can be used on all release channels
Ungated ,
}
2025-03-04 14:17:06 +01:00
// FIXME(jdonszelmann): move to rustc_attr_data_structures
2019-11-30 00:56:46 +01:00
/// A template that the attribute input must match.
/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
2019-12-30 21:38:43 +03:00
#[ derive(Clone, Copy, Default) ]
2019-11-30 00:56:46 +01:00
pub struct AttributeTemplate {
2021-09-05 16:30:37 -07:00
/// If `true`, the attribute is allowed to be a bare word like `#[test]`.
2019-11-30 00:56:46 +01:00
pub word : bool ,
2021-09-05 16:30:37 -07:00
/// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`.
2019-11-30 00:56:46 +01:00
pub list : Option < & 'static str > ,
2024-06-20 17:44:11 +10:00
/// If non-empty, the attribute is allowed to take a list containing exactly
/// one of the listed words, like `#[coverage(off)]`.
pub one_of : & 'static [ Symbol ] ,
2021-09-05 16:30:37 -07:00
/// If `Some`, the attribute is allowed to be a name/value pair where the
/// value is a string, like `#[must_use = "reason"]`.
2019-11-30 00:56:46 +01:00
pub name_value_str : Option < & 'static str > ,
}
2025-03-04 14:17:06 +01:00
impl AttributeTemplate {
pub fn suggestions ( & self , inner : bool , name : impl std ::fmt ::Display ) -> Vec < String > {
let mut suggestions = vec! [ ] ;
let inner = if inner { " ! " } else { " " } ;
if self . word {
suggestions . push ( format! ( " # {inner} [ {name} ] " ) ) ;
}
if let Some ( descr ) = self . list {
suggestions . push ( format! ( " # {inner} [ {name} ( {descr} )] " ) ) ;
}
suggestions . extend ( self . one_of . iter ( ) . map ( | & word | format! ( " # {inner} [ {name} ( {word} )] " ) ) ) ;
if let Some ( descr ) = self . name_value_str {
suggestions . push ( format! ( " # {inner} [ {name} = \" {descr} \" ] " ) ) ;
}
suggestions . sort ( ) ;
suggestions
}
}
2021-09-05 16:30:37 -07:00
/// How to handle multiple duplicate attributes on the same item.
#[ derive(Clone, Copy, Default) ]
pub enum AttributeDuplicates {
/// Duplicates of this attribute are allowed.
///
/// This should only be used with attributes where duplicates have semantic
/// meaning, or some kind of "additive" behavior. For example, `#[warn(..)]`
/// can be specified multiple times, and it combines all the entries. Or use
/// this if there is validation done elsewhere.
#[ default ]
DuplicatesOk ,
/// Duplicates after the first attribute will be an unused_attribute warning.
///
/// This is usually used for "word" attributes, where they are used as a
/// boolean marker, like `#[used]`. It is not necessarily wrong that there
/// are duplicates, but the others should probably be removed.
WarnFollowing ,
/// Same as `WarnFollowing`, but only issues warnings for word-style attributes.
///
/// This is only for special cases, for example multiple `#[macro_use]` can
/// be warned, but multiple `#[macro_use(...)]` should not because the list
/// form has different meaning from the word form.
WarnFollowingWordOnly ,
/// Duplicates after the first attribute will be an error.
///
/// This should be used where duplicates would be ignored, but carry extra
/// meaning that could cause confusion. For example, `#[stable(since="1.0")]
/// #[stable(since="2.0")]`, which version should be used for `stable`?
ErrorFollowing ,
/// Duplicates preceding the last instance of the attribute will be an error.
///
/// This is the same as `ErrorFollowing`, except the last attribute is the
/// one that is "used". This is typically used in cases like codegen
/// attributes which usually only honor the last attribute.
ErrorPreceding ,
/// Duplicates after the first attribute will be an unused_attribute warning
/// with a note that this will be an error in the future.
///
/// This should be used for attributes that should be `ErrorFollowing`, but
/// because older versions of rustc silently accepted (and ignored) the
/// attributes, this is used to transition.
FutureWarnFollowing ,
/// Duplicates preceding the last instance of the attribute will be a
/// warning, with a note that this will be an error in the future.
///
/// This is the same as `FutureWarnFollowing`, except the last attribute is
/// the one that is "used". Ideally these can eventually migrate to
/// `ErrorPreceding`.
FutureWarnPreceding ,
}
2019-08-22 18:32:31 +02:00
/// A convenience macro for constructing attribute templates.
/// E.g., `template!(Word, List: "description")` means that the attribute
/// supports forms `#[attr]` and `#[attr(description)]`.
2025-03-04 14:17:06 +01:00
#[ macro_export ]
2019-08-22 18:32:31 +02:00
macro_rules ! template {
2025-03-04 14:17:06 +01:00
( Word ) = > { $crate ::template! ( @ true , None , & [ ] , None ) } ;
( List : $descr : expr ) = > { $crate ::template! ( @ false , Some ( $descr ) , & [ ] , None ) } ;
( OneOf : $one_of : expr ) = > { $crate ::template! ( @ false , None , $one_of , None ) } ;
( NameValueStr : $descr : expr ) = > { $crate ::template! ( @ false , None , & [ ] , Some ( $descr ) ) } ;
( Word , List : $descr : expr ) = > { $crate ::template! ( @ true , Some ( $descr ) , & [ ] , None ) } ;
( Word , NameValueStr : $descr : expr ) = > { $crate ::template! ( @ true , None , & [ ] , Some ( $descr ) ) } ;
2019-08-22 18:32:31 +02:00
( List : $descr1 : expr , NameValueStr : $descr2 : expr ) = > {
2025-03-04 14:17:06 +01:00
$crate ::template! ( @ false , Some ( $descr1 ) , & [ ] , Some ( $descr2 ) )
2019-08-22 18:32:31 +02:00
} ;
( Word , List : $descr1 : expr , NameValueStr : $descr2 : expr ) = > {
2025-03-04 14:17:06 +01:00
$crate ::template! ( @ true , Some ( $descr1 ) , & [ ] , Some ( $descr2 ) )
2019-08-22 18:32:31 +02:00
} ;
2025-03-04 14:17:06 +01:00
( @ $word : expr , $list : expr , $one_of : expr , $name_value_str : expr ) = > { $crate ::AttributeTemplate {
2024-06-20 17:44:11 +10:00
word : $word , list : $list , one_of : $one_of , name_value_str : $name_value_str
2019-08-22 18:32:31 +02:00
} } ;
}
2019-08-22 20:40:50 +02:00
macro_rules ! ungated {
2025-04-12 19:58:19 +02:00
( unsafe ( $edition :ident ) $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr $(, ) ? ) = > {
BuiltinAttribute {
name : sym ::$attr ,
encode_cross_crate : $encode_cross_crate ,
type_ : $typ ,
safety : AttributeSafety ::Unsafe { unsafe_since : Some ( Edition ::$edition ) } ,
template : $tpl ,
gate : Ungated ,
duplicates : $duplicates ,
}
} ;
2024-04-25 11:12:02 -05:00
( unsafe $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr $(, ) ? ) = > {
2021-09-05 16:30:37 -07:00
BuiltinAttribute {
name : sym ::$attr ,
2024-03-19 00:05:18 +08:00
encode_cross_crate : $encode_cross_crate ,
2021-09-05 16:30:37 -07:00
type_ : $typ ,
2025-04-12 19:58:19 +02:00
safety : AttributeSafety ::Unsafe { unsafe_since : None } ,
2024-04-20 23:54:50 -05:00
template : $tpl ,
gate : Ungated ,
duplicates : $duplicates ,
}
} ;
2024-04-25 11:12:02 -05:00
( $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr $(, ) ? ) = > {
2024-04-20 23:54:50 -05:00
BuiltinAttribute {
name : sym ::$attr ,
encode_cross_crate : $encode_cross_crate ,
type_ : $typ ,
2024-04-25 11:12:02 -05:00
safety : AttributeSafety ::Normal ,
2021-09-05 16:30:37 -07:00
template : $tpl ,
gate : Ungated ,
duplicates : $duplicates ,
}
2019-08-22 20:40:50 +02:00
} ;
}
macro_rules ! gated {
2025-05-18 18:35:13 +02:00
( unsafe $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr , $gate :ident , $message :expr $(, ) ? ) = > {
2021-11-12 20:15:14 +08:00
BuiltinAttribute {
name : sym ::$attr ,
2024-03-19 00:05:18 +08:00
encode_cross_crate : $encode_cross_crate ,
2021-11-12 20:15:14 +08:00
type_ : $typ ,
2025-04-12 19:58:19 +02:00
safety : AttributeSafety ::Unsafe { unsafe_since : None } ,
2021-11-12 20:15:14 +08:00
template : $tpl ,
2021-09-05 16:30:37 -07:00
duplicates : $duplicates ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::$gate ,
message : $message ,
check : Features ::$gate ,
notes : & [ ] ,
} ,
2021-11-12 20:15:14 +08:00
}
2019-08-22 20:40:50 +02:00
} ;
2025-05-18 18:35:13 +02:00
( unsafe $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr , $message :expr $(, ) ? ) = > {
2021-11-12 20:15:14 +08:00
BuiltinAttribute {
name : sym ::$attr ,
2024-03-19 00:05:18 +08:00
encode_cross_crate : $encode_cross_crate ,
2021-11-12 20:15:14 +08:00
type_ : $typ ,
2025-04-12 19:58:19 +02:00
safety : AttributeSafety ::Unsafe { unsafe_since : None } ,
2024-04-20 23:54:50 -05:00
template : $tpl ,
duplicates : $duplicates ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::$attr ,
message : $message ,
check : Features ::$attr ,
notes : & [ ] ,
} ,
2024-04-20 23:54:50 -05:00
}
} ;
2025-05-18 18:35:13 +02:00
( $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr , $gate :ident , $message :expr $(, ) ? ) = > {
2024-04-20 23:54:50 -05:00
BuiltinAttribute {
name : sym ::$attr ,
encode_cross_crate : $encode_cross_crate ,
type_ : $typ ,
2024-04-25 11:12:02 -05:00
safety : AttributeSafety ::Normal ,
2024-04-20 23:54:50 -05:00
template : $tpl ,
duplicates : $duplicates ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::$gate ,
message : $message ,
check : Features ::$gate ,
notes : & [ ] ,
} ,
2024-04-20 23:54:50 -05:00
}
} ;
2025-05-18 18:35:13 +02:00
( $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr , $message :expr $(, ) ? ) = > {
2024-04-20 23:54:50 -05:00
BuiltinAttribute {
name : sym ::$attr ,
encode_cross_crate : $encode_cross_crate ,
type_ : $typ ,
2024-04-25 11:12:02 -05:00
safety : AttributeSafety ::Normal ,
2021-11-12 20:15:14 +08:00
template : $tpl ,
2021-09-05 16:30:37 -07:00
duplicates : $duplicates ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::$attr ,
message : $message ,
check : Features ::$attr ,
notes : & [ ] ,
} ,
2021-11-12 20:15:14 +08:00
}
2019-08-22 20:40:50 +02:00
} ;
}
2019-08-22 19:37:04 +02:00
macro_rules ! rustc_attr {
2024-03-19 00:05:18 +08:00
( TEST , $attr :ident , $typ :expr , $tpl :expr , $duplicate :expr , $encode_cross_crate :expr $(, ) ? ) = > {
2019-08-22 19:37:04 +02:00
rustc_attr! (
2019-12-24 17:44:51 -05:00
$attr ,
$typ ,
$tpl ,
2021-09-05 16:30:37 -07:00
$duplicate ,
2024-03-19 00:05:18 +08:00
$encode_cross_crate ,
2019-12-24 17:44:51 -05:00
concat! (
" the `#[ " ,
stringify! ( $attr ) ,
2025-05-18 18:35:13 +02:00
" ]` attribute is used for rustc unit tests "
2019-08-22 19:37:04 +02:00
) ,
)
} ;
2025-05-18 18:35:13 +02:00
( $attr :ident , $typ :expr , $tpl :expr , $duplicates :expr , $encode_cross_crate :expr , $( $notes :expr ) , * $(, ) ? ) = > {
2021-11-12 20:15:14 +08:00
BuiltinAttribute {
name : sym ::$attr ,
2024-03-19 00:05:18 +08:00
encode_cross_crate : $encode_cross_crate ,
2021-11-12 20:15:14 +08:00
type_ : $typ ,
2024-04-20 23:54:50 -05:00
safety : AttributeSafety ::Normal ,
2021-11-12 20:15:14 +08:00
template : $tpl ,
2021-09-05 16:30:37 -07:00
duplicates : $duplicates ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::rustc_attrs ,
message : " use of an internal attribute " ,
check : Features ::rustc_attrs ,
notes : & [
concat! ( " the `#[ " ,
stringify! ( $attr ) ,
" ]` attribute is an internal implementation detail that will never be stable " ) ,
$( $notes ) , *
]
} ,
2021-11-12 20:15:14 +08:00
}
2019-08-22 19:37:04 +02:00
} ;
}
2019-08-22 23:30:59 +02:00
macro_rules ! experimental {
( $attr :ident ) = > {
concat! ( " the `#[ " , stringify! ( $attr ) , " ]` attribute is an experimental feature " )
2019-12-24 17:44:51 -05:00
} ;
2019-08-22 23:30:59 +02:00
}
2021-11-12 20:15:14 +08:00
pub struct BuiltinAttribute {
pub name : Symbol ,
2024-03-19 00:05:18 +08:00
/// Whether this attribute is encode cross crate.
2022-04-01 15:04:47 +02:00
///
2024-03-19 00:05:18 +08:00
/// If so, it is encoded in the crate metadata.
/// Otherwise, it can only be used in the local crate.
pub encode_cross_crate : EncodeCrossCrate ,
2021-11-12 20:15:14 +08:00
pub type_ : AttributeType ,
2024-04-20 23:54:50 -05:00
pub safety : AttributeSafety ,
2021-11-12 20:15:14 +08:00
pub template : AttributeTemplate ,
2021-09-05 16:30:37 -07:00
pub duplicates : AttributeDuplicates ,
2021-11-12 20:15:14 +08:00
pub gate : AttributeGate ,
}
2019-08-22 18:32:31 +02:00
2019-09-06 03:56:45 +01:00
/// Attributes that have a special meaning to rustc or rustdoc.
2019-12-24 17:44:51 -05:00
#[ rustfmt::skip ]
2025-01-28 17:38:22 +03:00
pub static BUILTIN_ATTRIBUTES : & [ BuiltinAttribute ] = & [
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Stable attributes:
// ==========================================================================
2020-03-06 12:13:55 +01:00
// Conditional compilation:
2024-03-19 00:05:18 +08:00
ungated! ( cfg , Normal , template! ( List : " predicate " ) , DuplicatesOk , EncodeCrossCrate ::Yes ) ,
ungated! ( cfg_attr , Normal , template! ( List : " predicate, attr1, attr2, ... " ) , DuplicatesOk , EncodeCrossCrate ::Yes ) ,
2019-08-22 18:32:31 +02:00
2019-08-22 23:30:59 +02:00
// Testing:
2024-02-23 17:23:01 +08:00
ungated! (
ignore , Normal , template! ( Word , NameValueStr : " reason " ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-02-23 17:23:01 +08:00
) ,
2019-08-22 23:30:59 +02:00
ungated! (
should_panic , Normal ,
2022-08-15 15:57:55 +08:00
template! ( Word , List : r #" expected = " reason " " #, NameValueStr : " reason " ) , FutureWarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
) ,
// FIXME(Centril): This can be used on stable but shouldn't.
2024-02-23 17:23:01 +08:00
ungated! (
reexport_test_harness_main , CrateLevel , template! ( NameValueStr : " name " ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-02-23 17:23:01 +08:00
) ,
2019-08-22 23:30:59 +02:00
// Macros:
2024-03-19 00:05:18 +08:00
ungated! ( automatically_derived , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) ,
2024-02-23 17:23:01 +08:00
ungated! (
macro_use , Normal , template! ( Word , List : " name1, name2, ... " ) , WarnFollowingWordOnly ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-02-23 17:23:01 +08:00
) ,
2024-03-19 00:05:18 +08:00
ungated! ( macro_escape , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) , // Deprecated synonym for `macro_use`.
ungated! (
macro_export , Normal , template! ( Word , List : " local_inner_macros " ) ,
WarnFollowing , EncodeCrossCrate ::Yes
) ,
ungated! ( proc_macro , Normal , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::No ) ,
2019-08-22 23:30:59 +02:00
ungated! (
2024-02-23 17:23:01 +08:00
proc_macro_derive , Normal , template! ( List : " TraitName, /*opt*/ attributes(name1, name2, ...) " ) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
) ,
2024-03-19 00:05:18 +08:00
ungated! ( proc_macro_attribute , Normal , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::No ) ,
2019-08-22 23:30:59 +02:00
// Lints:
2021-09-05 16:30:37 -07:00
ungated! (
2022-09-13 15:23:54 +02:00
warn , Normal , template! ( List : r #" lint1, lint2, ..., /*opt*/ reason = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No ,
2021-09-05 16:30:37 -07:00
) ,
ungated! (
2022-09-13 15:23:54 +02:00
allow , Normal , template! ( List : r #" lint1, lint2, ..., /*opt*/ reason = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No ,
2021-09-05 16:30:37 -07:00
) ,
2024-02-10 21:53:34 +00:00
ungated! (
expect , Normal , template! ( List : r #" lint1, lint2, ..., /*opt*/ reason = " .. . " " #) ,
DuplicatesOk , EncodeCrossCrate ::No ,
2021-08-06 23:18:16 +02:00
) ,
2021-09-05 16:30:37 -07:00
ungated! (
2022-09-13 15:23:54 +02:00
forbid , Normal , template! ( List : r #" lint1, lint2, ..., /*opt*/ reason = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No
2021-09-05 16:30:37 -07:00
) ,
ungated! (
2022-09-13 15:23:54 +02:00
deny , Normal , template! ( List : r #" lint1, lint2, ..., /*opt*/ reason = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No
) ,
ungated! (
must_use , Normal , template! ( Word , NameValueStr : " reason " ) ,
FutureWarnFollowing , EncodeCrossCrate ::Yes
2021-09-05 16:30:37 -07:00
) ,
2021-09-04 19:36:51 -07:00
gated! (
2021-09-05 16:30:37 -07:00
must_not_suspend , Normal , template! ( Word , NameValueStr : " reason " ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes , experimental! ( must_not_suspend )
2021-09-04 19:36:51 -07:00
) ,
2019-08-22 23:30:59 +02:00
ungated! (
deprecated , Normal ,
template! (
Word ,
List : r #" /*opt*/ since = " version " , /*opt*/ note = " reason " " #,
NameValueStr : " reason "
) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::Yes
2019-08-22 23:30:59 +02:00
) ,
2019-08-22 20:40:50 +02:00
2019-08-22 23:30:59 +02:00
// Crate properties:
2024-02-23 17:23:01 +08:00
ungated! (
crate_name , CrateLevel , template! ( NameValueStr : " name " ) , FutureWarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-02-23 17:23:01 +08:00
) ,
ungated! (
crate_type , CrateLevel , template! ( NameValueStr : " bin|lib|... " ) , DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-02-23 17:23:01 +08:00
) ,
2019-08-22 20:40:50 +02:00
2019-08-22 23:30:59 +02:00
// ABI, linking, symbols, and FFI
ungated! (
2021-07-29 12:00:41 -05:00
link , Normal ,
2022-07-12 13:52:35 -07:00
template! ( List : r #" name = " .. . " , /*opt*/ kind = " dylib | static | .. . " , /*opt*/ wasm_import_module = " .. . " , /*opt*/ import_name_type = " decorated | noprefix | undecorated " " #) ,
2021-09-05 16:30:37 -07:00
DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
) ,
ungated! (
link_name , Normal , template! ( NameValueStr : " name " ) ,
FutureWarnPreceding , EncodeCrossCrate ::Yes
2019-08-22 23:30:59 +02:00
) ,
2024-03-19 00:05:18 +08:00
ungated! ( no_link , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( repr , Normal , template! ( List : " C " ) , DuplicatesOk , EncodeCrossCrate ::No ) ,
2025-06-09 20:08:52 +02:00
gated! ( align , Normal , template! ( List : " alignment " ) , DuplicatesOk , EncodeCrossCrate ::No , fn_align , experimental! ( align ) ) ,
2025-04-12 19:58:19 +02:00
ungated! ( unsafe ( Edition2024 ) export_name , Normal , template! ( NameValueStr : " name " ) , FutureWarnPreceding , EncodeCrossCrate ::No ) ,
ungated! ( unsafe ( Edition2024 ) link_section , Normal , template! ( NameValueStr : " name " ) , FutureWarnPreceding , EncodeCrossCrate ::No ) ,
ungated! ( unsafe ( Edition2024 ) no_mangle , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
2024-03-19 00:05:18 +08:00
ungated! ( used , Normal , template! ( Word , List : " compiler|linker " ) , WarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( link_ordinal , Normal , template! ( List : " ordinal " ) , ErrorPreceding , EncodeCrossCrate ::Yes ) ,
2024-12-18 22:05:27 +01:00
ungated! ( unsafe naked , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
2019-08-22 23:30:59 +02:00
// Limits:
2024-02-23 17:23:01 +08:00
ungated! (
recursion_limit , CrateLevel , template! ( NameValueStr : " N " ) , FutureWarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No
2024-02-23 17:23:01 +08:00
) ,
ungated! (
type_length_limit , CrateLevel , template! ( NameValueStr : " N " ) , FutureWarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No
2024-02-23 17:23:01 +08:00
) ,
2021-03-26 16:28:52 +00:00
gated! (
2021-09-05 16:30:37 -07:00
move_size_limit , CrateLevel , template! ( NameValueStr : " N " ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , large_assignments , experimental! ( move_size_limit )
2021-03-26 16:28:52 +00:00
) ,
2019-08-22 23:30:59 +02:00
// Entry point:
2024-03-19 00:05:18 +08:00
ungated! ( no_main , CrateLevel , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
2019-08-22 23:30:59 +02:00
// Modules, prelude, and resolution:
2024-03-19 00:05:18 +08:00
ungated! ( path , Normal , template! ( NameValueStr : " file " ) , FutureWarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( no_std , CrateLevel , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( no_implicit_prelude , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( non_exhaustive , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) ,
2019-08-22 23:30:59 +02:00
// Runtime
2021-09-05 16:30:37 -07:00
ungated! (
2022-01-09 13:08:30 -08:00
windows_subsystem , CrateLevel ,
2024-02-27 10:45:19 +08:00
template! ( NameValueStr : " windows|console " ) , FutureWarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No
2021-09-05 16:30:37 -07:00
) ,
2024-03-19 00:05:18 +08:00
ungated! ( panic_handler , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) , // RFC 2070
2019-08-22 23:30:59 +02:00
// Code generation:
2024-03-19 00:05:18 +08:00
ungated! ( inline , Normal , template! ( Word , List : " always|never " ) , FutureWarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( cold , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ) ,
ungated! ( no_builtins , CrateLevel , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) ,
2022-09-13 15:23:54 +02:00
ungated! (
target_feature , Normal , template! ( List : r #" enable = " name " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No ,
2022-09-13 15:23:54 +02:00
) ,
2024-03-19 00:05:18 +08:00
ungated! ( track_caller , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) ,
ungated! ( instruction_set , Normal , template! ( List : " set " ) , ErrorPreceding , EncodeCrossCrate ::No ) ,
2020-01-12 00:00:00 +00:00
gated! (
2021-07-29 12:00:41 -05:00
no_sanitize , Normal ,
2022-11-21 21:29:00 -08:00
template! ( List : " address, kcfi, memory, thread " ) , DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( no_sanitize )
2024-02-27 10:45:19 +08:00
) ,
2024-12-22 14:26:54 +11:00
gated! (
2024-06-20 17:44:11 +10:00
coverage , Normal , template! ( OneOf : & [ sym ::off , sym ::on ] ) ,
2024-06-19 17:02:19 +10:00
ErrorPreceding , EncodeCrossCrate ::No ,
2024-12-22 14:26:54 +11:00
coverage_attribute , experimental! ( coverage )
2020-01-12 00:00:00 +00:00
) ,
2019-08-22 23:30:59 +02:00
2021-09-05 16:30:37 -07:00
ungated! (
2024-03-19 00:05:18 +08:00
doc , Normal , template! ( List : " hidden|inline|... " , NameValueStr : " string " ) , DuplicatesOk ,
EncodeCrossCrate ::Yes
2021-09-05 16:30:37 -07:00
) ,
2019-08-22 23:30:59 +02:00
2023-03-01 18:56:29 -08:00
// Debugging
ungated! (
2023-03-02 10:41:08 -08:00
debugger_visualizer , Normal ,
2024-02-27 10:45:19 +08:00
template! ( List : r #" natvis_file = " .. . " , gdb_script_file = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No
2023-03-01 18:56:29 -08:00
) ,
2024-02-09 15:39:25 +03:00
ungated! ( collapse_debuginfo , Normal , template! ( List : " no|external|yes " ) , ErrorFollowing ,
EncodeCrossCrate ::Yes
) ,
2023-03-01 18:56:29 -08:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Unstable attributes:
// ==========================================================================
2024-09-30 21:07:36 +03:00
// Linking:
gated! (
export_stable , Normal , template! ( Word ) , WarnFollowing ,
EncodeCrossCrate ::No , experimental! ( export_stable )
) ,
2019-08-22 23:30:59 +02:00
// Testing:
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
test_runner , CrateLevel , template! ( List : " path " ) , ErrorFollowing ,
EncodeCrossCrate ::Yes , custom_test_frameworks ,
2019-08-22 23:30:59 +02:00
" custom test frameworks are an unstable feature " ,
2019-08-22 20:40:50 +02:00
) ,
2019-08-22 18:32:31 +02:00
// RFC #1268
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
marker , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2023-02-14 10:56:24 +01:00
marker_trait_attr , experimental! ( marker )
2021-09-05 16:30:37 -07:00
) ,
gated! (
2024-03-19 00:05:18 +08:00
thread_local , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
" `#[thread_local]` is an experimental feature, and does not currently handle destructors " ,
2019-08-22 20:40:50 +02:00
) ,
2024-02-27 10:45:19 +08:00
gated! (
no_core , CrateLevel , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( no_core )
2024-02-27 10:45:19 +08:00
) ,
2019-08-22 23:30:59 +02:00
// RFC 2412
2019-08-22 20:40:50 +02:00
gated! (
2024-12-09 19:00:43 +00:00
optimize , Normal , template! ( List : " none|size|speed " ) , ErrorPreceding ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , optimize_attribute , experimental! ( optimize )
2019-08-22 20:40:50 +02:00
) ,
2024-02-27 10:45:19 +08:00
gated! (
2024-05-27 11:46:19 -05:00
unsafe ffi_pure , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( ffi_pure )
2024-02-27 10:45:19 +08:00
) ,
gated! (
2024-05-27 11:46:19 -05:00
unsafe ffi_const , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( ffi_const )
2024-02-27 10:45:19 +08:00
) ,
2019-11-03 20:28:20 +03:00
gated! (
2021-09-05 16:30:37 -07:00
register_tool , CrateLevel , template! ( List : " tool1, tool2, ... " ) , DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( register_tool ) ,
2019-11-03 20:28:20 +03:00
) ,
2019-08-22 23:30:59 +02:00
2021-07-04 23:50:34 +08:00
// RFC 2632
gated! (
2024-07-01 08:36:28 +00:00
const_trait , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No , const_trait_impl ,
2022-08-28 04:53:36 +00:00
" `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
2022-03-16 20:49:54 +11:00
` impls ` and all default bodies as ` const ` , which may be removed or renamed in the \
future . "
2021-07-04 23:50:34 +08:00
) ,
2022-03-15 19:28:53 -03:00
// lang-team MCP 147
gated! (
deprecated_safe , Normal , template! ( List : r #" since = " version " , note = " .. . " " #) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes , experimental! ( deprecated_safe ) ,
2022-03-15 19:28:53 -03:00
) ,
2022-07-21 16:19:22 +01:00
2022-12-12 22:42:44 -08:00
// `#[cfi_encoding = ""]`
gated! (
cfi_encoding , Normal , template! ( NameValueStr : " encoding " ) , ErrorPreceding ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes , experimental! ( cfi_encoding )
2022-12-12 22:42:44 -08:00
) ,
2024-04-11 12:48:32 +00:00
// `#[coroutine]` attribute to be applied to closures to make them coroutines instead
gated! (
coroutine , Normal , template! ( Word ) , ErrorFollowing ,
2025-01-09 21:40:14 -08:00
EncodeCrossCrate ::No , coroutines , experimental! ( coroutine )
2024-04-11 12:48:32 +00:00
) ,
2024-05-02 23:19:02 +02:00
// RFC 3543
// `#[patchable_function_entry(prefix_nops = m, entry_nops = n)]`
2023-12-12 13:37:04 -08:00
gated! (
2024-05-02 23:19:02 +02:00
patchable_function_entry , Normal , template! ( List : " prefix_nops = m, entry_nops = n " ) , ErrorPreceding ,
EncodeCrossCrate ::Yes , experimental! ( patchable_function_entry )
2023-12-12 13:37:04 -08:00
) ,
2024-05-26 17:57:13 +08:00
2025-01-06 21:15:56 -08:00
// Probably temporary component of min_generic_const_args.
// `#[type_const] const ASSOC: usize;`
gated! (
type_const , Normal , template! ( Word ) , ErrorFollowing ,
EncodeCrossCrate ::Yes , min_generic_const_args , experimental! ( type_const ) ,
) ,
2025-02-18 14:16:57 +01:00
// The `#[loop_match]` and `#[const_continue]` attributes are part of the
// lang experiment for RFC 3720 tracked in:
//
// - https://github.com/rust-lang/rust/issues/132306
gated! (
const_continue , Normal , template! ( Word ) , ErrorFollowing ,
EncodeCrossCrate ::No , loop_match , experimental! ( const_continue )
) ,
gated! (
loop_match , Normal , template! ( Word ) , ErrorFollowing ,
EncodeCrossCrate ::No , loop_match , experimental! ( loop_match )
) ,
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes: Stability, deprecation, and unsafe:
// ==========================================================================
2022-09-13 15:23:54 +02:00
ungated! (
feature , CrateLevel ,
2024-03-19 00:05:18 +08:00
template! ( List : " name1, name2, ... " ) , DuplicatesOk , EncodeCrossCrate ::No ,
2022-09-13 15:23:54 +02:00
) ,
2021-09-05 16:30:37 -07:00
// DuplicatesOk since it has its own validation
ungated! (
2022-09-13 15:23:54 +02:00
stable , Normal ,
2024-03-19 00:05:18 +08:00
template! ( List : r #" feature = " name " , since = " version " " #) , DuplicatesOk , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
) ,
ungated! (
2021-07-29 12:00:41 -05:00
unstable , Normal ,
2021-09-05 16:30:37 -07:00
template! ( List : r #" feature = " name " , reason = " .. . " , issue = " N " " #) , DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes
) ,
2025-07-14 13:38:19 +00:00
ungated! (
unstable_feature_bound , Normal , template! ( Word , List : " feat1, feat2, ... " ) ,
DuplicatesOk , EncodeCrossCrate ::No ,
) ,
2024-03-19 00:05:18 +08:00
ungated! (
rustc_const_unstable , Normal , template! ( List : r #" feature = " name " " #) ,
DuplicatesOk , EncodeCrossCrate ::Yes
2019-08-22 20:40:50 +02:00
) ,
2022-09-13 15:23:54 +02:00
ungated! (
rustc_const_stable , Normal ,
2024-03-19 00:05:18 +08:00
template! ( List : r #" feature = " name " " #) , DuplicatesOk , EncodeCrossCrate ::No ,
2022-09-13 15:23:54 +02:00
) ,
2022-04-27 18:14:19 +04:00
ungated! (
rustc_default_body_unstable , Normal ,
2024-02-27 10:45:19 +08:00
template! ( List : r #" feature = " name " , reason = " .. . " , issue = " N " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No
2022-04-27 18:14:19 +04:00
) ,
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
allow_internal_unstable , Normal , template! ( Word , List : " feat1, feat2, ... " ) ,
DuplicatesOk , EncodeCrossCrate ::Yes ,
2019-11-30 02:03:32 +01:00
" allow_internal_unstable side-steps feature gating and stability checks " ,
) ,
gated! (
2021-09-05 16:30:37 -07:00
allow_internal_unsafe , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , " allow_internal_unsafe side-steps the unsafe_code lint " ,
2024-02-28 22:45:43 +08:00
) ,
rustc_attr! (
2025-02-02 12:33:40 +01:00
rustc_allowed_through_unstable_modules , Normal , template! ( NameValueStr : " deprecation message " ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
" rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
through unstable paths "
2019-08-22 20:40:50 +02:00
) ,
2024-05-13 09:05:34 +02:00
rustc_attr! (
2024-07-29 13:31:59 +02:00
rustc_deprecated_safe_2024 , Normal , template! ( List : r #" audit_that = " .. . " " #) ,
2024-07-17 13:45:31 +02:00
ErrorFollowing , EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary " ,
2024-05-13 09:05:34 +02:00
) ,
2024-08-24 19:44:12 +03:00
rustc_attr! (
rustc_pub_transparent , Normal , template! ( Word ) ,
2025-06-14 20:54:30 +03:00
ErrorFollowing , EncodeCrossCrate ::Yes ,
2024-08-24 19:44:12 +03:00
" used internally to mark types with a `transparent` representation when it is guaranteed by the documentation " ,
) ,
2024-05-13 09:05:34 +02:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes: Type system related:
// ==========================================================================
2019-08-22 19:37:04 +02:00
2024-03-19 00:05:18 +08:00
gated! ( fundamental , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes , experimental! ( fundamental ) ) ,
2019-08-22 20:40:50 +02:00
gated! (
2024-02-28 22:45:43 +08:00
may_dangle , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , dropck_eyepatch ,
2019-08-22 23:30:59 +02:00
" `may_dangle` has unstable semantics and may be removed in the future " ,
2019-08-22 20:40:50 +02:00
) ,
2019-08-22 23:30:59 +02:00
2024-03-15 12:27:54 +00:00
rustc_attr! (
2024-03-21 19:47:46 +00:00
rustc_never_type_options ,
Normal ,
template! ( List : r #" /*opt*/ fallback = " unit | niko | never | no " " #) ,
ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2024-03-21 19:47:46 +00:00
" `rustc_never_type_options` is used to experiment with never type fallback and work on \
2025-05-18 18:35:13 +02:00
never type stabilization "
2024-03-15 12:27:54 +00:00
) ,
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes: Runtime related:
// ==========================================================================
2024-02-28 22:45:43 +08:00
rustc_attr! (
rustc_allocator , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
rustc_attr! (
rustc_nounwind , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
rustc_attr! (
rustc_reallocator , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
rustc_attr! (
rustc_deallocator , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
rustc_attr! (
rustc_allocator_zeroed , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
gated! (
default_lib_allocator , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , allocator_internals , experimental! ( default_lib_allocator ) ,
2024-02-28 22:45:43 +08:00
) ,
2019-08-22 20:40:50 +02:00
gated! (
2024-02-28 22:45:43 +08:00
needs_allocator , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , allocator_internals , experimental! ( needs_allocator ) ,
2019-08-22 20:40:50 +02:00
) ,
gated! (
2024-07-31 15:56:09 +00:00
panic_runtime , CrateLevel , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( panic_runtime )
2019-08-22 20:40:50 +02:00
) ,
gated! (
2024-07-31 15:56:09 +00:00
needs_panic_runtime , CrateLevel , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , experimental! ( needs_panic_runtime )
2021-09-05 16:30:37 -07:00
) ,
gated! (
2024-07-31 15:56:09 +00:00
compiler_builtins , CrateLevel , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2019-08-22 20:40:50 +02:00
" the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
which contains compiler - rt intrinsics and will never be stable " ,
) ,
gated! (
2024-07-31 15:56:09 +00:00
profiler_runtime , CrateLevel , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2019-08-22 20:40:50 +02:00
" the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
which contains the profiler runtime and will never be stable " ,
) ,
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Linkage:
// ==========================================================================
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
linkage , Normal , template! ( NameValueStr : " external|internal|... " ) ,
ErrorPreceding , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
" the `linkage` attribute is experimental and not portable across platforms " ,
2019-08-22 20:40:50 +02:00
) ,
2021-09-05 16:30:37 -07:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_std_internal_symbol , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2021-09-05 16:30:37 -07:00
) ,
2019-08-22 20:40:50 +02:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Macro related:
// ==========================================================================
2021-07-10 17:16:53 +03:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
rustc_builtin_macro , Normal ,
2021-09-05 16:30:37 -07:00
template! ( Word , List : " name, /*opt*/ attributes(name1, name2, ...) " ) , ErrorFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes ,
2021-07-10 17:16:53 +03:00
) ,
2024-02-28 22:45:43 +08:00
rustc_attr! (
rustc_proc_macro_decls , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No ,
2024-02-28 22:45:43 +08:00
) ,
2019-08-22 23:30:59 +02:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
rustc_macro_transparency , Normal ,
2025-03-28 22:31:20 +03:00
template! ( NameValueStr : " transparent|semiopaque|opaque " ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes , " used internally for testing macro hygiene " ,
2019-08-22 20:40:50 +02:00
) ,
2024-10-11 19:13:31 +02:00
rustc_attr! (
rustc_autodiff , Normal ,
template! ( Word , List : r #" " .. . " " #) , DuplicatesOk ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes ,
2024-10-11 19:13:31 +02:00
) ,
2025-03-22 21:42:34 +03:00
// Traces that are left when `cfg` and `cfg_attr` attributes are expanded.
// The attributes are not gated, to avoid stability errors, but they cannot be used in stable
// or unstable code directly because `sym::cfg_(attr_)trace` are not valid identifiers, they
// can only be generated by the compiler.
ungated! (
cfg_trace , Normal , template! ( Word /* irrelevant */ ) , DuplicatesOk ,
EncodeCrossCrate ::No
) ,
2025-03-14 20:34:43 +03:00
ungated! (
cfg_attr_trace , Normal , template! ( Word /* irrelevant */ ) , DuplicatesOk ,
EncodeCrossCrate ::No
) ,
2019-08-22 20:40:50 +02:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Diagnostics related:
// ==========================================================================
2019-10-25 07:19:07 +02:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
rustc_on_unimplemented , Normal ,
2019-08-22 23:30:59 +02:00
template! (
List : r #" /*opt*/ message = " .. . " , /*opt*/ label = " .. . " , /*opt*/ note = " .. . " " #,
NameValueStr : " message "
) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute "
2019-08-22 20:40:50 +02:00
) ,
2023-07-16 18:18:38 +08:00
rustc_attr! (
rustc_confusables , Normal ,
template! ( List : r #" " name1 " , " name2 " , ... " #) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::Yes ,
2023-07-16 18:18:38 +08:00
) ,
2020-07-07 11:12:44 -04:00
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
2021-09-05 16:30:37 -07:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_conversion_suggestion , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2021-09-05 16:30:37 -07:00
) ,
2021-05-21 19:35:49 +02:00
// Prevents field reads in the marked trait or method to be considered
// during dead code analysis.
2021-09-05 16:30:37 -07:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_trivial_field_reads , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2021-09-05 16:30:37 -07:00
) ,
2022-01-05 13:02:16 +01:00
// Used by the `rustc::potential_query_instability` lint to warn methods which
// might not be stable during incremental compilation.
2024-03-19 00:05:18 +08:00
rustc_attr! (
rustc_lint_query_instability , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2024-03-19 00:05:18 +08:00
) ,
2024-08-09 09:52:12 +02:00
// Used by the `rustc::untracked_query_information` lint to warn methods which
// might not be stable during incremental compilation.
rustc_attr! (
rustc_lint_untracked_query_information , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2024-08-09 09:52:12 +02:00
) ,
2024-02-20 14:12:50 +11:00
// Used by the `rustc::diagnostic_outside_of_impl` lints to assist in changes to diagnostic
// APIs. Any function with this attribute will be checked by that lint.
2024-03-19 00:05:18 +08:00
rustc_attr! (
rustc_lint_diagnostics , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2024-03-19 00:05:18 +08:00
) ,
2022-07-25 13:02:39 +01:00
// Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions`
// types (as well as any others in future).
2024-03-19 00:05:18 +08:00
rustc_attr! (
rustc_lint_opt_ty , Normal , template! ( Word ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2024-03-19 00:05:18 +08:00
) ,
2022-07-25 13:02:39 +01:00
// Used by the `rustc::bad_opt_access` lint on fields
// types (as well as any others in future).
2024-03-19 00:05:18 +08:00
rustc_attr! (
rustc_lint_opt_deny_field_access , Normal , template! ( List : " message " ) ,
2025-05-18 18:35:13 +02:00
WarnFollowing , EncodeCrossCrate ::Yes ,
2024-03-19 00:05:18 +08:00
) ,
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Const related:
// ==========================================================================
2024-03-05 15:46:49 +08:00
rustc_attr! (
rustc_promotable , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::No , ) ,
2021-09-05 16:30:37 -07:00
rustc_attr! (
rustc_legacy_const_generics , Normal , template! ( List : " N " ) , ErrorFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes ,
2021-09-05 16:30:37 -07:00
) ,
2025-06-15 14:59:05 +08:00
// Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
2021-09-05 16:30:37 -07:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_do_not_const_check , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes , " `#[rustc_do_not_const_check]` skips const-check for this function's body " ,
2021-09-05 16:30:37 -07:00
) ,
2023-09-03 06:31:56 +02:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_const_panic_str , Normal , template! ( Word ) , WarnFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes , " `#[rustc_const_panic_str]` ensures the argument to this function is &&str during const-check " ,
2024-06-14 12:16:15 +00:00
) ,
2024-10-06 19:59:19 +02:00
rustc_attr! (
rustc_const_stable_indirect , Normal ,
2025-05-18 18:35:13 +02:00
template! ( Word ) ,
WarnFollowing ,
EncodeCrossCrate ::No ,
" this is an internal implementation detail " ,
2024-10-06 19:59:19 +02:00
) ,
2024-11-01 22:53:59 +01:00
rustc_attr! (
2024-11-17 22:50:14 +01:00
rustc_intrinsic_const_stable_indirect , Normal ,
2025-05-18 18:35:13 +02:00
template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No , " this is an internal implementation detail " ,
2024-11-01 22:53:59 +01:00
) ,
2024-10-06 19:59:19 +02:00
gated! (
rustc_allow_const_fn_unstable , Normal ,
template! ( Word , List : " feat1, feat2, ... " ) , DuplicatesOk , EncodeCrossCrate ::No ,
" rustc_allow_const_fn_unstable side-steps feature gating and stability checks "
) ,
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Layout related:
// ==========================================================================
2019-08-22 18:32:31 +02:00
2019-08-22 19:37:04 +02:00
rustc_attr! (
2021-09-05 16:30:37 -07:00
rustc_layout_scalar_valid_range_start , Normal , template! ( List : " value " ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes ,
2019-08-22 23:30:59 +02:00
" the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
2025-05-18 18:35:13 +02:00
niche optimizations in the standard library " ,
2019-08-22 19:37:04 +02:00
) ,
rustc_attr! (
2021-09-05 16:30:37 -07:00
rustc_layout_scalar_valid_range_end , Normal , template! ( List : " value " ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes ,
2019-08-22 23:30:59 +02:00
" the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
2025-05-18 18:35:13 +02:00
niche optimizations in the standard library " ,
2019-08-22 19:37:04 +02:00
) ,
rustc_attr! (
2021-09-05 16:30:37 -07:00
rustc_nonnull_optimization_guaranteed , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes ,
2024-09-22 08:11:17 +02:00
" the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document \
2025-05-18 18:35:13 +02:00
guaranteed niche optimizations in the standard library " ,
" the compiler does not even check whether the type indeed is being non-null-optimized; \
it is your responsibility to ensure that the attribute is only used on types that are optimized " ,
2019-08-22 19:37:04 +02:00
) ,
2019-08-22 18:32:31 +02:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Misc:
// ==========================================================================
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
lang , Normal , template! ( NameValueStr : " name " ) , DuplicatesOk , EncodeCrossCrate ::No , lang_items ,
2024-04-17 12:30:45 +02:00
" lang items are subject to change " ,
2019-08-22 20:40:50 +02:00
) ,
2024-11-02 11:39:29 -06:00
rustc_attr! (
rustc_as_ptr , Normal , template! ( Word ) , ErrorFollowing ,
EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations. "
2024-11-02 11:39:29 -06:00
) ,
2022-01-07 11:38:16 +00:00
rustc_attr! (
2023-02-14 10:17:19 +01:00
rustc_pass_by_value , Normal , template! ( Word ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_pass_by_value]` is used to mark types that must be passed by value instead of reference. "
2022-01-07 11:38:16 +00:00
) ,
2023-08-05 04:54:23 +02:00
rustc_attr! (
rustc_never_returns_null_ptr , Normal , template! ( Word ) , ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_never_returns_null_ptr]` is used to mark functions returning non-null pointers. "
2023-08-05 04:54:23 +02:00
) ,
2022-03-15 16:30:30 +01:00
rustc_attr! (
2024-03-30 16:00:28 +01:00
rustc_no_implicit_autorefs , AttributeType ::Normal , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::Yes ,
" `#[rustc_no_implicit_autorefs]` is used to mark functions for which an autoref to the dereference of a raw pointer should not be used as an argument. "
) ,
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_coherence_is_core , AttributeType ::CrateLevel , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::No ,
2025-05-18 18:35:13 +02:00
" `#![rustc_coherence_is_core]` allows inherent methods on builtin types, only intended to be used in `core`. "
2022-03-15 16:30:30 +01:00
) ,
2023-02-14 10:17:19 +01:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_coinductive , AttributeType ::Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2025-05-18 18:35:13 +02:00
" `#[rustc_coinductive]` changes a trait to be coinductive, allowing cycles in the trait solver. "
2023-02-14 10:17:19 +01:00
) ,
2022-03-15 16:30:30 +01:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_allow_incoherent_impl , AttributeType ::Normal , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::No ,
2025-05-18 18:35:13 +02:00
" `#[rustc_allow_incoherent_impl]` has to be added to all impl items of an incoherent inherent impl. "
2022-03-15 16:30:30 +01:00
) ,
2024-03-10 16:29:39 +08:00
rustc_attr! (
rustc_preserve_ub_checks , AttributeType ::CrateLevel , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::No ,
" `#![rustc_preserve_ub_checks]` prevents the designated crate from evaluating whether UB checks are enabled when optimizing MIR " ,
) ,
2022-11-12 23:37:52 +00:00
rustc_attr! (
2023-06-16 23:45:01 +00:00
rustc_deny_explicit_impl ,
AttributeType ::Normal ,
2024-12-20 16:57:14 +01:00
template! ( Word ) ,
2023-06-16 23:45:01 +00:00
ErrorFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No ,
2025-05-18 18:35:13 +02:00
" `#[rustc_deny_explicit_impl]` enforces that a trait can have no user-provided impls "
2022-11-12 23:37:52 +00:00
) ,
2024-12-20 16:57:14 +01:00
rustc_attr! (
rustc_do_not_implement_via_object ,
AttributeType ::Normal ,
template! ( Word ) ,
ErrorFollowing ,
EncodeCrossCrate ::No ,
2025-05-18 18:35:13 +02:00
" `#[rustc_do_not_implement_via_object]` opts out of the automatic trait impl for trait objects \
2024-12-20 16:57:14 +01:00
( ` impl Trait for dyn Trait ` ) "
) ,
2022-04-28 16:26:30 +02:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_has_incoherent_inherent_impls , AttributeType ::Normal , template! ( Word ) ,
ErrorFollowing , EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_has_incoherent_inherent_impls]` allows the addition of incoherent inherent impls for \
the given type by annotating all impl items with ` #[ rustc_allow_incoherent_impl ] ` . "
2022-04-28 16:26:30 +02:00
) ,
2022-05-22 23:10:27 +02:00
2021-11-12 20:15:14 +08:00
BuiltinAttribute {
name : sym ::rustc_diagnostic_item ,
2022-04-01 15:04:47 +02:00
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
2024-03-19 00:05:18 +08:00
encode_cross_crate : EncodeCrossCrate ::Yes ,
2021-11-12 20:15:14 +08:00
type_ : Normal ,
2024-04-20 23:54:50 -05:00
safety : AttributeSafety ::Normal ,
2021-11-12 20:15:14 +08:00
template : template ! ( NameValueStr : " name " ) ,
2021-09-05 16:30:37 -07:00
duplicates : ErrorFollowing ,
2025-05-18 18:35:13 +02:00
gate : Gated {
feature : sym ::rustc_attrs ,
message : " use of an internal attribute " ,
check : Features ::rustc_attrs ,
notes : & [ " the `#[rustc_diagnostic_item]` attribute allows the compiler to reference types \
from the standard library for diagnostic purposes " ],
} ,
2021-11-12 20:15:14 +08:00
} ,
2019-08-22 20:40:50 +02:00
gated! (
2019-08-22 23:30:59 +02:00
// Used in resolve:
2021-09-05 16:30:37 -07:00
prelude_import , Normal , template! ( Word ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , " `#[prelude_import]` is for use by rustc only " ,
2019-08-22 20:40:50 +02:00
) ,
gated! (
2024-03-19 00:05:18 +08:00
rustc_paren_sugar , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2024-03-05 15:46:49 +08:00
unboxed_closures , " unboxed_closures are still evolving " ,
2019-08-22 20:40:50 +02:00
) ,
2019-08-22 23:30:59 +02:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_inherit_overflow_checks , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
" the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
2025-05-18 18:35:13 +02:00
overflow checking behavior of several functions in the standard library that are inlined \
across crates " ,
2019-08-22 23:30:59 +02:00
) ,
2021-09-05 16:30:37 -07:00
rustc_attr! (
rustc_reservation_impl , Normal ,
2024-03-19 00:05:18 +08:00
template! ( NameValueStr : " reservation message " ) , ErrorFollowing , EncodeCrossCrate ::Yes ,
2021-09-05 16:30:37 -07:00
" the `#[rustc_reservation_impl]` attribute is internally used \
2025-05-18 18:35:13 +02:00
for reserving ` impl < T > From < ! > for T ` as part of the effort to stabilize ` ! ` "
2019-07-13 18:02:00 +03:00
) ,
2019-08-22 23:30:59 +02:00
rustc_attr! (
2022-07-26 17:40:48 -04:00
rustc_test_marker , Normal , template! ( NameValueStr : " name " ) , WarnFollowing ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No , " the `#[rustc_test_marker]` attribute is used internally to track tests " ,
2019-08-22 23:30:59 +02:00
) ,
2020-02-08 17:56:25 +00:00
rustc_attr! (
2024-03-05 15:46:49 +08:00
rustc_unsafe_specialization_marker , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No ,
2020-02-08 17:56:25 +00:00
" the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations "
) ,
rustc_attr! (
2024-03-05 15:46:49 +08:00
rustc_specialization_trait , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No ,
2020-02-08 17:56:25 +00:00
" the `#[rustc_specialization_trait]` attribute is used to check specializations "
) ,
2021-04-08 21:37:38 +08:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_main , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::No ,
2021-04-08 21:37:38 +08:00
" the `#[rustc_main]` attribute is used internally to specify test entry point function " ,
) ,
2021-04-12 16:03:53 -07:00
rustc_attr! (
2025-06-18 22:27:35 +03:00
rustc_skip_during_method_dispatch , Normal , template! ( List : " array, boxed_slice " ) , ErrorFollowing ,
2024-04-17 16:32:17 -04:00
EncodeCrossCrate ::No ,
" the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \
from method dispatch when the receiver is of the following type , for compatibility in \
editions < 2021 ( array ) or editions < 2024 ( boxed_slice ) . "
2021-04-12 16:03:53 -07:00
) ,
2021-12-21 18:40:50 +03:00
rustc_attr! (
2024-03-05 15:46:49 +08:00
rustc_must_implement_one_of , Normal , template! ( List : " function1, function2, ... " ) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::No ,
2021-12-21 18:40:50 +03:00
" the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
2025-05-18 18:35:13 +02:00
definition of a trait . Its syntax and semantics are highly experimental and will be \
subject to change before stabilization " ,
2021-12-21 18:40:50 +03:00
) ,
2023-03-21 16:43:51 +01:00
rustc_attr! (
rustc_doc_primitive , Normal , template! ( NameValueStr : " primitive name " ) , ErrorFollowing ,
2025-05-18 18:35:13 +02:00
EncodeCrossCrate ::Yes , " the `#[rustc_doc_primitive]` attribute is used by the standard library \
to provide a way to generate documentation for primitive types " ,
2023-03-21 16:43:51 +01:00
) ,
2024-11-07 08:59:43 +01:00
gated! (
rustc_intrinsic , Normal , template! ( Word ) , ErrorFollowing , EncodeCrossCrate ::Yes , intrinsics ,
2025-01-04 11:41:51 +01:00
" the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items " ,
2024-01-30 16:03:58 +00:00
) ,
2024-02-14 22:08:03 +01:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
rustc_no_mir_inline , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_no_mir_inline]` prevents the MIR inliner from inlining a function while not affecting codegen "
2024-02-14 22:08:03 +01:00
) ,
2024-09-23 18:46:23 +01:00
rustc_attr! (
rustc_force_inline , Normal , template! ( Word , NameValueStr : " reason " ) , WarnFollowing , EncodeCrossCrate ::Yes ,
2025-05-18 18:35:13 +02:00
" `#[rustc_force_inline]` forces a free function to be inlined "
2024-09-23 18:46:23 +01:00
) ,
2019-08-22 18:32:31 +02:00
2019-08-22 23:30:59 +02:00
// ==========================================================================
// Internal attributes, Testing:
// ==========================================================================
2019-08-22 18:32:31 +02:00
2024-03-19 00:05:18 +08:00
rustc_attr! ( TEST , rustc_effective_visibility , Normal , template! ( Word ) , WarnFollowing , EncodeCrossCrate ::Yes ) ,
2024-03-05 15:46:49 +08:00
rustc_attr! (
TEST , rustc_outlives , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
2024-03-05 15:46:49 +08:00
) ,
rustc_attr! (
TEST , rustc_capture_analysis , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
) ,
rustc_attr! (
TEST , rustc_insignificant_dtor , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::Yes
) ,
2025-06-18 12:23:35 +00:00
rustc_attr! (
TEST , rustc_no_implicit_bounds , CrateLevel , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
) ,
2024-03-19 00:05:18 +08:00
rustc_attr! (
TEST , rustc_strict_coherence , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::Yes
) ,
rustc_attr! (
TEST , rustc_variance , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2024-03-05 15:46:49 +08:00
) ,
2024-03-14 17:12:39 +08:00
rustc_attr! (
TEST , rustc_variance_of_opaques , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
2024-03-14 17:12:39 +08:00
) ,
rustc_attr! (
TEST , rustc_hidden_type_of_opaques , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
) ,
rustc_attr! (
TEST , rustc_layout , Normal , template! ( List : " field1, field2, ... " ) ,
WarnFollowing , EncodeCrossCrate ::Yes
) ,
2024-03-14 17:12:39 +08:00
rustc_attr! (
TEST , rustc_abi , Normal , template! ( List : " field1, field2, ... " ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
2024-03-14 17:12:39 +08:00
) ,
rustc_attr! (
TEST , rustc_regions , Normal , template! ( Word ) ,
2024-03-19 00:05:18 +08:00
WarnFollowing , EncodeCrossCrate ::No
2024-03-14 17:12:39 +08:00
) ,
2019-11-03 16:44:19 +01:00
rustc_attr! (
2025-03-30 00:39:55 +03:00
TEST , rustc_delayed_bug_from_inside_query , Normal ,
template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2024-03-19 00:05:18 +08:00
) ,
rustc_attr! (
TEST , rustc_dump_user_args , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2021-09-05 16:30:37 -07:00
) ,
2024-03-14 17:12:39 +08:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_evaluate_where_clauses , Normal , template! ( Word ) , WarnFollowing ,
EncodeCrossCrate ::Yes
2024-03-14 17:12:39 +08:00
) ,
2021-09-05 16:30:37 -07:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_if_this_changed , Normal , template! ( Word , List : " DepNode " ) , DuplicatesOk ,
EncodeCrossCrate ::No
2021-09-05 16:30:37 -07:00
) ,
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_then_this_would_need , Normal , template! ( List : " DepNode " ) , DuplicatesOk ,
EncodeCrossCrate ::No
2019-11-03 16:44:19 +01:00
) ,
2019-08-22 19:37:04 +02:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
TEST , rustc_clean , Normal ,
2019-08-22 23:30:59 +02:00
template! ( List : r #" cfg = " .. . " , /*opt*/ label = " .. . " , /*opt*/ except = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
DuplicatesOk , EncodeCrossCrate ::No
2019-08-22 19:37:04 +02:00
) ,
rustc_attr! (
2021-07-29 12:00:41 -05:00
TEST , rustc_partition_reused , Normal ,
2024-03-19 00:05:18 +08:00
template! ( List : r #" cfg = " .. . " , module = " .. . " " #) , DuplicatesOk , EncodeCrossCrate ::No
2019-08-22 18:32:31 +02:00
) ,
2019-08-22 23:30:59 +02:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
TEST , rustc_partition_codegened , Normal ,
2024-03-19 00:05:18 +08:00
template! ( List : r #" cfg = " .. . " , module = " .. . " " #) , DuplicatesOk , EncodeCrossCrate ::No
2019-08-22 20:40:50 +02:00
) ,
2019-08-22 23:30:59 +02:00
rustc_attr! (
2021-07-29 12:00:41 -05:00
TEST , rustc_expected_cgu_reuse , Normal ,
2021-09-05 16:30:37 -07:00
template! ( List : r #" cfg = " .. . " , module = " .. . " , kind = " .. . " " #) , DuplicatesOk ,
2024-03-19 00:05:18 +08:00
EncodeCrossCrate ::No
) ,
rustc_attr! (
TEST , rustc_symbol_name , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2024-03-14 17:12:39 +08:00
) ,
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_def_path , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
) ,
rustc_attr! (
TEST , rustc_mir , Normal , template! ( List : " arg1, arg2, ... " ) ,
DuplicatesOk , EncodeCrossCrate ::Yes
2024-03-14 17:12:39 +08:00
) ,
2022-08-03 04:30:13 -07:00
gated! (
custom_mir , Normal , template! ( List : r #" dialect = " .. . " , phase = " .. . " " #) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::No ,
2024-03-14 17:12:39 +08:00
" the `#[custom_mir]` attribute is just used for the Rust test suite " ,
) ,
2024-06-19 14:24:25 +02:00
rustc_attr! (
TEST , rustc_dump_item_bounds , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
) ,
rustc_attr! (
TEST , rustc_dump_predicates , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2024-06-30 19:31:15 +01:00
) ,
rustc_attr! (
TEST , rustc_dump_def_parents , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2024-06-19 14:24:25 +02:00
) ,
2024-03-14 17:12:39 +08:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_object_lifetime_default , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No
2022-08-03 04:30:13 -07:00
) ,
2024-03-14 17:12:39 +08:00
rustc_attr! (
2024-03-19 00:05:18 +08:00
TEST , rustc_dump_vtable , Normal , template! ( Word ) ,
2025-01-10 20:09:10 +00:00
WarnFollowing , EncodeCrossCrate ::No
2024-03-19 00:05:18 +08:00
) ,
rustc_attr! (
TEST , rustc_dummy , Normal , template! ( Word /* doesn't matter */ ) ,
DuplicatesOk , EncodeCrossCrate ::No
2024-03-14 17:12:39 +08:00
) ,
2019-08-22 20:40:50 +02:00
gated! (
2024-03-19 00:05:18 +08:00
omit_gdb_pretty_printer_section , Normal , template! ( Word ) ,
WarnFollowing , EncodeCrossCrate ::No ,
2019-08-22 23:30:59 +02:00
" the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite " ,
2019-08-22 20:40:50 +02:00
) ,
2024-03-02 22:48:41 +01:00
rustc_attr! (
2025-02-07 15:58:00 +11:00
TEST , pattern_complexity_limit , CrateLevel , template! ( NameValueStr : " N " ) ,
2024-03-19 00:05:18 +08:00
ErrorFollowing , EncodeCrossCrate ::No ,
2024-03-02 22:48:41 +01:00
) ,
2019-08-22 18:32:31 +02:00
] ;
2019-11-30 02:20:07 +01:00
pub fn is_builtin_attr_name ( name : Symbol ) -> bool {
2019-08-22 18:32:31 +02:00
BUILTIN_ATTRIBUTE_MAP . get ( & name ) . is_some ( )
}
2024-03-19 00:05:18 +08:00
/// Whether this builtin attribute is encoded cross crate.
/// This means it can be used cross crate.
pub fn encode_cross_crate ( name : Symbol ) -> bool {
if let Some ( attr ) = BUILTIN_ATTRIBUTE_MAP . get ( & name ) {
2024-04-07 17:59:11 +02:00
attr . encode_cross_crate = = EncodeCrossCrate ::Yes
2024-03-19 00:05:18 +08:00
} else {
true
}
2022-04-01 15:04:47 +02:00
}
2022-09-06 14:16:54 +08:00
pub fn is_valid_for_get_attr ( name : Symbol ) -> bool {
2023-05-24 14:19:22 +00:00
BUILTIN_ATTRIBUTE_MAP . get ( & name ) . is_some_and ( | attr | match attr . duplicates {
2022-09-06 14:16:54 +08:00
WarnFollowing | ErrorFollowing | ErrorPreceding | FutureWarnFollowing
| FutureWarnPreceding = > true ,
DuplicatesOk | WarnFollowingWordOnly = > false ,
} )
}
2022-06-16 19:39:39 +04:00
pub static BUILTIN_ATTRIBUTE_MAP : LazyLock < FxHashMap < Symbol , & BuiltinAttribute > > =
LazyLock ::new ( | | {
2020-09-01 21:49:36 +01:00
let mut map = FxHashMap ::default ( ) ;
for attr in BUILTIN_ATTRIBUTES . iter ( ) {
2021-11-12 20:15:14 +08:00
if map . insert ( attr . name , attr ) . is_some ( ) {
panic! ( " duplicate builtin attribute ` {} ` " , attr . name ) ;
2020-09-01 21:49:36 +01:00
}
2019-08-22 18:32:31 +02:00
}
2020-09-01 21:49:36 +01:00
map
} ) ;
2024-09-06 18:47:22 +02:00
2024-10-23 08:09:15 +02:00
pub fn is_stable_diagnostic_attribute ( sym : Symbol , _features : & Features ) -> bool {
2024-09-06 18:47:22 +02:00
match sym {
2024-10-23 08:09:15 +02:00
sym ::on_unimplemented | sym ::do_not_recommend = > true ,
2024-09-06 18:47:22 +02:00
_ = > false ,
}
}