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