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