Skip to main content

hir_expand/
inert_attr_macro.rs

1//! Builtin attributes resolved by nameres.
2//!
3//! The actual definitions were copied from rustc's `compiler/rustc_feature/src/builtin_attrs.rs`.
4//!
5//! It was last synchronized with upstream commit c3def263a44e07e09ae6d57abfc8650227fb4972.
6//!
7//! The macros were adjusted to only expand to the attribute name, since that is all we need to do
8//! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to
9//! ease updating.
10
11use std::sync::OnceLock;
12
13use intern::Symbol;
14use rustc_hash::FxHashMap;
15
16pub struct BuiltinAttribute {
17    pub name: &'static str,
18    pub template: AttributeTemplate,
19}
20
21/// A template that the attribute input must match.
22/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
23#[derive(Clone, Copy)]
24pub struct AttributeTemplate {
25    pub word: bool,
26    pub list: Option<&'static str>,
27    pub name_value_str: Option<&'static str>,
28}
29
30pub fn find_builtin_attr_idx(name: &Symbol) -> Option<usize> {
31    static BUILTIN_LOOKUP_TABLE: OnceLock<FxHashMap<Symbol, usize>> = OnceLock::new();
32    BUILTIN_LOOKUP_TABLE
33        .get_or_init(|| {
34            INERT_ATTRIBUTES
35                .iter()
36                .map(|attr| attr.name)
37                .enumerate()
38                .map(|(a, b)| (Symbol::intern(b), a))
39                .collect()
40        })
41        .get(name)
42        .copied()
43}
44
45/// A convenience macro for constructing attribute templates.
46/// E.g., `template!(Word, List: "description")` means that the attribute
47/// supports forms `#[attr]` and `#[attr(description)]`.
48macro_rules! template {
49    (Word) => { template!(@ true, None, None) };
50    (List: $descr: expr) => { template!(@ false, Some($descr), None) };
51    (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
52    (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
53    (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
54    (List: $descr1: expr, NameValueStr: $descr2: expr) => {
55        template!(@ false, Some($descr1), Some($descr2))
56    };
57    (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
58        template!(@ true, Some($descr1), Some($descr2))
59    };
60    (@ $word: expr, $list: expr, $name_value_str: expr) => {
61        AttributeTemplate {
62            word: $word, list: $list, name_value_str: $name_value_str
63        }
64    };
65}
66
67macro_rules! ungated {
68    ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)? $(,)?) => {
69        BuiltinAttribute { name: stringify!($attr), template: $tpl }
70    };
71}
72
73macro_rules! gated {
74    ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $gate:ident, $msg:expr $(,)?) => {
75        BuiltinAttribute { name: stringify!($attr), template: $tpl }
76    };
77    ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $msg:expr $(,)?) => {
78        BuiltinAttribute { name: stringify!($attr), template: $tpl }
79    };
80}
81
82macro_rules! rustc_attr {
83    (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr $(, @only_local: $only_local:expr)? $(,)?) => {
84        rustc_attr!(
85            $attr,
86            $typ,
87            $tpl,
88            $duplicate,
89            $(@only_local: $only_local,)?
90            concat!(
91                "the `#[",
92                stringify!($attr),
93                "]` attribute is just used for rustc unit tests \
94                and will never be stable",
95            ),
96        )
97    };
98    ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr $(, @only_local: $only_local:expr)?, $msg:expr $(,)?) => {
99        BuiltinAttribute { name: stringify!($attr), template: $tpl }
100    };
101}
102
103#[allow(unused_macros)]
104macro_rules! experimental {
105    ($attr:ident) => {
106        concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
107    };
108}
109
110/// Attributes that have a special meaning to rustc or rustdoc.
111#[rustfmt::skip]
112pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
113    // ==========================================================================
114    // Stable attributes:
115    // ==========================================================================
116
117    // Conditional compilation:
118    ungated!(cfg, Normal, template!(List: "predicate"), DuplicatesOk),
119    ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk),
120
121    // Testing:
122    ungated!(ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing),
123    ungated!(
124        should_panic, Normal,
125        template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing,
126    ),
127
128    // Macros:
129    ungated!(automatically_derived, Normal, template!(Word), WarnFollowing),
130    ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly),
131    ungated!(macro_escape, Normal, template!(Word), WarnFollowing), // Deprecated synonym for `macro_use`.
132    ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros"), WarnFollowing),
133    ungated!(proc_macro, Normal, template!(Word), ErrorFollowing),
134    ungated!(
135        proc_macro_derive, Normal,
136        template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
137    ),
138    ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing),
139
140    // Lints:
141    ungated!(
142        warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
143        DuplicatesOk, @only_local: true,
144    ),
145    ungated!(
146        allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
147        DuplicatesOk, @only_local: true,
148    ),
149    ungated!(
150        expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
151        DuplicatesOk, @only_local: true,
152    ),
153    ungated!(
154        forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
155        DuplicatesOk, @only_local: true,
156    ),
157    ungated!(
158        deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
159        DuplicatesOk, @only_local: true,
160    ),
161    ungated!(must_use, Normal, template!(Word, NameValueStr: "reason"), FutureWarnFollowing),
162    gated!(
163        must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
164        experimental!(must_not_suspend)
165    ),
166    ungated!(
167        deprecated, Normal,
168        template!(
169            Word,
170            List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
171            NameValueStr: "reason"
172        ),
173        ErrorFollowing
174    ),
175
176    // Crate properties:
177    ungated!(crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing),
178    ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk),
179    // crate_id is deprecated
180    ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing),
181
182    // ABI, linking, symbols, and FFI
183    ungated!(
184        link, Normal,
185        template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#),
186        DuplicatesOk,
187    ),
188    ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
189    ungated!(no_link, Normal, template!(Word), WarnFollowing),
190    ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, @only_local: true),
191    ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
192    ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
193    ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
194    ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
195    ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),
196
197    // Limits:
198    ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
199    ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
200    gated!(
201        move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
202        large_assignments, experimental!(move_size_limit)
203    ),
204
205    // Entry point:
206    ungated!(start, Normal, template!(Word), WarnFollowing),
207    ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
208    ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
209
210    // Modules, prelude, and resolution:
211    ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing),
212    ungated!(no_std, CrateLevel, template!(Word), WarnFollowing),
213    ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing),
214    ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing),
215
216    // Runtime
217    ungated!(
218        windows_subsystem, CrateLevel,
219        template!(NameValueStr: "windows|console"), FutureWarnFollowing
220    ),
221    ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
222
223    // Code generation:
224    ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, @only_local: true),
225    ungated!(cold, Normal, template!(Word), WarnFollowing, @only_local: true),
226    ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
227    ungated!(
228        target_feature, Normal, template!(List: r#"enable = "name""#),
229        DuplicatesOk, @only_local: true,
230    ),
231    ungated!(track_caller, Normal, template!(Word), WarnFollowing),
232    ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding),
233    gated!(
234        no_sanitize, Normal,
235        template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
236        experimental!(no_sanitize)
237    ),
238    gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, coverage_attribute, experimental!(coverage)),
239
240    ungated!(
241        doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
242    ),
243
244    // Debugging
245    ungated!(
246        debugger_visualizer, Normal,
247        template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), DuplicatesOk
248    ),
249
250    // ==========================================================================
251    // Unstable attributes:
252    // ==========================================================================
253
254    // Linking:
255    gated!(
256        naked, Normal, template!(Word), WarnFollowing, @only_local: true,
257        naked_functions, experimental!(naked)
258    ),
259
260    // Testing:
261    gated!(
262        test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, custom_test_frameworks,
263        "custom test frameworks are an unstable feature",
264    ),
265
266    gated!(
267        reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"),
268        ErrorFollowing, custom_test_frameworks,
269        "custom test frameworks are an unstable feature",
270    ),
271
272    // RFC #1268
273    gated!(
274        marker, Normal, template!(Word), WarnFollowing, @only_local: true,
275        marker_trait_attr, experimental!(marker)
276    ),
277    gated!(
278        thread_local, Normal, template!(Word), WarnFollowing,
279        "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
280    ),
281    gated!(no_core, CrateLevel, template!(Word), WarnFollowing, experimental!(no_core)),
282    // RFC 2412
283    gated!(
284        optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
285        experimental!(optimize),
286    ),
287
288    gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
289    gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
290    gated!(
291        register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
292        experimental!(register_tool),
293    ),
294
295    gated!(
296        cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
297        experimental!(cmse_nonsecure_entry)
298    ),
299    // RFC 2632
300    gated!(
301        const_trait, Normal, template!(Word), WarnFollowing, const_trait_impl,
302        "`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
303        `impls` and all default bodies as `const`, which may be removed or renamed in the \
304        future."
305    ),
306    // lang-team MCP 147
307    gated!(
308        deprecated_safe, Normal, template!(List: r#"since = "version", note = "...""#), ErrorFollowing,
309        experimental!(deprecated_safe),
310    ),
311
312    // `#[collapse_debuginfo]`
313    gated!(
314        collapse_debuginfo, Normal, template!(Word), WarnFollowing,
315        experimental!(collapse_debuginfo)
316    ),
317
318    // RFC 2397
319    gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
320
321    // `#[cfi_encoding = ""]`
322    gated!(
323        cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
324        experimental!(cfi_encoding)
325    ),
326
327    // ==========================================================================
328    // Internal attributes: Stability, deprecation, and unsafe:
329    // ==========================================================================
330
331    ungated!(
332        feature, CrateLevel,
333        template!(List: "name1, name2, ..."), DuplicatesOk, @only_local: true,
334    ),
335    // DuplicatesOk since it has its own validation
336    ungated!(
337        stable, Normal,
338        template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, @only_local: true,
339    ),
340    ungated!(
341        unstable, Normal,
342        template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
343    ),
344    ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
345    ungated!(
346        rustc_const_stable, Normal,
347        template!(List: r#"feature = "name""#), DuplicatesOk, @only_local: true,
348    ),
349    ungated!(
350        rustc_default_body_unstable, Normal,
351        template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk
352    ),
353    gated!(
354        allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
355        "allow_internal_unstable side-steps feature gating and stability checks",
356    ),
357    gated!(
358        rustc_allow_const_fn_unstable, Normal,
359        template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
360        "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
361    ),
362    gated!(
363        allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
364        "allow_internal_unsafe side-steps the unsafe_code lint",
365    ),
366    rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
367    "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
368    through unstable paths"),
369
370    // ==========================================================================
371    // Internal attributes: Type system related:
372    // ==========================================================================
373
374    gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)),
375    gated!(
376        may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch,
377        "`may_dangle` has unstable semantics and may be removed in the future",
378    ),
379
380    // ==========================================================================
381    // Internal attributes: Runtime related:
382    // ==========================================================================
383
384    rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
385    rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
386    rustc_attr!(rustc_reallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
387    rustc_attr!(rustc_deallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
388    rustc_attr!(rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
389    gated!(
390        default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
391        experimental!(default_lib_allocator),
392    ),
393    gated!(
394        needs_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
395        experimental!(needs_allocator),
396    ),
397    gated!(panic_runtime, Normal, template!(Word), WarnFollowing, experimental!(panic_runtime)),
398    gated!(
399        needs_panic_runtime, Normal, template!(Word), WarnFollowing,
400        experimental!(needs_panic_runtime)
401    ),
402    gated!(
403        compiler_builtins, Normal, template!(Word), WarnFollowing,
404        "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
405        which contains compiler-rt intrinsics and will never be stable",
406    ),
407    gated!(
408        profiler_runtime, Normal, template!(Word), WarnFollowing,
409        "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
410        which contains the profiler runtime and will never be stable",
411    ),
412
413    // ==========================================================================
414    // Internal attributes, Linkage:
415    // ==========================================================================
416
417    gated!(
418        linkage, Normal, template!(NameValueStr: "external|internal|..."), ErrorPreceding, @only_local: true,
419        "the `linkage` attribute is experimental and not portable across platforms",
420    ),
421    rustc_attr!(
422        rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing, @only_local: true, INTERNAL_UNSTABLE
423    ),
424
425    // ==========================================================================
426    // Internal attributes, Macro related:
427    // ==========================================================================
428
429    rustc_attr!(
430        rustc_builtin_macro, Normal,
431        template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
432        IMPL_DETAIL,
433    ),
434    rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
435    rustc_attr!(
436        rustc_macro_transparency, Normal,
437        template!(NameValueStr: "transparent|semiopaque|opaque"), ErrorFollowing,
438        "used internally for testing macro hygiene",
439    ),
440
441    // ==========================================================================
442    // Internal attributes, Diagnostics related:
443    // ==========================================================================
444
445    rustc_attr!(
446        rustc_on_unimplemented, Normal,
447        template!(
448            List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
449            NameValueStr: "message"
450        ),
451        ErrorFollowing,
452        INTERNAL_UNSTABLE
453    ),
454    rustc_attr!(
455        rustc_confusables, Normal,
456        template!(List: r#""name1", "name2", ..."#),
457        ErrorFollowing,
458        INTERNAL_UNSTABLE,
459    ),
460    // Enumerates "identity-like" conversion methods to suggest on type mismatch.
461    rustc_attr!(
462        rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
463    ),
464    // Prevents field reads in the marked trait or method to be considered
465    // during dead code analysis.
466    rustc_attr!(
467        rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
468    ),
469    // Used by the `rustc::potential_query_instability` lint to warn methods which
470    // might not be stable during incremental compilation.
471    rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
472    // Used by the `rustc::untracked_query_information` lint to warn methods which
473    // might break incremental compilation.
474    rustc_attr!(rustc_lint_untracked_query_information, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
475    // Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions`
476    // types (as well as any others in future).
477    rustc_attr!(rustc_lint_opt_ty, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
478    // Used by the `rustc::bad_opt_access` lint on fields
479    // types (as well as any others in future).
480    rustc_attr!(rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), WarnFollowing, INTERNAL_UNSTABLE),
481
482    // ==========================================================================
483    // Internal attributes, Const related:
484    // ==========================================================================
485
486    rustc_attr!(rustc_promotable, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
487    rustc_attr!(
488        rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
489        INTERNAL_UNSTABLE
490    ),
491    // Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
492    rustc_attr!(
493        rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
494    ),
495    // Ensure the argument to this function is &&str during const-check.
496    rustc_attr!(
497        rustc_const_panic_str, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
498    ),
499
500    // ==========================================================================
501    // Internal attributes, Layout related:
502    // ==========================================================================
503
504    rustc_attr!(
505        rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"), ErrorFollowing,
506        "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
507        niche optimizations in libcore and libstd and will never be stable",
508    ),
509    rustc_attr!(
510        rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"), ErrorFollowing,
511        "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
512        niche optimizations in libcore and libstd and will never be stable",
513    ),
514    rustc_attr!(
515        rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
516        "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
517        niche optimizations in libcore and libstd and will never be stable",
518    ),
519
520    // ==========================================================================
521    // Internal attributes, Misc:
522    // ==========================================================================
523    gated!(
524        lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, @only_local: true, lang_items,
525        "language items are subject to change",
526    ),
527    rustc_attr!(
528        rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
529        "#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference."
530    ),
531    rustc_attr!(
532        rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing,
533        "#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
534    ),
535    rustc_attr!(
536        rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, @only_local: true,
537        "#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."
538    ),
539    rustc_attr!(
540        rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, @only_local: true,
541        "#![rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver."
542    ),
543    rustc_attr!(
544        rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true,
545        "#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
546    ),
547    rustc_attr!(
548        rustc_deny_explicit_impl,
549        AttributeType::Normal,
550        template!(List: "implement_via_object = (true|false)"),
551        ErrorFollowing,
552        @only_local: true,
553        "#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls"
554    ),
555    rustc_attr!(
556        rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word), ErrorFollowing,
557        "#[rustc_has_incoherent_inherent_impls] allows the addition of incoherent inherent impls for \
558         the given type by annotating all impl items with #[rustc_allow_incoherent_impl]."
559    ),
560    rustc_attr!(
561        rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing,
562        "#[rustc_box] allows creating boxes \
563        and it is only intended to be used in `alloc`."
564    ),
565
566    BuiltinAttribute {
567        // name: sym::rustc_diagnostic_item,
568        name: "rustc_diagnostic_item",
569        // FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
570        // only_local: false,
571        // type_: Normal,
572        template: template!(NameValueStr: "name"),
573        // duplicates: ErrorFollowing,
574        // gate: Gated(
575            // Stability::Unstable,
576            // sym::rustc_attrs,
577            // "diagnostic items compiler internal support for linting",
578            // cfg_fn!(rustc_attrs),
579        // ),
580    },
581    gated!(
582        // Used in resolve:
583        prelude_import, Normal, template!(Word), WarnFollowing,
584        "`#[prelude_import]` is for use by rustc only",
585    ),
586    gated!(
587        rustc_paren_sugar, Normal, template!(Word), WarnFollowing, unboxed_closures,
588        "unboxed_closures are still evolving",
589    ),
590    rustc_attr!(
591        rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, @only_local: true,
592        "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
593        overflow checking behavior of several libcore functions that are inlined \
594        across crates and will never be stable",
595    ),
596    rustc_attr!(
597        rustc_reservation_impl, Normal,
598        template!(NameValueStr: "reservation message"), ErrorFollowing,
599        "the `#[rustc_reservation_impl]` attribute is internally used \
600         for reserving for `for<T> From<!> for T` impl"
601    ),
602    rustc_attr!(
603        rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
604        "the `#[rustc_test_marker]` attribute is used internally to track tests",
605    ),
606    rustc_attr!(
607        rustc_unsafe_specialization_marker, Normal, template!(Word), WarnFollowing,
608        "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
609    ),
610    rustc_attr!(
611        rustc_specialization_trait, Normal, template!(Word), WarnFollowing,
612        "the `#[rustc_specialization_trait]` attribute is used to check specializations"
613    ),
614    rustc_attr!(
615        rustc_main, Normal, template!(Word), WarnFollowing,
616        "the `#[rustc_main]` attribute is used internally to specify test entry point function",
617    ),
618    rustc_attr!(
619        rustc_skip_array_during_method_dispatch, Normal, template!(Word), WarnFollowing,
620        "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
621        from method dispatch when the receiver is an array, for compatibility in editions < 2021."
622    ),
623    rustc_attr!(
624        rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), ErrorFollowing,
625        "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
626        definition of a trait, it's currently in experimental form and should be changed before \
627        being exposed outside of the std"
628    ),
629    rustc_attr!(
630        rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
631        r#"`rustc_doc_primitive` is a rustc internal attribute"#,
632    ),
633    rustc_attr!(
634        rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
635        "the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
636    ),
637    rustc_attr!(
638        rustc_intrinsic, Normal, template!(Word), ErrorFollowing,
639        "the `#[rustc_intrinsic]` attribute is used to declare intrinsics with function bodies",
640    ),
641    rustc_attr!(
642        rustc_no_mir_inline, Normal, template!(Word), WarnFollowing,
643        "#[rustc_no_mir_inline] prevents the MIR inliner from inlining a function while not affecting codegen"
644    ),
645    rustc_attr!(
646        rustc_intrinsic_must_be_overridden, Normal, template!(Word), ErrorFollowing,
647        "the `#[rustc_intrinsic_must_be_overridden]` attribute is used to declare intrinsics without real bodies",
648    ),
649
650    rustc_attr!(
651        rustc_deprecated_safe_2024, Normal, template!(Word), WarnFollowing,
652        "the `#[rustc_safe_intrinsic]` marks functions as unsafe in Rust 2024",
653    ),
654
655    // ==========================================================================
656    // Internal attributes, Testing:
657    // ==========================================================================
658
659    rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing),
660    rustc_attr!(TEST, rustc_outlives, Normal, template!(Word), WarnFollowing),
661    rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word), WarnFollowing),
662    rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
663    rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing),
664    rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing),
665    rustc_attr!(TEST, rustc_variance_of_opaques, Normal, template!(Word), WarnFollowing),
666    rustc_attr!(TEST, rustc_hidden_type_of_opaques, Normal, template!(Word), WarnFollowing),
667    rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
668    rustc_attr!(TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
669    rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
670    rustc_attr!(TEST, rustc_dump_user_args, Normal, template!(Word), WarnFollowing),
671    rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
672    rustc_attr!(
673        TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk
674    ),
675    rustc_attr!(
676        TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), DuplicatesOk
677    ),
678    rustc_attr!(
679        TEST, rustc_clean, Normal,
680        template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
681        DuplicatesOk,
682    ),
683    rustc_attr!(
684        TEST, rustc_partition_reused, Normal,
685        template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
686    ),
687    rustc_attr!(
688        TEST, rustc_partition_codegened, Normal,
689        template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
690    ),
691    rustc_attr!(
692        TEST, rustc_expected_cgu_reuse, Normal,
693        template!(List: r#"cfg = "...", module = "...", kind = "...""#), DuplicatesOk,
694    ),
695    rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word), WarnFollowing),
696    rustc_attr!(TEST, rustc_def_path, Normal, template!(Word), WarnFollowing),
697    rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), DuplicatesOk),
698    gated!(
699        custom_mir, Normal, template!(List: r#"dialect = "...", phase = "...""#),
700        ErrorFollowing, "the `#[custom_mir]` attribute is just used for the Rust test suite",
701    ),
702    rustc_attr!(TEST, rustc_dump_program_clauses, Normal, template!(Word), WarnFollowing),
703    rustc_attr!(TEST, rustc_dump_env_program_clauses, Normal, template!(Word), WarnFollowing),
704    rustc_attr!(TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing),
705    rustc_attr!(TEST, rustc_dyn_incompatible_trait, Normal, template!(Word), WarnFollowing),
706    rustc_attr!(TEST, rustc_dump_vtable, Normal, template!(Word), WarnFollowing),
707    rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/), DuplicatesOk),
708    gated!(
709        omit_gdb_pretty_printer_section, Normal, template!(Word), WarnFollowing,
710        "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
711    ),
712];