1use std::sync::LazyLock;
4
5use AttributeDuplicates::*;
6use AttributeGate::*;
7use AttributeType::*;
8use rustc_data_structures::fx::FxHashMap;
9use rustc_hir::AttrStyle;
10use rustc_hir::attrs::EncodeCrossCrate;
11use rustc_span::edition::Edition;
12use rustc_span::{Symbol, sym};
13
14use crate::Features;
15
16type GateFn = fn(&Features) -> bool;
17
18pub type GatedCfg = (Symbol, Symbol, GateFn);
19
20const GATED_CFGS: &[GatedCfg] = &[
22 (sym::overflow_checks, sym::cfg_overflow_checks, Features::cfg_overflow_checks),
24 (sym::ub_checks, sym::cfg_ub_checks, Features::cfg_ub_checks),
25 (sym::contract_checks, sym::cfg_contract_checks, Features::cfg_contract_checks),
26 (sym::target_thread_local, sym::cfg_target_thread_local, Features::cfg_target_thread_local),
27 (
28 sym::target_has_atomic_equal_alignment,
29 sym::cfg_target_has_atomic_equal_alignment,
30 Features::cfg_target_has_atomic_equal_alignment,
31 ),
32 (
33 sym::target_has_atomic_load_store,
34 sym::cfg_target_has_atomic,
35 Features::cfg_target_has_atomic,
36 ),
37 (sym::sanitize, sym::cfg_sanitize, Features::cfg_sanitize),
38 (sym::version, sym::cfg_version, Features::cfg_version),
39 (sym::relocation_model, sym::cfg_relocation_model, Features::cfg_relocation_model),
40 (sym::sanitizer_cfi_generalize_pointers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
41 (sym::sanitizer_cfi_normalize_integers, sym::cfg_sanitizer_cfi, Features::cfg_sanitizer_cfi),
42 (sym::fmt_debug, sym::fmt_debug, Features::fmt_debug),
44 (sym::emscripten_wasm_eh, sym::cfg_emscripten_wasm_eh, Features::cfg_emscripten_wasm_eh),
45 (
46 sym::target_has_reliable_f16,
47 sym::cfg_target_has_reliable_f16_f128,
48 Features::cfg_target_has_reliable_f16_f128,
49 ),
50 (
51 sym::target_has_reliable_f16_math,
52 sym::cfg_target_has_reliable_f16_f128,
53 Features::cfg_target_has_reliable_f16_f128,
54 ),
55 (
56 sym::target_has_reliable_f128,
57 sym::cfg_target_has_reliable_f16_f128,
58 Features::cfg_target_has_reliable_f16_f128,
59 ),
60 (
61 sym::target_has_reliable_f128_math,
62 sym::cfg_target_has_reliable_f16_f128,
63 Features::cfg_target_has_reliable_f16_f128,
64 ),
65];
66
67pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
69 GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
70}
71
72#[derive(Copy, Clone, PartialEq, Debug)]
77pub enum AttributeType {
78 Normal,
81
82 CrateLevel,
84}
85
86#[derive(Copy, Clone, PartialEq, Debug)]
87pub enum AttributeSafety {
88 Normal,
90
91 Unsafe { unsafe_since: Option<Edition> },
97}
98
99#[derive(Clone, Debug, Copy)]
100pub enum AttributeGate {
101 Gated {
103 feature: Symbol,
105 message: &'static str,
107 check: fn(&Features) -> bool,
109 notes: &'static [&'static str],
111 },
112 Ungated,
114}
115
116#[derive(Clone, Copy, Default)]
120pub struct AttributeTemplate {
121 pub word: bool,
123 pub list: Option<&'static [&'static str]>,
125 pub one_of: &'static [Symbol],
128 pub name_value_str: Option<&'static [&'static str]>,
131 pub docs: Option<&'static str>,
133}
134
135impl AttributeTemplate {
136 pub fn suggestions(&self, style: AttrStyle, name: impl std::fmt::Display) -> Vec<String> {
137 let mut suggestions = vec![];
138 let inner = match style {
139 AttrStyle::Outer => "",
140 AttrStyle::Inner => "!",
141 };
142 if self.word {
143 suggestions.push(format!("#{inner}[{name}]"));
144 }
145 if let Some(descr) = self.list {
146 for descr in descr {
147 suggestions.push(format!("#{inner}[{name}({descr})]"));
148 }
149 }
150 suggestions.extend(self.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]")));
151 if let Some(descr) = self.name_value_str {
152 for descr in descr {
153 suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
154 }
155 }
156 suggestions.sort();
157
158 suggestions
159 }
160}
161
162#[derive(Clone, Copy, Default)]
164pub enum AttributeDuplicates {
165 #[default]
172 DuplicatesOk,
173 WarnFollowing,
179 WarnFollowingWordOnly,
185 ErrorFollowing,
191 ErrorPreceding,
197 FutureWarnFollowing,
204 FutureWarnPreceding,
211}
212
213#[macro_export]
217macro_rules! template {
218 (Word) => { $crate::template!(@ true, None, &[], None, None) };
219 (Word, $link: literal) => { $crate::template!(@ true, None, &[], None, Some($link)) };
220 (List: $descr: expr) => { $crate::template!(@ false, Some($descr), &[], None, None) };
221 (List: $descr: expr, $link: literal) => { $crate::template!(@ false, Some($descr), &[], None, Some($link)) };
222 (OneOf: $one_of: expr) => { $crate::template!(@ false, None, $one_of, None, None) };
223 (NameValueStr: [$($descr: literal),* $(,)?]) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), None) };
224 (NameValueStr: [$($descr: literal),* $(,)?], $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), Some($link)) };
225 (NameValueStr: $descr: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), None) };
226 (NameValueStr: $descr: literal, $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), Some($link)) };
227 (Word, List: $descr: expr) => { $crate::template!(@ true, Some($descr), &[], None, None) };
228 (Word, List: $descr: expr, $link: literal) => { $crate::template!(@ true, Some($descr), &[], None, Some($link)) };
229 (Word, NameValueStr: $descr: expr) => { $crate::template!(@ true, None, &[], Some(&[$descr]), None) };
230 (Word, NameValueStr: $descr: expr, $link: literal) => { $crate::template!(@ true, None, &[], Some(&[$descr]), Some($link)) };
231 (List: $descr1: expr, NameValueStr: $descr2: expr) => {
232 $crate::template!(@ false, Some($descr1), &[], Some(&[$descr2]), None)
233 };
234 (List: $descr1: expr, NameValueStr: $descr2: expr, $link: literal) => {
235 $crate::template!(@ false, Some($descr1), &[], Some(&[$descr2]), Some($link))
236 };
237 (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
238 $crate::template!(@ true, Some($descr1), &[], Some(&[$descr2]), None)
239 };
240 (Word, List: $descr1: expr, NameValueStr: $descr2: expr, $link: literal) => {
241 $crate::template!(@ true, Some($descr1), &[], Some(&[$descr2]), Some($link))
242 };
243 (@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr, $link: expr) => { $crate::AttributeTemplate {
244 word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str, docs: $link,
245 } };
246}
247
248macro_rules! ungated {
249 (unsafe($edition:ident) $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
250 BuiltinAttribute {
251 name: sym::$attr,
252 encode_cross_crate: $encode_cross_crate,
253 type_: $typ,
254 safety: AttributeSafety::Unsafe { unsafe_since: Some(Edition::$edition) },
255 template: $tpl,
256 gate: Ungated,
257 duplicates: $duplicates,
258 }
259 };
260 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
261 BuiltinAttribute {
262 name: sym::$attr,
263 encode_cross_crate: $encode_cross_crate,
264 type_: $typ,
265 safety: AttributeSafety::Unsafe { unsafe_since: None },
266 template: $tpl,
267 gate: Ungated,
268 duplicates: $duplicates,
269 }
270 };
271 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
272 BuiltinAttribute {
273 name: sym::$attr,
274 encode_cross_crate: $encode_cross_crate,
275 type_: $typ,
276 safety: AttributeSafety::Normal,
277 template: $tpl,
278 gate: Ungated,
279 duplicates: $duplicates,
280 }
281 };
282}
283
284macro_rules! gated {
285 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $gate:ident, $message:expr $(,)?) => {
286 BuiltinAttribute {
287 name: sym::$attr,
288 encode_cross_crate: $encode_cross_crate,
289 type_: $typ,
290 safety: AttributeSafety::Unsafe { unsafe_since: None },
291 template: $tpl,
292 duplicates: $duplicates,
293 gate: Gated {
294 feature: sym::$gate,
295 message: $message,
296 check: Features::$gate,
297 notes: &[],
298 },
299 }
300 };
301 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $message:expr $(,)?) => {
302 BuiltinAttribute {
303 name: sym::$attr,
304 encode_cross_crate: $encode_cross_crate,
305 type_: $typ,
306 safety: AttributeSafety::Unsafe { unsafe_since: None },
307 template: $tpl,
308 duplicates: $duplicates,
309 gate: Gated {
310 feature: sym::$attr,
311 message: $message,
312 check: Features::$attr,
313 notes: &[],
314 },
315 }
316 };
317 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $gate:ident, $message:expr $(,)?) => {
318 BuiltinAttribute {
319 name: sym::$attr,
320 encode_cross_crate: $encode_cross_crate,
321 type_: $typ,
322 safety: AttributeSafety::Normal,
323 template: $tpl,
324 duplicates: $duplicates,
325 gate: Gated {
326 feature: sym::$gate,
327 message: $message,
328 check: Features::$gate,
329 notes: &[],
330 },
331 }
332 };
333 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $message:expr $(,)?) => {
334 BuiltinAttribute {
335 name: sym::$attr,
336 encode_cross_crate: $encode_cross_crate,
337 type_: $typ,
338 safety: AttributeSafety::Normal,
339 template: $tpl,
340 duplicates: $duplicates,
341 gate: Gated {
342 feature: sym::$attr,
343 message: $message,
344 check: Features::$attr,
345 notes: &[],
346 },
347 }
348 };
349}
350
351macro_rules! rustc_attr {
352 (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr, $encode_cross_crate:expr $(,)?) => {
353 rustc_attr!(
354 $attr,
355 $typ,
356 $tpl,
357 $duplicate,
358 $encode_cross_crate,
359 concat!(
360 "the `#[",
361 stringify!($attr),
362 "]` attribute is used for rustc unit tests"
363 ),
364 )
365 };
366 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $($notes:expr),* $(,)?) => {
367 BuiltinAttribute {
368 name: sym::$attr,
369 encode_cross_crate: $encode_cross_crate,
370 type_: $typ,
371 safety: AttributeSafety::Normal,
372 template: $tpl,
373 duplicates: $duplicates,
374 gate: Gated {
375 feature: sym::rustc_attrs,
376 message: "use of an internal attribute",
377 check: Features::rustc_attrs,
378 notes: &[
379 concat!("the `#[",
380 stringify!($attr),
381 "]` attribute is an internal implementation detail that will never be stable"),
382 $($notes),*
383 ]
384 },
385 }
386 };
387}
388
389macro_rules! experimental {
390 ($attr:ident) => {
391 concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
392 };
393}
394
395pub struct BuiltinAttribute {
396 pub name: Symbol,
397 pub encode_cross_crate: EncodeCrossCrate,
402 pub type_: AttributeType,
403 pub safety: AttributeSafety,
404 pub template: AttributeTemplate,
405 pub duplicates: AttributeDuplicates,
406 pub gate: AttributeGate,
407}
408
409#[rustfmt::skip]
411pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
412 ungated!(
418 cfg, Normal,
419 template!(
420 List: &["predicate"],
421 "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute"
422 ),
423 DuplicatesOk, EncodeCrossCrate::Yes
424 ),
425 ungated!(
426 cfg_attr, Normal,
427 template!(
428 List: &["predicate, attr1, attr2, ..."],
429 "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute"
430 ),
431 DuplicatesOk, EncodeCrossCrate::Yes
432 ),
433
434 ungated!(
436 ignore, Normal,
437 template!(
438 Word,
439 NameValueStr: "reason",
440 "https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute"
441 ),
442 WarnFollowing, EncodeCrossCrate::No,
443 ),
444 ungated!(
445 should_panic, Normal,
446 template!(
447 Word,
448 List: &[r#"expected = "reason""#],
449 NameValueStr: "reason",
450 "https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute"
451 ),
452 FutureWarnFollowing, EncodeCrossCrate::No,
453 ),
454 ungated!(
456 reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing,
457 EncodeCrossCrate::No,
458 ),
459
460 ungated!(
462 automatically_derived, Normal,
463 template!(
464 Word,
465 "https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute"
466 ),
467 WarnFollowing, EncodeCrossCrate::Yes
468 ),
469 ungated!(
470 macro_use, Normal,
471 template!(
472 Word,
473 List: &["name1, name2, ..."],
474 "https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute"
475 ),
476 WarnFollowingWordOnly, EncodeCrossCrate::No,
477 ),
478 ungated!(macro_escape, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), ungated!(
480 macro_export, Normal,
481 template!(
482 Word,
483 List: &["local_inner_macros"],
484 "https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"
485 ),
486 WarnFollowing, EncodeCrossCrate::Yes
487 ),
488 ungated!(
489 proc_macro, Normal,
490 template!(
491 Word,
492 "https://doc.rust-lang.org/reference/procedural-macros.html#function-like-procedural-macros"),
493 ErrorFollowing, EncodeCrossCrate::No
494 ),
495 ungated!(
496 proc_macro_derive, Normal,
497 template!(
498 List: &["TraitName", "TraitName, attributes(name1, name2, ...)"],
499 "https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros"
500 ),
501 ErrorFollowing, EncodeCrossCrate::No,
502 ),
503 ungated!(
504 proc_macro_attribute, Normal,
505 template!(Word, "https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros"),
506 ErrorFollowing, EncodeCrossCrate::No
507 ),
508
509 ungated!(
511 warn, Normal,
512 template!(
513 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
514 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
515 ),
516 DuplicatesOk, EncodeCrossCrate::No,
517 ),
518 ungated!(
519 allow, Normal,
520 template!(
521 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
522 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
523 ),
524 DuplicatesOk, EncodeCrossCrate::No,
525 ),
526 ungated!(
527 expect, Normal,
528 template!(
529 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
530 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
531 ),
532 DuplicatesOk, EncodeCrossCrate::No,
533 ),
534 ungated!(
535 forbid, Normal,
536 template!(
537 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
538 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
539 ),
540 DuplicatesOk, EncodeCrossCrate::No
541 ),
542 ungated!(
543 deny, Normal,
544 template!(
545 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
546 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
547 ),
548 DuplicatesOk, EncodeCrossCrate::No
549 ),
550 ungated!(
551 must_use, Normal,
552 template!(
553 Word,
554 NameValueStr: "reason",
555 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
556 ),
557 FutureWarnFollowing, EncodeCrossCrate::Yes
558 ),
559 gated!(
560 must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
561 EncodeCrossCrate::Yes, experimental!(must_not_suspend)
562 ),
563 ungated!(
564 deprecated, Normal,
565 template!(
566 Word,
567 List: &[r#"/*opt*/ since = "version", /*opt*/ note = "reason""#],
568 NameValueStr: "reason",
569 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"
570 ),
571 ErrorFollowing, EncodeCrossCrate::Yes
572 ),
573
574 ungated!(
576 crate_name, CrateLevel,
577 template!(
578 NameValueStr: "name",
579 "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute"
580 ),
581 FutureWarnFollowing, EncodeCrossCrate::No,
582 ),
583 ungated!(
584 crate_type, CrateLevel,
585 template!(
586 NameValueStr: ["bin", "lib", "dylib", "cdylib", "rlib", "staticlib", "sdylib", "proc-macro"],
587 "https://doc.rust-lang.org/reference/linkage.html"
588 ),
589 DuplicatesOk, EncodeCrossCrate::No,
590 ),
591
592 ungated!(
594 link, Normal,
595 template!(List: &[
596 r#"name = "...""#,
597 r#"name = "...", kind = "dylib|static|...""#,
598 r#"name = "...", wasm_import_module = "...""#,
599 r#"name = "...", import_name_type = "decorated|noprefix|undecorated""#,
600 r#"name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated""#,
601 ], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute"),
602 DuplicatesOk, EncodeCrossCrate::No,
603 ),
604 ungated!(
605 link_name, Normal,
606 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute"),
607 FutureWarnPreceding, EncodeCrossCrate::Yes
608 ),
609 ungated!(
610 no_link, Normal,
611 template!(Word, "https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute"),
612 WarnFollowing, EncodeCrossCrate::No
613 ),
614 ungated!(
615 repr, Normal,
616 template!(
617 List: &["C", "Rust", "transparent", "align(...)", "packed(...)", "<integer type>"],
618 "https://doc.rust-lang.org/reference/type-layout.html#representations"
619 ),
620 DuplicatesOk, EncodeCrossCrate::No
621 ),
622 gated!(rustc_align, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
624 ungated!(
625 unsafe(Edition2024) export_name, Normal,
626 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute"),
627 FutureWarnPreceding, EncodeCrossCrate::No
628 ),
629 ungated!(
630 unsafe(Edition2024) link_section, Normal,
631 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"),
632 FutureWarnPreceding, EncodeCrossCrate::No
633 ),
634 ungated!(
635 unsafe(Edition2024) no_mangle, Normal,
636 template!(Word, "https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute"),
637 WarnFollowing, EncodeCrossCrate::No
638 ),
639 ungated!(
640 used, Normal,
641 template!(Word, List: &["compiler", "linker"], "https://doc.rust-lang.org/reference/abi.html#the-used-attribute"),
642 WarnFollowing, EncodeCrossCrate::No
643 ),
644 ungated!(
645 link_ordinal, Normal,
646 template!(List: &["ordinal"], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute"),
647 ErrorPreceding, EncodeCrossCrate::Yes
648 ),
649 ungated!(
650 unsafe naked, Normal,
651 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-naked-attribute"),
652 WarnFollowing, EncodeCrossCrate::No
653 ),
654
655 ungated!(
657 recursion_limit, CrateLevel,
658 template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute"),
659 FutureWarnFollowing, EncodeCrossCrate::No
660 ),
661 ungated!(
662 type_length_limit, CrateLevel,
663 template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-type_length_limit-attribute"),
664 FutureWarnFollowing, EncodeCrossCrate::No
665 ),
666 gated!(
667 move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
668 EncodeCrossCrate::No, large_assignments, experimental!(move_size_limit)
669 ),
670
671 ungated!(
673 no_main, CrateLevel,
674 template!(Word, "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-no_main-attribute"),
675 WarnFollowing, EncodeCrossCrate::No
676 ),
677
678 ungated!(
680 path, Normal,
681 template!(NameValueStr: "file", "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"),
682 FutureWarnFollowing, EncodeCrossCrate::No
683 ),
684 ungated!(
685 no_std, CrateLevel,
686 template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute"),
687 WarnFollowing, EncodeCrossCrate::No
688 ),
689 ungated!(
690 no_implicit_prelude, Normal,
691 template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_implicit_prelude-attribute"),
692 WarnFollowing, EncodeCrossCrate::No
693 ),
694 ungated!(
695 non_exhaustive, Normal,
696 template!(Word, "https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute"),
697 WarnFollowing, EncodeCrossCrate::Yes
698 ),
699
700 ungated!(
702 windows_subsystem, CrateLevel,
703 template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute"),
704 FutureWarnFollowing, EncodeCrossCrate::No
705 ),
706 ungated!( panic_handler, Normal,
708 template!(Word, "https://doc.rust-lang.org/reference/panic.html#the-panic_handler-attribute"),
709 WarnFollowing, EncodeCrossCrate::Yes
710 ),
711
712 ungated!(
714 inline, Normal,
715 template!(
716 Word,
717 List: &["always", "never"],
718 "https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute"
719 ),
720 FutureWarnFollowing, EncodeCrossCrate::No
721 ),
722 ungated!(
723 cold, Normal,
724 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-cold-attribute"),
725 WarnFollowing, EncodeCrossCrate::No
726 ),
727 ungated!(
728 no_builtins, CrateLevel,
729 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-no_builtins-attribute"),
730 WarnFollowing, EncodeCrossCrate::Yes
731 ),
732 ungated!(
733 target_feature, Normal,
734 template!(List: &[r#"enable = "name""#], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute"),
735 DuplicatesOk, EncodeCrossCrate::No,
736 ),
737 ungated!(
738 track_caller, Normal,
739 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute"),
740 WarnFollowing, EncodeCrossCrate::Yes
741 ),
742 ungated!(
743 instruction_set, Normal,
744 template!(List: &["set"], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute"),
745 ErrorPreceding, EncodeCrossCrate::No
746 ),
747 gated!(
748 sanitize, Normal, template!(List: &[r#"address = "on|off""#, r#"kernel_address = "on|off""#, r#"cfi = "on|off""#, r#"hwaddress = "on|off""#, r#"kcfi = "on|off""#, r#"memory = "on|off""#, r#"memtag = "on|off""#, r#"shadow_call_stack = "on|off""#, r#"thread = "on|off""#]), ErrorPreceding,
749 EncodeCrossCrate::No, sanitize, experimental!(sanitize),
750 ),
751 gated!(
752 coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
753 ErrorPreceding, EncodeCrossCrate::No,
754 coverage_attribute, experimental!(coverage)
755 ),
756
757 ungated!(
758 doc, Normal,
759 template!(
760 List: &["hidden", "inline"],
761 NameValueStr: "string",
762 "https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html"
763 ),
764 DuplicatesOk, EncodeCrossCrate::Yes
765 ),
766
767 ungated!(
769 debugger_visualizer, Normal,
770 template!(
771 List: &[r#"natvis_file = "...", gdb_script_file = "...""#],
772 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"
773 ),
774 DuplicatesOk, EncodeCrossCrate::No
775 ),
776 ungated!(
777 collapse_debuginfo, Normal,
778 template!(
779 List: &["no", "external", "yes"],
780 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-collapse_debuginfo-attribute"
781 ),
782 ErrorFollowing, EncodeCrossCrate::Yes
783 ),
784
785 gated!(
791 export_stable, Normal, template!(Word), WarnFollowing,
792 EncodeCrossCrate::No, experimental!(export_stable)
793 ),
794
795 gated!(
797 test_runner, CrateLevel, template!(List: &["path"]), ErrorFollowing,
798 EncodeCrossCrate::Yes, custom_test_frameworks,
799 "custom test frameworks are an unstable feature",
800 ),
801 gated!(
803 marker, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
804 marker_trait_attr, experimental!(marker)
805 ),
806 gated!(
807 thread_local, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
808 "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
809 ),
810 gated!(
811 no_core, CrateLevel, template!(Word), WarnFollowing,
812 EncodeCrossCrate::No, experimental!(no_core)
813 ),
814 gated!(
816 optimize, Normal, template!(List: &["none", "size", "speed"]), ErrorPreceding,
817 EncodeCrossCrate::No, optimize_attribute, experimental!(optimize)
818 ),
819
820 gated!(
821 unsafe ffi_pure, Normal, template!(Word), WarnFollowing,
822 EncodeCrossCrate::No, experimental!(ffi_pure)
823 ),
824 gated!(
825 unsafe ffi_const, Normal, template!(Word), WarnFollowing,
826 EncodeCrossCrate::No, experimental!(ffi_const)
827 ),
828 gated!(
829 register_tool, CrateLevel, template!(List: &["tool1, tool2, ..."]), DuplicatesOk,
830 EncodeCrossCrate::No, experimental!(register_tool),
831 ),
832
833 gated!(
836 const_trait, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, const_trait_impl,
837 "`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
838 `impls` and all default bodies as `const`, which may be removed or renamed in the \
839 future."
840 ),
841 gated!(
843 deprecated_safe, Normal, template!(List: &[r#"since = "version", note = "...""#]), ErrorFollowing,
844 EncodeCrossCrate::Yes, experimental!(deprecated_safe),
845 ),
846
847 gated!(
849 cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
850 EncodeCrossCrate::Yes, experimental!(cfi_encoding)
851 ),
852
853 gated!(
855 coroutine, Normal, template!(Word), ErrorFollowing,
856 EncodeCrossCrate::No, coroutines, experimental!(coroutine)
857 ),
858
859 gated!(
862 patchable_function_entry, Normal, template!(List: &["prefix_nops = m, entry_nops = n"]), ErrorPreceding,
863 EncodeCrossCrate::Yes, experimental!(patchable_function_entry)
864 ),
865
866 gated!(
869 type_const, Normal, template!(Word), ErrorFollowing,
870 EncodeCrossCrate::Yes, min_generic_const_args, experimental!(type_const),
871 ),
872
873 gated!(
878 const_continue, Normal, template!(Word), ErrorFollowing,
879 EncodeCrossCrate::No, loop_match, experimental!(const_continue)
880 ),
881 gated!(
882 loop_match, Normal, template!(Word), ErrorFollowing,
883 EncodeCrossCrate::No, loop_match, experimental!(loop_match)
884 ),
885
886 ungated!(
891 feature, CrateLevel,
892 template!(List: &["name1, name2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
893 ),
894 ungated!(
896 stable, Normal,
897 template!(List: &[r#"feature = "name", since = "version""#]), DuplicatesOk, EncodeCrossCrate::No,
898 ),
899 ungated!(
900 unstable, Normal,
901 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), DuplicatesOk,
902 EncodeCrossCrate::Yes
903 ),
904 ungated!(
905 unstable_feature_bound, Normal, template!(Word, List: &["feat1, feat2, ..."]),
906 DuplicatesOk, EncodeCrossCrate::No,
907 ),
908 ungated!(
909 rustc_const_unstable, Normal, template!(List: &[r#"feature = "name""#]),
910 DuplicatesOk, EncodeCrossCrate::Yes
911 ),
912 ungated!(
913 rustc_const_stable, Normal,
914 template!(List: &[r#"feature = "name""#]), DuplicatesOk, EncodeCrossCrate::No,
915 ),
916 ungated!(
917 rustc_default_body_unstable, Normal,
918 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]),
919 DuplicatesOk, EncodeCrossCrate::No
920 ),
921 gated!(
922 allow_internal_unstable, Normal, template!(Word, List: &["feat1, feat2, ..."]),
923 DuplicatesOk, EncodeCrossCrate::Yes,
924 "allow_internal_unstable side-steps feature gating and stability checks",
925 ),
926 gated!(
927 allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
928 EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint",
929 ),
930 rustc_attr!(
931 rustc_allowed_through_unstable_modules, Normal, template!(NameValueStr: "deprecation message"),
932 WarnFollowing, EncodeCrossCrate::No,
933 "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
934 through unstable paths"
935 ),
936 rustc_attr!(
937 rustc_deprecated_safe_2024, Normal, template!(List: &[r#"audit_that = "...""#]),
938 ErrorFollowing, EncodeCrossCrate::Yes,
939 "`#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary",
940 ),
941 rustc_attr!(
942 rustc_pub_transparent, Normal, template!(Word),
943 ErrorFollowing, EncodeCrossCrate::Yes,
944 "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
945 ),
946
947
948 gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)),
953 gated!(
954 may_dangle, Normal, template!(Word), WarnFollowing,
955 EncodeCrossCrate::No, dropck_eyepatch,
956 "`may_dangle` has unstable semantics and may be removed in the future",
957 ),
958
959 rustc_attr!(
960 rustc_never_type_options,
961 Normal,
962 template!(List: &[
963 "",
964 r#"fallback = "unit""#,
965 r#"fallback = "niko""#,
966 r#"fallback = "never""#,
967 r#"fallback = "no""#,
968 ]),
969 ErrorFollowing,
970 EncodeCrossCrate::No,
971 "`rustc_never_type_options` is used to experiment with never type fallback and work on \
972 never type stabilization"
973 ),
974
975 rustc_attr!(
980 rustc_allocator, Normal, template!(Word), WarnFollowing,
981 EncodeCrossCrate::No,
982 ),
983 rustc_attr!(
984 rustc_nounwind, Normal, template!(Word), WarnFollowing,
985 EncodeCrossCrate::No,
986 ),
987 rustc_attr!(
988 rustc_reallocator, Normal, template!(Word), WarnFollowing,
989 EncodeCrossCrate::No,
990 ),
991 rustc_attr!(
992 rustc_deallocator, Normal, template!(Word), WarnFollowing,
993 EncodeCrossCrate::No,
994 ),
995 rustc_attr!(
996 rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing,
997 EncodeCrossCrate::No,
998 ),
999 gated!(
1000 default_lib_allocator, Normal, template!(Word), WarnFollowing,
1001 EncodeCrossCrate::No, allocator_internals, experimental!(default_lib_allocator),
1002 ),
1003 gated!(
1004 needs_allocator, Normal, template!(Word), WarnFollowing,
1005 EncodeCrossCrate::No, allocator_internals, experimental!(needs_allocator),
1006 ),
1007 gated!(
1008 panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1009 EncodeCrossCrate::No, experimental!(panic_runtime)
1010 ),
1011 gated!(
1012 needs_panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1013 EncodeCrossCrate::No, experimental!(needs_panic_runtime)
1014 ),
1015 gated!(
1016 compiler_builtins, CrateLevel, template!(Word), WarnFollowing,
1017 EncodeCrossCrate::No,
1018 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
1019 which contains compiler-rt intrinsics and will never be stable",
1020 ),
1021 gated!(
1022 profiler_runtime, CrateLevel, template!(Word), WarnFollowing,
1023 EncodeCrossCrate::No,
1024 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
1025 which contains the profiler runtime and will never be stable",
1026 ),
1027
1028 gated!(
1033 linkage, Normal, template!(NameValueStr: [
1034 "available_externally",
1035 "common",
1036 "extern_weak",
1037 "external",
1038 "internal",
1039 "linkonce",
1040 "linkonce_odr",
1041 "weak",
1042 "weak_odr",
1043 ], "https://doc.rust-lang.org/reference/linkage.html"),
1044 ErrorPreceding, EncodeCrossCrate::No,
1045 "the `linkage` attribute is experimental and not portable across platforms",
1046 ),
1047 rustc_attr!(
1048 rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing,
1049 EncodeCrossCrate::No,
1050 ),
1051
1052 rustc_attr!(
1057 rustc_builtin_macro, Normal,
1058 template!(Word, List: &["name", "name, /*opt*/ attributes(name1, name2, ...)"]), ErrorFollowing,
1059 EncodeCrossCrate::Yes,
1060 ),
1061 rustc_attr!(
1062 rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing,
1063 EncodeCrossCrate::No,
1064 ),
1065 rustc_attr!(
1066 rustc_macro_transparency, Normal,
1067 template!(NameValueStr: ["transparent", "semiopaque", "opaque"]), ErrorFollowing,
1068 EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
1069 ),
1070 rustc_attr!(
1071 rustc_autodiff, Normal,
1072 template!(Word, List: &[r#""...""#]), DuplicatesOk,
1073 EncodeCrossCrate::Yes,
1074 ),
1075 ungated!(
1080 cfg_trace, Normal, template!(Word ), DuplicatesOk,
1081 EncodeCrossCrate::No
1082 ),
1083 ungated!(
1084 cfg_attr_trace, Normal, template!(Word ), DuplicatesOk,
1085 EncodeCrossCrate::No
1086 ),
1087
1088 rustc_attr!(
1093 rustc_on_unimplemented, Normal,
1094 template!(
1095 List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#],
1096 NameValueStr: "message"
1097 ),
1098 ErrorFollowing, EncodeCrossCrate::Yes,
1099 "see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute"
1100 ),
1101 rustc_attr!(
1102 rustc_confusables, Normal,
1103 template!(List: &[r#""name1", "name2", ..."#]),
1104 ErrorFollowing, EncodeCrossCrate::Yes,
1105 ),
1106 rustc_attr!(
1108 rustc_conversion_suggestion, Normal, template!(Word),
1109 WarnFollowing, EncodeCrossCrate::Yes,
1110 ),
1111 rustc_attr!(
1114 rustc_trivial_field_reads, Normal, template!(Word),
1115 WarnFollowing, EncodeCrossCrate::Yes,
1116 ),
1117 rustc_attr!(
1120 rustc_lint_query_instability, Normal, template!(Word),
1121 WarnFollowing, EncodeCrossCrate::Yes,
1122 ),
1123 rustc_attr!(
1126 rustc_lint_untracked_query_information, Normal, template!(Word),
1127 WarnFollowing, EncodeCrossCrate::Yes,
1128 ),
1129 rustc_attr!(
1132 rustc_lint_diagnostics, Normal, template!(Word),
1133 WarnFollowing, EncodeCrossCrate::Yes,
1134 ),
1135 rustc_attr!(
1138 rustc_lint_opt_ty, Normal, template!(Word),
1139 WarnFollowing, EncodeCrossCrate::Yes,
1140 ),
1141 rustc_attr!(
1144 rustc_lint_opt_deny_field_access, Normal, template!(List: &["message"]),
1145 WarnFollowing, EncodeCrossCrate::Yes,
1146 ),
1147
1148 rustc_attr!(
1153 rustc_promotable, Normal, template!(Word), WarnFollowing,
1154 EncodeCrossCrate::No, ),
1155 rustc_attr!(
1156 rustc_legacy_const_generics, Normal, template!(List: &["N"]), ErrorFollowing,
1157 EncodeCrossCrate::Yes,
1158 ),
1159 rustc_attr!(
1161 rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
1162 EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
1163 ),
1164 rustc_attr!(
1165 rustc_const_stable_indirect, Normal,
1166 template!(Word),
1167 WarnFollowing,
1168 EncodeCrossCrate::No,
1169 "this is an internal implementation detail",
1170 ),
1171 rustc_attr!(
1172 rustc_intrinsic_const_stable_indirect, Normal,
1173 template!(Word), WarnFollowing, EncodeCrossCrate::No, "this is an internal implementation detail",
1174 ),
1175 gated!(
1176 rustc_allow_const_fn_unstable, Normal,
1177 template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
1178 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
1179 ),
1180
1181 rustc_attr!(
1186 rustc_layout_scalar_valid_range_start, Normal, template!(List: &["value"]), ErrorFollowing,
1187 EncodeCrossCrate::Yes,
1188 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
1189 niche optimizations in the standard library",
1190 ),
1191 rustc_attr!(
1192 rustc_layout_scalar_valid_range_end, Normal, template!(List: &["value"]), ErrorFollowing,
1193 EncodeCrossCrate::Yes,
1194 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
1195 niche optimizations in the standard library",
1196 ),
1197 rustc_attr!(
1198 rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
1199 EncodeCrossCrate::Yes,
1200 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document \
1201 guaranteed niche optimizations in the standard library",
1202 "the compiler does not even check whether the type indeed is being non-null-optimized; \
1203 it is your responsibility to ensure that the attribute is only used on types that are optimized",
1204 ),
1205
1206 gated!(
1210 lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items,
1211 "lang items are subject to change",
1212 ),
1213 rustc_attr!(
1214 rustc_as_ptr, Normal, template!(Word), ErrorFollowing,
1215 EncodeCrossCrate::Yes,
1216 "`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations."
1217 ),
1218 rustc_attr!(
1219 rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
1220 EncodeCrossCrate::Yes,
1221 "`#[rustc_pass_by_value]` is used to mark types that must be passed by value instead of reference."
1222 ),
1223 rustc_attr!(
1224 rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing,
1225 EncodeCrossCrate::Yes,
1226 "`#[rustc_never_returns_null_ptr]` is used to mark functions returning non-null pointers."
1227 ),
1228 rustc_attr!(
1229 rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
1230 "`#[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."
1231 ),
1232 rustc_attr!(
1233 rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1234 "`#![rustc_coherence_is_core]` allows inherent methods on builtin types, only intended to be used in `core`."
1235 ),
1236 rustc_attr!(
1237 rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1238 "`#[rustc_coinductive]` changes a trait to be coinductive, allowing cycles in the trait solver."
1239 ),
1240 rustc_attr!(
1241 rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1242 "`#[rustc_allow_incoherent_impl]` has to be added to all impl items of an incoherent inherent impl."
1243 ),
1244 rustc_attr!(
1245 rustc_preserve_ub_checks, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1246 "`#![rustc_preserve_ub_checks]` prevents the designated crate from evaluating whether UB checks are enabled when optimizing MIR",
1247 ),
1248 rustc_attr!(
1249 rustc_deny_explicit_impl,
1250 AttributeType::Normal,
1251 template!(Word),
1252 ErrorFollowing,
1253 EncodeCrossCrate::No,
1254 "`#[rustc_deny_explicit_impl]` enforces that a trait can have no user-provided impls"
1255 ),
1256 rustc_attr!(
1257 rustc_do_not_implement_via_object,
1258 AttributeType::Normal,
1259 template!(Word),
1260 ErrorFollowing,
1261 EncodeCrossCrate::No,
1262 "`#[rustc_do_not_implement_via_object]` opts out of the automatic trait impl for trait objects \
1263 (`impl Trait for dyn Trait`)"
1264 ),
1265 rustc_attr!(
1266 rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word),
1267 ErrorFollowing, EncodeCrossCrate::Yes,
1268 "`#[rustc_has_incoherent_inherent_impls]` allows the addition of incoherent inherent impls for \
1269 the given type by annotating all impl items with `#[rustc_allow_incoherent_impl]`."
1270 ),
1271
1272 BuiltinAttribute {
1273 name: sym::rustc_diagnostic_item,
1274 encode_cross_crate: EncodeCrossCrate::Yes,
1276 type_: Normal,
1277 safety: AttributeSafety::Normal,
1278 template: template!(NameValueStr: "name"),
1279 duplicates: ErrorFollowing,
1280 gate: Gated{
1281 feature: sym::rustc_attrs,
1282 message: "use of an internal attribute",
1283 check: Features::rustc_attrs,
1284 notes: &["the `#[rustc_diagnostic_item]` attribute allows the compiler to reference types \
1285 from the standard library for diagnostic purposes"],
1286 },
1287 },
1288 gated!(
1289 prelude_import, Normal, template!(Word), WarnFollowing,
1291 EncodeCrossCrate::No, "`#[prelude_import]` is for use by rustc only",
1292 ),
1293 gated!(
1294 rustc_paren_sugar, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1295 unboxed_closures, "unboxed_closures are still evolving",
1296 ),
1297 rustc_attr!(
1298 rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1299 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
1300 overflow checking behavior of several functions in the standard library that are inlined \
1301 across crates",
1302 ),
1303 rustc_attr!(
1304 rustc_reservation_impl, Normal,
1305 template!(NameValueStr: "reservation message"), ErrorFollowing, EncodeCrossCrate::Yes,
1306 "the `#[rustc_reservation_impl]` attribute is internally used \
1307 for reserving `impl<T> From<!> for T` as part of the effort to stabilize `!`"
1308 ),
1309 rustc_attr!(
1310 rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
1311 EncodeCrossCrate::No, "the `#[rustc_test_marker]` attribute is used internally to track tests",
1312 ),
1313 rustc_attr!(
1314 rustc_unsafe_specialization_marker, Normal, template!(Word),
1315 WarnFollowing, EncodeCrossCrate::No,
1316 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
1317 ),
1318 rustc_attr!(
1319 rustc_specialization_trait, Normal, template!(Word),
1320 WarnFollowing, EncodeCrossCrate::No,
1321 "the `#[rustc_specialization_trait]` attribute is used to check specializations"
1322 ),
1323 rustc_attr!(
1324 rustc_main, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1325 "the `#[rustc_main]` attribute is used internally to specify test entry point function",
1326 ),
1327 rustc_attr!(
1328 rustc_skip_during_method_dispatch, Normal, template!(List: &["array, boxed_slice"]), ErrorFollowing,
1329 EncodeCrossCrate::No,
1330 "the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \
1331 from method dispatch when the receiver is of the following type, for compatibility in \
1332 editions < 2021 (array) or editions < 2024 (boxed_slice)."
1333 ),
1334 rustc_attr!(
1335 rustc_must_implement_one_of, Normal, template!(List: &["function1, function2, ..."]),
1336 ErrorFollowing, EncodeCrossCrate::No,
1337 "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
1338 definition of a trait. Its syntax and semantics are highly experimental and will be \
1339 subject to change before stabilization",
1340 ),
1341 rustc_attr!(
1342 rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
1343 EncodeCrossCrate::Yes, "the `#[rustc_doc_primitive]` attribute is used by the standard library \
1344 to provide a way to generate documentation for primitive types",
1345 ),
1346 gated!(
1347 rustc_intrinsic, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, intrinsics,
1348 "the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items",
1349 ),
1350 rustc_attr!(
1351 rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes,
1352 "`#[rustc_no_mir_inline]` prevents the MIR inliner from inlining a function while not affecting codegen"
1353 ),
1354 rustc_attr!(
1355 rustc_force_inline, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, EncodeCrossCrate::Yes,
1356 "`#[rustc_force_inline]` forces a free function to be inlined"
1357 ),
1358
1359 rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
1364 rustc_attr!(
1365 TEST, rustc_outlives, Normal, template!(Word),
1366 WarnFollowing, EncodeCrossCrate::No
1367 ),
1368 rustc_attr!(
1369 TEST, rustc_capture_analysis, Normal, template!(Word),
1370 WarnFollowing, EncodeCrossCrate::No
1371 ),
1372 rustc_attr!(
1373 TEST, rustc_insignificant_dtor, Normal, template!(Word),
1374 WarnFollowing, EncodeCrossCrate::Yes
1375 ),
1376 rustc_attr!(
1377 TEST, rustc_no_implicit_bounds, CrateLevel, template!(Word),
1378 WarnFollowing, EncodeCrossCrate::No
1379 ),
1380 rustc_attr!(
1381 TEST, rustc_strict_coherence, Normal, template!(Word),
1382 WarnFollowing, EncodeCrossCrate::Yes
1383 ),
1384 rustc_attr!(
1385 TEST, rustc_variance, Normal, template!(Word),
1386 WarnFollowing, EncodeCrossCrate::No
1387 ),
1388 rustc_attr!(
1389 TEST, rustc_variance_of_opaques, Normal, template!(Word),
1390 WarnFollowing, EncodeCrossCrate::No
1391 ),
1392 rustc_attr!(
1393 TEST, rustc_hidden_type_of_opaques, Normal, template!(Word),
1394 WarnFollowing, EncodeCrossCrate::No
1395 ),
1396 rustc_attr!(
1397 TEST, rustc_layout, Normal, template!(List: &["field1, field2, ..."]),
1398 WarnFollowing, EncodeCrossCrate::Yes
1399 ),
1400 rustc_attr!(
1401 TEST, rustc_abi, Normal, template!(List: &["field1, field2, ..."]),
1402 WarnFollowing, EncodeCrossCrate::No
1403 ),
1404 rustc_attr!(
1405 TEST, rustc_regions, Normal, template!(Word),
1406 WarnFollowing, EncodeCrossCrate::No
1407 ),
1408 rustc_attr!(
1409 TEST, rustc_delayed_bug_from_inside_query, Normal,
1410 template!(Word),
1411 WarnFollowing, EncodeCrossCrate::No
1412 ),
1413 rustc_attr!(
1414 TEST, rustc_dump_user_args, Normal, template!(Word),
1415 WarnFollowing, EncodeCrossCrate::No
1416 ),
1417 rustc_attr!(
1418 TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing,
1419 EncodeCrossCrate::Yes
1420 ),
1421 rustc_attr!(
1422 TEST, rustc_if_this_changed, Normal, template!(Word, List: &["DepNode"]), DuplicatesOk,
1423 EncodeCrossCrate::No
1424 ),
1425 rustc_attr!(
1426 TEST, rustc_then_this_would_need, Normal, template!(List: &["DepNode"]), DuplicatesOk,
1427 EncodeCrossCrate::No
1428 ),
1429 rustc_attr!(
1430 TEST, rustc_clean, Normal,
1431 template!(List: &[r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#]),
1432 DuplicatesOk, EncodeCrossCrate::No
1433 ),
1434 rustc_attr!(
1435 TEST, rustc_partition_reused, Normal,
1436 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1437 ),
1438 rustc_attr!(
1439 TEST, rustc_partition_codegened, Normal,
1440 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1441 ),
1442 rustc_attr!(
1443 TEST, rustc_expected_cgu_reuse, Normal,
1444 template!(List: &[r#"cfg = "...", module = "...", kind = "...""#]), DuplicatesOk,
1445 EncodeCrossCrate::No
1446 ),
1447 rustc_attr!(
1448 TEST, rustc_symbol_name, Normal, template!(Word),
1449 WarnFollowing, EncodeCrossCrate::No
1450 ),
1451 rustc_attr!(
1452 TEST, rustc_def_path, Normal, template!(Word),
1453 WarnFollowing, EncodeCrossCrate::No
1454 ),
1455 rustc_attr!(
1456 TEST, rustc_mir, Normal, template!(List: &["arg1, arg2, ..."]),
1457 DuplicatesOk, EncodeCrossCrate::Yes
1458 ),
1459 gated!(
1460 custom_mir, Normal, template!(List: &[r#"dialect = "...", phase = "...""#]),
1461 ErrorFollowing, EncodeCrossCrate::No,
1462 "the `#[custom_mir]` attribute is just used for the Rust test suite",
1463 ),
1464 rustc_attr!(
1465 TEST, rustc_dump_item_bounds, Normal, template!(Word),
1466 WarnFollowing, EncodeCrossCrate::No
1467 ),
1468 rustc_attr!(
1469 TEST, rustc_dump_predicates, Normal, template!(Word),
1470 WarnFollowing, EncodeCrossCrate::No
1471 ),
1472 rustc_attr!(
1473 TEST, rustc_dump_def_parents, Normal, template!(Word),
1474 WarnFollowing, EncodeCrossCrate::No
1475 ),
1476 rustc_attr!(
1477 TEST, rustc_object_lifetime_default, Normal, template!(Word),
1478 WarnFollowing, EncodeCrossCrate::No
1479 ),
1480 rustc_attr!(
1481 TEST, rustc_dump_vtable, Normal, template!(Word),
1482 WarnFollowing, EncodeCrossCrate::No
1483 ),
1484 rustc_attr!(
1485 TEST, rustc_dummy, Normal, template!(Word ),
1486 DuplicatesOk, EncodeCrossCrate::No
1487 ),
1488 rustc_attr!(
1489 TEST, pattern_complexity_limit, CrateLevel, template!(NameValueStr: "N"),
1490 ErrorFollowing, EncodeCrossCrate::No,
1491 ),
1492];
1493
1494pub fn is_builtin_attr_name(name: Symbol) -> bool {
1495 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
1496}
1497
1498pub fn encode_cross_crate(name: Symbol) -> bool {
1501 if let Some(attr) = BUILTIN_ATTRIBUTE_MAP.get(&name) {
1502 attr.encode_cross_crate == EncodeCrossCrate::Yes
1503 } else {
1504 true
1505 }
1506}
1507
1508pub fn is_valid_for_get_attr(name: Symbol) -> bool {
1509 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| match attr.duplicates {
1510 WarnFollowing | ErrorFollowing | ErrorPreceding | FutureWarnFollowing
1511 | FutureWarnPreceding => true,
1512 DuplicatesOk | WarnFollowingWordOnly => false,
1513 })
1514}
1515
1516pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
1517 LazyLock::new(|| {
1518 let mut map = FxHashMap::default();
1519 for attr in BUILTIN_ATTRIBUTES.iter() {
1520 if map.insert(attr.name, attr).is_some() {
1521 panic!("duplicate builtin attribute `{}`", attr.name);
1522 }
1523 }
1524 map
1525 });
1526
1527pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
1528 match sym {
1529 sym::on_unimplemented | sym::do_not_recommend => true,
1530 _ => false,
1531 }
1532}