1 //! Builtin attributes resolved by nameres. 2 //! 3 //! The actual definitions were copied from rustc's `compiler/rustc_feature/src/builtin_attrs.rs`. 4 //! 5 //! It was last synchronized with upstream commit 835150e70288535bc57bb624792229b9dc94991d. 6 //! 7 //! The macros were adjusted to only expand to the attribute name, since that is all we need to do 8 //! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to 9 //! ease updating. 10 11 /// Ignored attribute namespaces used by tools. 12 pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"]; 13 14 type BuiltinAttribute = &'static str; 15 16 macro_rules! ungated { 17 ($attr:ident, $typ:expr, $tpl:expr $(,)?) => { 18 stringify!($attr) 19 }; 20 } 21 22 macro_rules! gated { 23 ($attr:ident $($rest:tt)*) => { 24 stringify!($attr) 25 }; 26 } 27 28 macro_rules! rustc_attr { 29 (TEST, $attr:ident $($rest:tt)*) => { 30 stringify!($attr) 31 }; 32 ($attr:ident $($rest:tt)*) => { 33 stringify!($attr) 34 }; 35 } 36 37 /// "Inert" built-in attributes that have a special meaning to rustc or rustdoc. 38 #[rustfmt::skip] 39 pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[ 40 // ========================================================================== 41 // Stable attributes: 42 // ========================================================================== 43 44 // Conditional compilation: 45 ungated!(cfg, Normal, template!(List: "predicate")), 46 ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")), 47 48 // Testing: 49 ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")), 50 ungated!( 51 should_panic, Normal, 52 template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), 53 ), 54 // FIXME(Centril): This can be used on stable but shouldn't. 55 ungated!(reexport_test_harness_main, Normal, template!(NameValueStr: "name")), 56 57 // Macros: 58 ungated!(automatically_derived, Normal, template!(Word)), 59 // FIXME(#14407) 60 ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")), 61 ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`. 62 ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")), 63 ungated!(proc_macro, Normal, template!(Word)), 64 ungated!( 65 proc_macro_derive, Normal, 66 template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), 67 ), 68 ungated!(proc_macro_attribute, Normal, template!(Word)), 69 70 // Lints: 71 ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), 72 ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), 73 ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), 74 ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)), 75 ungated!(must_use, AssumedUsed, template!(Word, NameValueStr: "reason")), 76 // FIXME(#14407) 77 ungated!( 78 deprecated, Normal, 79 template!( 80 Word, 81 List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, 82 NameValueStr: "reason" 83 ), 84 ), 85 86 // Crate properties: 87 ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")), 88 ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")), 89 ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")), 90 91 // ABI, linking, symbols, and FFI 92 ungated!( 93 link, AssumedUsed, 94 template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#), 95 ), 96 ungated!(link_name, AssumedUsed, template!(NameValueStr: "name")), 97 ungated!(no_link, AssumedUsed, template!(Word)), 98 ungated!(repr, AssumedUsed, template!(List: "C")), 99 ungated!(export_name, AssumedUsed, template!(NameValueStr: "name")), 100 ungated!(link_section, AssumedUsed, template!(NameValueStr: "name")), 101 ungated!(no_mangle, AssumedUsed, template!(Word)), 102 ungated!(used, AssumedUsed, template!(Word)), 103 104 // Limits: 105 ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")), 106 ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")), 107 gated!( 108 const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit, 109 experimental!(const_eval_limit) 110 ), 111 gated!( 112 move_size_limit, CrateLevel, template!(NameValueStr: "N"), large_assignments, 113 experimental!(move_size_limit) 114 ), 115 116 // Entry point: 117 ungated!(main, Normal, template!(Word)), 118 ungated!(start, Normal, template!(Word)), 119 ungated!(no_start, CrateLevel, template!(Word)), 120 ungated!(no_main, CrateLevel, template!(Word)), 121 122 // Modules, prelude, and resolution: 123 ungated!(path, Normal, template!(NameValueStr: "file")), 124 ungated!(no_std, CrateLevel, template!(Word)), 125 ungated!(no_implicit_prelude, Normal, template!(Word)), 126 ungated!(non_exhaustive, AssumedUsed, template!(Word)), 127 128 // Runtime 129 ungated!(windows_subsystem, AssumedUsed, template!(NameValueStr: "windows|console")), 130 ungated!(panic_handler, Normal, template!(Word)), // RFC 2070 131 132 // Code generation: 133 ungated!(inline, AssumedUsed, template!(Word, List: "always|never")), 134 ungated!(cold, AssumedUsed, template!(Word)), 135 ungated!(no_builtins, AssumedUsed, template!(Word)), 136 ungated!(target_feature, AssumedUsed, template!(List: r#"enable = "name""#)), 137 ungated!(track_caller, AssumedUsed, template!(Word)), 138 gated!( 139 no_sanitize, AssumedUsed, 140 template!(List: "address, memory, thread"), 141 experimental!(no_sanitize) 142 ), 143 gated!(no_coverage, AssumedUsed, template!(Word), experimental!(no_coverage)), 144 145 // FIXME: #14408 assume docs are used since rustdoc looks at them. 146 ungated!(doc, AssumedUsed, template!(List: "hidden|inline|...", NameValueStr: "string")), 147 148 // ========================================================================== 149 // Unstable attributes: 150 // ========================================================================== 151 152 // Linking: 153 gated!(naked, AssumedUsed, template!(Word), naked_functions, experimental!(naked)), 154 gated!( 155 link_ordinal, AssumedUsed, template!(List: "ordinal"), raw_dylib, 156 experimental!(link_ordinal) 157 ), 158 159 // Plugins: 160 // XXX Modified for use in rust-analyzer 161 gated!(plugin_registrar), 162 gated!(plugin), 163 164 // Testing: 165 gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)), 166 gated!( 167 test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks, 168 "custom test frameworks are an unstable feature", 169 ), 170 // RFC #1268 171 gated!(marker, AssumedUsed, template!(Word), marker_trait_attr, experimental!(marker)), 172 gated!( 173 thread_local, AssumedUsed, template!(Word), 174 "`#[thread_local]` is an experimental feature, and does not currently handle destructors", 175 ), 176 gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)), 177 // RFC 2412 178 gated!( 179 optimize, AssumedUsed, template!(List: "size|speed"), optimize_attribute, 180 experimental!(optimize), 181 ), 182 // RFC 2867 183 gated!(instruction_set, AssumedUsed, template!(List: "set"), isa_attribute, experimental!(instruction_set)), 184 185 gated!(ffi_returns_twice, AssumedUsed, template!(Word), experimental!(ffi_returns_twice)), 186 gated!(ffi_pure, AssumedUsed, template!(Word), experimental!(ffi_pure)), 187 gated!(ffi_const, AssumedUsed, template!(Word), experimental!(ffi_const)), 188 gated!( 189 register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), 190 experimental!(register_attr), 191 ), 192 gated!( 193 register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), 194 experimental!(register_tool), 195 ), 196 197 gated!(cmse_nonsecure_entry, AssumedUsed, template!(Word), experimental!(cmse_nonsecure_entry)), 198 199 // ========================================================================== 200 // Internal attributes: Stability, deprecation, and unsafe: 201 // ========================================================================== 202 203 ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")), 204 // FIXME(#14407) -- only looked at on-demand so we can't 205 // guarantee they'll have already been checked. 206 ungated!( 207 rustc_deprecated, AssumedUsed, 208 template!(List: r#"since = "version", reason = "...""#) 209 ), 210 // FIXME(#14407) 211 ungated!(stable, AssumedUsed, template!(List: r#"feature = "name", since = "version""#)), 212 // FIXME(#14407) 213 ungated!( 214 unstable, AssumedUsed, 215 template!(List: r#"feature = "name", reason = "...", issue = "N""#), 216 ), 217 // FIXME(#14407) 218 ungated!(rustc_const_unstable, AssumedUsed, template!(List: r#"feature = "name""#)), 219 // FIXME(#14407) 220 ungated!(rustc_const_stable, AssumedUsed, template!(List: r#"feature = "name""#)), 221 gated!( 222 allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."), 223 "allow_internal_unstable side-steps feature gating and stability checks", 224 ), 225 gated!( 226 rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."), 227 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks" 228 ), 229 gated!( 230 allow_internal_unsafe, Normal, template!(Word), 231 "allow_internal_unsafe side-steps the unsafe_code lint", 232 ), 233 234 // ========================================================================== 235 // Internal attributes: Type system related: 236 // ========================================================================== 237 238 gated!(fundamental, AssumedUsed, template!(Word), experimental!(fundamental)), 239 gated!( 240 may_dangle, Normal, template!(Word), dropck_eyepatch, 241 "`may_dangle` has unstable semantics and may be removed in the future", 242 ), 243 244 // ========================================================================== 245 // Internal attributes: Runtime related: 246 // ========================================================================== 247 248 rustc_attr!(rustc_allocator, AssumedUsed, template!(Word), IMPL_DETAIL), 249 rustc_attr!(rustc_allocator_nounwind, AssumedUsed, template!(Word), IMPL_DETAIL), 250 gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)), 251 gated!( 252 default_lib_allocator, AssumedUsed, template!(Word), allocator_internals, 253 experimental!(default_lib_allocator), 254 ), 255 gated!( 256 needs_allocator, Normal, template!(Word), allocator_internals, 257 experimental!(needs_allocator), 258 ), 259 gated!(panic_runtime, AssumedUsed, template!(Word), experimental!(panic_runtime)), 260 gated!(needs_panic_runtime, AssumedUsed, template!(Word), experimental!(needs_panic_runtime)), 261 gated!( 262 unwind, AssumedUsed, template!(List: "allowed|aborts"), unwind_attributes, 263 experimental!(unwind), 264 ), 265 gated!( 266 compiler_builtins, AssumedUsed, template!(Word), 267 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \ 268 which contains compiler-rt intrinsics and will never be stable", 269 ), 270 gated!( 271 profiler_runtime, AssumedUsed, template!(Word), 272 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \ 273 which contains the profiler runtime and will never be stable", 274 ), 275 276 // ========================================================================== 277 // Internal attributes, Linkage: 278 // ========================================================================== 279 280 gated!( 281 linkage, AssumedUsed, template!(NameValueStr: "external|internal|..."), 282 "the `linkage` attribute is experimental and not portable across platforms", 283 ), 284 rustc_attr!(rustc_std_internal_symbol, AssumedUsed, template!(Word), INTERNAL_UNSTABLE), 285 286 // ========================================================================== 287 // Internal attributes, Macro related: 288 // ========================================================================== 289 290 rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word, NameValueStr: "name"), IMPL_DETAIL), 291 rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE), 292 rustc_attr!( 293 rustc_macro_transparency, AssumedUsed, 294 template!(NameValueStr: "transparent|semitransparent|opaque"), 295 "used internally for testing macro hygiene", 296 ), 297 298 // ========================================================================== 299 // Internal attributes, Diagnostics related: 300 // ========================================================================== 301 302 rustc_attr!( 303 rustc_on_unimplemented, AssumedUsed, 304 template!( 305 List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#, 306 NameValueStr: "message" 307 ), 308 INTERNAL_UNSTABLE 309 ), 310 // Enumerates "identity-like" conversion methods to suggest on type mismatch. 311 rustc_attr!(rustc_conversion_suggestion, AssumedUsed, template!(Word), INTERNAL_UNSTABLE), 312 313 // ========================================================================== 314 // Internal attributes, Const related: 315 // ========================================================================== 316 317 rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL), 318 rustc_attr!(rustc_legacy_const_generics, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE), 319 320 // ========================================================================== 321 // Internal attributes, Layout related: 322 // ========================================================================== 323 324 rustc_attr!( 325 rustc_layout_scalar_valid_range_start, AssumedUsed, template!(List: "value"), 326 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ 327 niche optimizations in libcore and will never be stable", 328 ), 329 rustc_attr!( 330 rustc_layout_scalar_valid_range_end, AssumedUsed, template!(List: "value"), 331 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ 332 niche optimizations in libcore and will never be stable", 333 ), 334 rustc_attr!( 335 rustc_nonnull_optimization_guaranteed, AssumedUsed, template!(Word), 336 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \ 337 niche optimizations in libcore and will never be stable", 338 ), 339 340 // ========================================================================== 341 // Internal attributes, Misc: 342 // ========================================================================== 343 gated!( 344 lang, Normal, template!(NameValueStr: "name"), lang_items, 345 "language items are subject to change", 346 ), 347 gated!(rustc_diagnostic_item), // XXX modified in rust-analyzer 348 gated!( 349 // Used in resolve: 350 prelude_import, AssumedUsed, template!(Word), 351 "`#[prelude_import]` is for use by rustc only", 352 ), 353 gated!( 354 rustc_paren_sugar, Normal, template!(Word), unboxed_closures, 355 "unboxed_closures are still evolving", 356 ), 357 rustc_attr!( 358 rustc_inherit_overflow_checks, AssumedUsed, template!(Word), 359 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \ 360 overflow checking behavior of several libcore functions that are inlined \ 361 across crates and will never be stable", 362 ), 363 rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"), 364 "the `#[rustc_reservation_impl]` attribute is internally used \ 365 for reserving for `for<T> From<!> for T` impl" 366 ), 367 rustc_attr!( 368 rustc_test_marker, Normal, template!(Word), 369 "the `#[rustc_test_marker]` attribute is used internally to track tests", 370 ), 371 rustc_attr!( 372 rustc_unsafe_specialization_marker, Normal, template!(Word), 373 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations" 374 ), 375 rustc_attr!( 376 rustc_specialization_trait, Normal, template!(Word), 377 "the `#[rustc_specialization_trait]` attribute is used to check specializations" 378 ), 379 rustc_attr!( 380 rustc_main, Normal, template!(Word), 381 "the `#[rustc_main]` attribute is used internally to specify test entry point function", 382 ), 383 rustc_attr!( 384 rustc_skip_array_during_method_dispatch, Normal, template!(Word), 385 "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \ 386 from method dispatch when the receiver is an array, for compatibility in editions < 2021." 387 ), 388 389 // ========================================================================== 390 // Internal attributes, Testing: 391 // ========================================================================== 392 393 rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)), 394 rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word)), 395 rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word)), 396 rustc_attr!(TEST, rustc_variance, Normal, template!(Word)), 397 rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")), 398 rustc_attr!(TEST, rustc_regions, Normal, template!(Word)), 399 rustc_attr!( 400 TEST, rustc_error, AssumedUsed, 401 template!(Word, List: "delay_span_bug_from_inside_query") 402 ), 403 rustc_attr!(TEST, rustc_dump_user_substs, AssumedUsed, template!(Word)), 404 rustc_attr!(TEST, rustc_evaluate_where_clauses, AssumedUsed, template!(Word)), 405 rustc_attr!(TEST, rustc_if_this_changed, AssumedUsed, template!(Word, List: "DepNode")), 406 rustc_attr!(TEST, rustc_then_this_would_need, AssumedUsed, template!(List: "DepNode")), 407 rustc_attr!( 408 TEST, rustc_clean, AssumedUsed, 409 template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), 410 ), 411 rustc_attr!( 412 TEST, rustc_partition_reused, AssumedUsed, 413 template!(List: r#"cfg = "...", module = "...""#), 414 ), 415 rustc_attr!( 416 TEST, rustc_partition_codegened, AssumedUsed, 417 template!(List: r#"cfg = "...", module = "...""#), 418 ), 419 rustc_attr!( 420 TEST, rustc_expected_cgu_reuse, AssumedUsed, 421 template!(List: r#"cfg = "...", module = "...", kind = "...""#), 422 ), 423 rustc_attr!(TEST, rustc_synthetic, AssumedUsed, template!(Word)), 424 rustc_attr!(TEST, rustc_symbol_name, AssumedUsed, template!(Word)), 425 rustc_attr!(TEST, rustc_polymorphize_error, AssumedUsed, template!(Word)), 426 rustc_attr!(TEST, rustc_def_path, AssumedUsed, template!(Word)), 427 rustc_attr!(TEST, rustc_mir, AssumedUsed, template!(List: "arg1, arg2, ...")), 428 rustc_attr!(TEST, rustc_dump_program_clauses, AssumedUsed, template!(Word)), 429 rustc_attr!(TEST, rustc_dump_env_program_clauses, AssumedUsed, template!(Word)), 430 rustc_attr!(TEST, rustc_object_lifetime_default, AssumedUsed, template!(Word)), 431 rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)), 432 gated!( 433 omit_gdb_pretty_printer_section, AssumedUsed, template!(Word), 434 "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite", 435 ), 436 ]; 437