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 unsafe force_target_feature, Normal, template!(List: &[r#"enable = "name""#]),
749 DuplicatesOk, EncodeCrossCrate::No, effective_target_features, experimental!(force_target_feature)
750 ),
751 gated!(
752 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,
753 EncodeCrossCrate::No, sanitize, experimental!(sanitize),
754 ),
755 gated!(
756 coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
757 ErrorPreceding, EncodeCrossCrate::No,
758 coverage_attribute, experimental!(coverage)
759 ),
760
761 ungated!(
762 doc, Normal,
763 template!(
764 List: &["hidden", "inline"],
765 NameValueStr: "string",
766 "https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html"
767 ),
768 DuplicatesOk, EncodeCrossCrate::Yes
769 ),
770
771 ungated!(
773 debugger_visualizer, Normal,
774 template!(
775 List: &[r#"natvis_file = "...", gdb_script_file = "...""#],
776 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"
777 ),
778 DuplicatesOk, EncodeCrossCrate::No
779 ),
780 ungated!(
781 collapse_debuginfo, Normal,
782 template!(
783 List: &["no", "external", "yes"],
784 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-collapse_debuginfo-attribute"
785 ),
786 ErrorFollowing, EncodeCrossCrate::Yes
787 ),
788
789 gated!(
795 export_stable, Normal, template!(Word), WarnFollowing,
796 EncodeCrossCrate::No, experimental!(export_stable)
797 ),
798
799 gated!(
801 test_runner, CrateLevel, template!(List: &["path"]), ErrorFollowing,
802 EncodeCrossCrate::Yes, custom_test_frameworks,
803 "custom test frameworks are an unstable feature",
804 ),
805 gated!(
807 marker, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
808 marker_trait_attr, experimental!(marker)
809 ),
810 gated!(
811 thread_local, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
812 "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
813 ),
814 gated!(
815 no_core, CrateLevel, template!(Word), WarnFollowing,
816 EncodeCrossCrate::No, experimental!(no_core)
817 ),
818 gated!(
820 optimize, Normal, template!(List: &["none", "size", "speed"]), ErrorPreceding,
821 EncodeCrossCrate::No, optimize_attribute, experimental!(optimize)
822 ),
823
824 gated!(
825 unsafe ffi_pure, Normal, template!(Word), WarnFollowing,
826 EncodeCrossCrate::No, experimental!(ffi_pure)
827 ),
828 gated!(
829 unsafe ffi_const, Normal, template!(Word), WarnFollowing,
830 EncodeCrossCrate::No, experimental!(ffi_const)
831 ),
832 gated!(
833 register_tool, CrateLevel, template!(List: &["tool1, tool2, ..."]), DuplicatesOk,
834 EncodeCrossCrate::No, experimental!(register_tool),
835 ),
836
837 gated!(
840 const_trait, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, const_trait_impl,
841 "`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
842 `impls` and all default bodies as `const`, which may be removed or renamed in the \
843 future."
844 ),
845 gated!(
847 deprecated_safe, Normal, template!(List: &[r#"since = "version", note = "...""#]), ErrorFollowing,
848 EncodeCrossCrate::Yes, experimental!(deprecated_safe),
849 ),
850
851 gated!(
853 cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
854 EncodeCrossCrate::Yes, experimental!(cfi_encoding)
855 ),
856
857 gated!(
859 coroutine, Normal, template!(Word), ErrorFollowing,
860 EncodeCrossCrate::No, coroutines, experimental!(coroutine)
861 ),
862
863 gated!(
866 patchable_function_entry, Normal, template!(List: &["prefix_nops = m, entry_nops = n"]), ErrorPreceding,
867 EncodeCrossCrate::Yes, experimental!(patchable_function_entry)
868 ),
869
870 gated!(
873 type_const, Normal, template!(Word), ErrorFollowing,
874 EncodeCrossCrate::Yes, min_generic_const_args, experimental!(type_const),
875 ),
876
877 gated!(
882 const_continue, Normal, template!(Word), ErrorFollowing,
883 EncodeCrossCrate::No, loop_match, experimental!(const_continue)
884 ),
885 gated!(
886 loop_match, Normal, template!(Word), ErrorFollowing,
887 EncodeCrossCrate::No, loop_match, experimental!(loop_match)
888 ),
889
890 ungated!(
895 feature, CrateLevel,
896 template!(List: &["name1, name2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
897 ),
898 ungated!(
900 stable, Normal,
901 template!(List: &[r#"feature = "name", since = "version""#]), DuplicatesOk, EncodeCrossCrate::No,
902 ),
903 ungated!(
904 unstable, Normal,
905 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), DuplicatesOk,
906 EncodeCrossCrate::Yes
907 ),
908 ungated!(
909 unstable_feature_bound, Normal, template!(Word, List: &["feat1, feat2, ..."]),
910 DuplicatesOk, EncodeCrossCrate::No,
911 ),
912 ungated!(
913 rustc_const_unstable, Normal, template!(List: &[r#"feature = "name""#]),
914 DuplicatesOk, EncodeCrossCrate::Yes
915 ),
916 ungated!(
917 rustc_const_stable, Normal,
918 template!(List: &[r#"feature = "name""#]), DuplicatesOk, EncodeCrossCrate::No,
919 ),
920 ungated!(
921 rustc_default_body_unstable, Normal,
922 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]),
923 DuplicatesOk, EncodeCrossCrate::No
924 ),
925 gated!(
926 allow_internal_unstable, Normal, template!(Word, List: &["feat1, feat2, ..."]),
927 DuplicatesOk, EncodeCrossCrate::Yes,
928 "allow_internal_unstable side-steps feature gating and stability checks",
929 ),
930 gated!(
931 allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
932 EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint",
933 ),
934 rustc_attr!(
935 rustc_allowed_through_unstable_modules, Normal, template!(NameValueStr: "deprecation message"),
936 WarnFollowing, EncodeCrossCrate::No,
937 "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
938 through unstable paths"
939 ),
940 rustc_attr!(
941 rustc_deprecated_safe_2024, Normal, template!(List: &[r#"audit_that = "...""#]),
942 ErrorFollowing, EncodeCrossCrate::Yes,
943 "`#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary",
944 ),
945 rustc_attr!(
946 rustc_pub_transparent, Normal, template!(Word),
947 ErrorFollowing, EncodeCrossCrate::Yes,
948 "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
949 ),
950
951
952 gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)),
957 gated!(
958 may_dangle, Normal, template!(Word), WarnFollowing,
959 EncodeCrossCrate::No, dropck_eyepatch,
960 "`may_dangle` has unstable semantics and may be removed in the future",
961 ),
962
963 rustc_attr!(
964 rustc_never_type_options,
965 Normal,
966 template!(List: &[
967 "",
968 r#"fallback = "unit""#,
969 r#"fallback = "niko""#,
970 r#"fallback = "never""#,
971 r#"fallback = "no""#,
972 ]),
973 ErrorFollowing,
974 EncodeCrossCrate::No,
975 "`rustc_never_type_options` is used to experiment with never type fallback and work on \
976 never type stabilization"
977 ),
978
979 rustc_attr!(
984 rustc_allocator, Normal, template!(Word), WarnFollowing,
985 EncodeCrossCrate::No,
986 ),
987 rustc_attr!(
988 rustc_nounwind, Normal, template!(Word), WarnFollowing,
989 EncodeCrossCrate::No,
990 ),
991 rustc_attr!(
992 rustc_reallocator, Normal, template!(Word), WarnFollowing,
993 EncodeCrossCrate::No,
994 ),
995 rustc_attr!(
996 rustc_deallocator, Normal, template!(Word), WarnFollowing,
997 EncodeCrossCrate::No,
998 ),
999 rustc_attr!(
1000 rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing,
1001 EncodeCrossCrate::No,
1002 ),
1003 rustc_attr!(
1004 rustc_allocator_zeroed_variant, Normal, template!(NameValueStr: "function"), ErrorPreceding,
1005 EncodeCrossCrate::Yes,
1006 ),
1007 gated!(
1008 default_lib_allocator, Normal, template!(Word), WarnFollowing,
1009 EncodeCrossCrate::No, allocator_internals, experimental!(default_lib_allocator),
1010 ),
1011 gated!(
1012 needs_allocator, Normal, template!(Word), WarnFollowing,
1013 EncodeCrossCrate::No, allocator_internals, experimental!(needs_allocator),
1014 ),
1015 gated!(
1016 panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1017 EncodeCrossCrate::No, experimental!(panic_runtime)
1018 ),
1019 gated!(
1020 needs_panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1021 EncodeCrossCrate::No, experimental!(needs_panic_runtime)
1022 ),
1023 gated!(
1024 compiler_builtins, CrateLevel, template!(Word), WarnFollowing,
1025 EncodeCrossCrate::No,
1026 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
1027 which contains compiler-rt intrinsics and will never be stable",
1028 ),
1029 gated!(
1030 profiler_runtime, CrateLevel, template!(Word), WarnFollowing,
1031 EncodeCrossCrate::No,
1032 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
1033 which contains the profiler runtime and will never be stable",
1034 ),
1035
1036 gated!(
1041 linkage, Normal, template!(NameValueStr: [
1042 "available_externally",
1043 "common",
1044 "extern_weak",
1045 "external",
1046 "internal",
1047 "linkonce",
1048 "linkonce_odr",
1049 "weak",
1050 "weak_odr",
1051 ], "https://doc.rust-lang.org/reference/linkage.html"),
1052 ErrorPreceding, EncodeCrossCrate::No,
1053 "the `linkage` attribute is experimental and not portable across platforms",
1054 ),
1055 rustc_attr!(
1056 rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing,
1057 EncodeCrossCrate::No,
1058 ),
1059
1060 rustc_attr!(
1065 rustc_builtin_macro, Normal,
1066 template!(Word, List: &["name", "name, /*opt*/ attributes(name1, name2, ...)"]), ErrorFollowing,
1067 EncodeCrossCrate::Yes,
1068 ),
1069 rustc_attr!(
1070 rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing,
1071 EncodeCrossCrate::No,
1072 ),
1073 rustc_attr!(
1074 rustc_macro_transparency, Normal,
1075 template!(NameValueStr: ["transparent", "semiopaque", "opaque"]), ErrorFollowing,
1076 EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
1077 ),
1078 rustc_attr!(
1079 rustc_autodiff, Normal,
1080 template!(Word, List: &[r#""...""#]), DuplicatesOk,
1081 EncodeCrossCrate::Yes,
1082 ),
1083 ungated!(
1088 cfg_trace, Normal, template!(Word ), DuplicatesOk,
1089 EncodeCrossCrate::No
1090 ),
1091 ungated!(
1092 cfg_attr_trace, Normal, template!(Word ), DuplicatesOk,
1093 EncodeCrossCrate::No
1094 ),
1095
1096 rustc_attr!(
1101 rustc_on_unimplemented, Normal,
1102 template!(
1103 List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#],
1104 NameValueStr: "message"
1105 ),
1106 ErrorFollowing, EncodeCrossCrate::Yes,
1107 "see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute"
1108 ),
1109 rustc_attr!(
1110 rustc_confusables, Normal,
1111 template!(List: &[r#""name1", "name2", ..."#]),
1112 ErrorFollowing, EncodeCrossCrate::Yes,
1113 ),
1114 rustc_attr!(
1116 rustc_conversion_suggestion, Normal, template!(Word),
1117 WarnFollowing, EncodeCrossCrate::Yes,
1118 ),
1119 rustc_attr!(
1122 rustc_trivial_field_reads, Normal, template!(Word),
1123 WarnFollowing, EncodeCrossCrate::Yes,
1124 ),
1125 rustc_attr!(
1128 rustc_lint_query_instability, Normal, template!(Word),
1129 WarnFollowing, EncodeCrossCrate::Yes,
1130 ),
1131 rustc_attr!(
1134 rustc_lint_untracked_query_information, Normal, template!(Word),
1135 WarnFollowing, EncodeCrossCrate::Yes,
1136 ),
1137 rustc_attr!(
1140 rustc_lint_diagnostics, Normal, template!(Word),
1141 WarnFollowing, EncodeCrossCrate::Yes,
1142 ),
1143 rustc_attr!(
1146 rustc_lint_opt_ty, Normal, template!(Word),
1147 WarnFollowing, EncodeCrossCrate::Yes,
1148 ),
1149 rustc_attr!(
1152 rustc_lint_opt_deny_field_access, Normal, template!(List: &["message"]),
1153 WarnFollowing, EncodeCrossCrate::Yes,
1154 ),
1155
1156 rustc_attr!(
1161 rustc_promotable, Normal, template!(Word), WarnFollowing,
1162 EncodeCrossCrate::No, ),
1163 rustc_attr!(
1164 rustc_legacy_const_generics, Normal, template!(List: &["N"]), ErrorFollowing,
1165 EncodeCrossCrate::Yes,
1166 ),
1167 rustc_attr!(
1169 rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
1170 EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
1171 ),
1172 rustc_attr!(
1173 rustc_const_stable_indirect, Normal,
1174 template!(Word),
1175 WarnFollowing,
1176 EncodeCrossCrate::No,
1177 "this is an internal implementation detail",
1178 ),
1179 rustc_attr!(
1180 rustc_intrinsic_const_stable_indirect, Normal,
1181 template!(Word), WarnFollowing, EncodeCrossCrate::No, "this is an internal implementation detail",
1182 ),
1183 gated!(
1184 rustc_allow_const_fn_unstable, Normal,
1185 template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
1186 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
1187 ),
1188
1189 rustc_attr!(
1194 rustc_layout_scalar_valid_range_start, Normal, template!(List: &["value"]), ErrorFollowing,
1195 EncodeCrossCrate::Yes,
1196 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
1197 niche optimizations in the standard library",
1198 ),
1199 rustc_attr!(
1200 rustc_layout_scalar_valid_range_end, Normal, template!(List: &["value"]), ErrorFollowing,
1201 EncodeCrossCrate::Yes,
1202 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
1203 niche optimizations in the standard library",
1204 ),
1205 rustc_attr!(
1206 rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
1207 EncodeCrossCrate::Yes,
1208 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document \
1209 guaranteed niche optimizations in the standard library",
1210 "the compiler does not even check whether the type indeed is being non-null-optimized; \
1211 it is your responsibility to ensure that the attribute is only used on types that are optimized",
1212 ),
1213
1214 gated!(
1218 lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items,
1219 "lang items are subject to change",
1220 ),
1221 rustc_attr!(
1222 rustc_as_ptr, Normal, template!(Word), ErrorFollowing,
1223 EncodeCrossCrate::Yes,
1224 "`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations."
1225 ),
1226 rustc_attr!(
1227 rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
1228 EncodeCrossCrate::Yes,
1229 "`#[rustc_pass_by_value]` is used to mark types that must be passed by value instead of reference."
1230 ),
1231 rustc_attr!(
1232 rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing,
1233 EncodeCrossCrate::Yes,
1234 "`#[rustc_never_returns_null_ptr]` is used to mark functions returning non-null pointers."
1235 ),
1236 rustc_attr!(
1237 rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
1238 "`#[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."
1239 ),
1240 rustc_attr!(
1241 rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1242 "`#![rustc_coherence_is_core]` allows inherent methods on builtin types, only intended to be used in `core`."
1243 ),
1244 rustc_attr!(
1245 rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1246 "`#[rustc_coinductive]` changes a trait to be coinductive, allowing cycles in the trait solver."
1247 ),
1248 rustc_attr!(
1249 rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1250 "`#[rustc_allow_incoherent_impl]` has to be added to all impl items of an incoherent inherent impl."
1251 ),
1252 rustc_attr!(
1253 rustc_preserve_ub_checks, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1254 "`#![rustc_preserve_ub_checks]` prevents the designated crate from evaluating whether UB checks are enabled when optimizing MIR",
1255 ),
1256 rustc_attr!(
1257 rustc_deny_explicit_impl,
1258 AttributeType::Normal,
1259 template!(Word),
1260 ErrorFollowing,
1261 EncodeCrossCrate::No,
1262 "`#[rustc_deny_explicit_impl]` enforces that a trait can have no user-provided impls"
1263 ),
1264 rustc_attr!(
1265 rustc_do_not_implement_via_object,
1266 AttributeType::Normal,
1267 template!(Word),
1268 ErrorFollowing,
1269 EncodeCrossCrate::No,
1270 "`#[rustc_do_not_implement_via_object]` opts out of the automatic trait impl for trait objects \
1271 (`impl Trait for dyn Trait`)"
1272 ),
1273 rustc_attr!(
1274 rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word),
1275 ErrorFollowing, EncodeCrossCrate::Yes,
1276 "`#[rustc_has_incoherent_inherent_impls]` allows the addition of incoherent inherent impls for \
1277 the given type by annotating all impl items with `#[rustc_allow_incoherent_impl]`."
1278 ),
1279
1280 BuiltinAttribute {
1281 name: sym::rustc_diagnostic_item,
1282 encode_cross_crate: EncodeCrossCrate::Yes,
1284 type_: Normal,
1285 safety: AttributeSafety::Normal,
1286 template: template!(NameValueStr: "name"),
1287 duplicates: ErrorFollowing,
1288 gate: Gated{
1289 feature: sym::rustc_attrs,
1290 message: "use of an internal attribute",
1291 check: Features::rustc_attrs,
1292 notes: &["the `#[rustc_diagnostic_item]` attribute allows the compiler to reference types \
1293 from the standard library for diagnostic purposes"],
1294 },
1295 },
1296 gated!(
1297 prelude_import, Normal, template!(Word), WarnFollowing,
1299 EncodeCrossCrate::No, "`#[prelude_import]` is for use by rustc only",
1300 ),
1301 gated!(
1302 rustc_paren_sugar, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1303 unboxed_closures, "unboxed_closures are still evolving",
1304 ),
1305 rustc_attr!(
1306 rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1307 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
1308 overflow checking behavior of several functions in the standard library that are inlined \
1309 across crates",
1310 ),
1311 rustc_attr!(
1312 rustc_reservation_impl, Normal,
1313 template!(NameValueStr: "reservation message"), ErrorFollowing, EncodeCrossCrate::Yes,
1314 "the `#[rustc_reservation_impl]` attribute is internally used \
1315 for reserving `impl<T> From<!> for T` as part of the effort to stabilize `!`"
1316 ),
1317 rustc_attr!(
1318 rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
1319 EncodeCrossCrate::No, "the `#[rustc_test_marker]` attribute is used internally to track tests",
1320 ),
1321 rustc_attr!(
1322 rustc_unsafe_specialization_marker, Normal, template!(Word),
1323 WarnFollowing, EncodeCrossCrate::No,
1324 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
1325 ),
1326 rustc_attr!(
1327 rustc_specialization_trait, Normal, template!(Word),
1328 WarnFollowing, EncodeCrossCrate::No,
1329 "the `#[rustc_specialization_trait]` attribute is used to check specializations"
1330 ),
1331 rustc_attr!(
1332 rustc_main, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1333 "the `#[rustc_main]` attribute is used internally to specify test entry point function",
1334 ),
1335 rustc_attr!(
1336 rustc_skip_during_method_dispatch, Normal, template!(List: &["array, boxed_slice"]), ErrorFollowing,
1337 EncodeCrossCrate::No,
1338 "the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \
1339 from method dispatch when the receiver is of the following type, for compatibility in \
1340 editions < 2021 (array) or editions < 2024 (boxed_slice)."
1341 ),
1342 rustc_attr!(
1343 rustc_must_implement_one_of, Normal, template!(List: &["function1, function2, ..."]),
1344 ErrorFollowing, EncodeCrossCrate::No,
1345 "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
1346 definition of a trait. Its syntax and semantics are highly experimental and will be \
1347 subject to change before stabilization",
1348 ),
1349 rustc_attr!(
1350 rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
1351 EncodeCrossCrate::Yes, "the `#[rustc_doc_primitive]` attribute is used by the standard library \
1352 to provide a way to generate documentation for primitive types",
1353 ),
1354 gated!(
1355 rustc_intrinsic, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, intrinsics,
1356 "the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items",
1357 ),
1358 rustc_attr!(
1359 rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes,
1360 "`#[rustc_no_mir_inline]` prevents the MIR inliner from inlining a function while not affecting codegen"
1361 ),
1362 rustc_attr!(
1363 rustc_force_inline, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, EncodeCrossCrate::Yes,
1364 "`#[rustc_force_inline]` forces a free function to be inlined"
1365 ),
1366
1367 rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
1372 rustc_attr!(
1373 TEST, rustc_outlives, Normal, template!(Word),
1374 WarnFollowing, EncodeCrossCrate::No
1375 ),
1376 rustc_attr!(
1377 TEST, rustc_capture_analysis, Normal, template!(Word),
1378 WarnFollowing, EncodeCrossCrate::No
1379 ),
1380 rustc_attr!(
1381 TEST, rustc_insignificant_dtor, Normal, template!(Word),
1382 WarnFollowing, EncodeCrossCrate::Yes
1383 ),
1384 rustc_attr!(
1385 TEST, rustc_no_implicit_bounds, CrateLevel, template!(Word),
1386 WarnFollowing, EncodeCrossCrate::No
1387 ),
1388 rustc_attr!(
1389 TEST, rustc_strict_coherence, Normal, template!(Word),
1390 WarnFollowing, EncodeCrossCrate::Yes
1391 ),
1392 rustc_attr!(
1393 TEST, rustc_variance, Normal, template!(Word),
1394 WarnFollowing, EncodeCrossCrate::No
1395 ),
1396 rustc_attr!(
1397 TEST, rustc_variance_of_opaques, Normal, template!(Word),
1398 WarnFollowing, EncodeCrossCrate::No
1399 ),
1400 rustc_attr!(
1401 TEST, rustc_hidden_type_of_opaques, Normal, template!(Word),
1402 WarnFollowing, EncodeCrossCrate::No
1403 ),
1404 rustc_attr!(
1405 TEST, rustc_layout, Normal, template!(List: &["field1, field2, ..."]),
1406 WarnFollowing, EncodeCrossCrate::Yes
1407 ),
1408 rustc_attr!(
1409 TEST, rustc_abi, Normal, template!(List: &["field1, field2, ..."]),
1410 WarnFollowing, EncodeCrossCrate::No
1411 ),
1412 rustc_attr!(
1413 TEST, rustc_regions, Normal, template!(Word),
1414 WarnFollowing, EncodeCrossCrate::No
1415 ),
1416 rustc_attr!(
1417 TEST, rustc_delayed_bug_from_inside_query, Normal,
1418 template!(Word),
1419 WarnFollowing, EncodeCrossCrate::No
1420 ),
1421 rustc_attr!(
1422 TEST, rustc_dump_user_args, Normal, template!(Word),
1423 WarnFollowing, EncodeCrossCrate::No
1424 ),
1425 rustc_attr!(
1426 TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing,
1427 EncodeCrossCrate::Yes
1428 ),
1429 rustc_attr!(
1430 TEST, rustc_if_this_changed, Normal, template!(Word, List: &["DepNode"]), DuplicatesOk,
1431 EncodeCrossCrate::No
1432 ),
1433 rustc_attr!(
1434 TEST, rustc_then_this_would_need, Normal, template!(List: &["DepNode"]), DuplicatesOk,
1435 EncodeCrossCrate::No
1436 ),
1437 rustc_attr!(
1438 TEST, rustc_clean, Normal,
1439 template!(List: &[r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#]),
1440 DuplicatesOk, EncodeCrossCrate::No
1441 ),
1442 rustc_attr!(
1443 TEST, rustc_partition_reused, Normal,
1444 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1445 ),
1446 rustc_attr!(
1447 TEST, rustc_partition_codegened, Normal,
1448 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1449 ),
1450 rustc_attr!(
1451 TEST, rustc_expected_cgu_reuse, Normal,
1452 template!(List: &[r#"cfg = "...", module = "...", kind = "...""#]), DuplicatesOk,
1453 EncodeCrossCrate::No
1454 ),
1455 rustc_attr!(
1456 TEST, rustc_symbol_name, Normal, template!(Word),
1457 WarnFollowing, EncodeCrossCrate::No
1458 ),
1459 rustc_attr!(
1460 TEST, rustc_def_path, Normal, template!(Word),
1461 WarnFollowing, EncodeCrossCrate::No
1462 ),
1463 rustc_attr!(
1464 TEST, rustc_mir, Normal, template!(List: &["arg1, arg2, ..."]),
1465 DuplicatesOk, EncodeCrossCrate::Yes
1466 ),
1467 gated!(
1468 custom_mir, Normal, template!(List: &[r#"dialect = "...", phase = "...""#]),
1469 ErrorFollowing, EncodeCrossCrate::No,
1470 "the `#[custom_mir]` attribute is just used for the Rust test suite",
1471 ),
1472 rustc_attr!(
1473 TEST, rustc_dump_item_bounds, Normal, template!(Word),
1474 WarnFollowing, EncodeCrossCrate::No
1475 ),
1476 rustc_attr!(
1477 TEST, rustc_dump_predicates, Normal, template!(Word),
1478 WarnFollowing, EncodeCrossCrate::No
1479 ),
1480 rustc_attr!(
1481 TEST, rustc_dump_def_parents, Normal, template!(Word),
1482 WarnFollowing, EncodeCrossCrate::No
1483 ),
1484 rustc_attr!(
1485 TEST, rustc_object_lifetime_default, Normal, template!(Word),
1486 WarnFollowing, EncodeCrossCrate::No
1487 ),
1488 rustc_attr!(
1489 TEST, rustc_dump_vtable, Normal, template!(Word),
1490 WarnFollowing, EncodeCrossCrate::No
1491 ),
1492 rustc_attr!(
1493 TEST, rustc_dummy, Normal, template!(Word ),
1494 DuplicatesOk, EncodeCrossCrate::No
1495 ),
1496 rustc_attr!(
1497 TEST, pattern_complexity_limit, CrateLevel, template!(NameValueStr: "N"),
1498 ErrorFollowing, EncodeCrossCrate::No,
1499 ),
1500];
1501
1502pub fn is_builtin_attr_name(name: Symbol) -> bool {
1503 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
1504}
1505
1506pub fn encode_cross_crate(name: Symbol) -> bool {
1509 if let Some(attr) = BUILTIN_ATTRIBUTE_MAP.get(&name) {
1510 attr.encode_cross_crate == EncodeCrossCrate::Yes
1511 } else {
1512 true
1513 }
1514}
1515
1516pub fn is_valid_for_get_attr(name: Symbol) -> bool {
1517 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| match attr.duplicates {
1518 WarnFollowing | ErrorFollowing | ErrorPreceding | FutureWarnFollowing
1519 | FutureWarnPreceding => true,
1520 DuplicatesOk | WarnFollowingWordOnly => false,
1521 })
1522}
1523
1524pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
1525 LazyLock::new(|| {
1526 let mut map = FxHashMap::default();
1527 for attr in BUILTIN_ATTRIBUTES.iter() {
1528 if map.insert(attr.name, attr).is_some() {
1529 panic!("duplicate builtin attribute `{}`", attr.name);
1530 }
1531 }
1532 map
1533 });
1534
1535pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
1536 match sym {
1537 sym::on_unimplemented | sym::do_not_recommend => true,
1538 _ => false,
1539 }
1540}