• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 e29821ff85a2a3000d226f99f62f89464028d5d6.
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 
find_builtin_attr_idx(name: &str) -> Option<usize>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 /// 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 = "...""#),
146         DuplicatesOk, @only_local: true,
147     ),
148     ungated!(
149         allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
150         DuplicatesOk, @only_local: true,
151     ),
152     gated!(
153         expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
154         lint_reasons, experimental!(expect)
155     ),
156     ungated!(
157         forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
158         DuplicatesOk, @only_local: true,
159     ),
160     ungated!(
161         deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
162         DuplicatesOk, @only_local: true,
163     ),
164     ungated!(must_use, Normal, template!(Word, NameValueStr: "reason"), FutureWarnFollowing),
165     gated!(
166         must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
167         experimental!(must_not_suspend)
168     ),
169     ungated!(
170         deprecated, Normal,
171         template!(
172             Word,
173             List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
174             NameValueStr: "reason"
175         ),
176         ErrorFollowing
177     ),
178 
179     // Crate properties:
180     ungated!(crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing),
181     ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk),
182     // crate_id is deprecated
183     ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored"), FutureWarnFollowing),
184 
185     // ABI, linking, symbols, and FFI
186     ungated!(
187         link, Normal,
188         template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#),
189         DuplicatesOk,
190     ),
191     ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
192     ungated!(no_link, Normal, template!(Word), WarnFollowing),
193     ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, @only_local: true),
194     ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
195     ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
196     ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
197     ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
198     ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),
199 
200     // Limits:
201     ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
202     ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
203     gated!(
204         move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
205         large_assignments, experimental!(move_size_limit)
206     ),
207 
208     // Entry point:
209     gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
210     ungated!(start, Normal, template!(Word), WarnFollowing),
211     ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
212     ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
213 
214     // Modules, prelude, and resolution:
215     ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing),
216     ungated!(no_std, CrateLevel, template!(Word), WarnFollowing),
217     ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing),
218     ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing),
219 
220     // Runtime
221     ungated!(
222         windows_subsystem, CrateLevel,
223         template!(NameValueStr: "windows|console"), FutureWarnFollowing
224     ),
225     ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
226 
227     // Code generation:
228     ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, @only_local: true),
229     ungated!(cold, Normal, template!(Word), WarnFollowing, @only_local: true),
230     ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
231     ungated!(
232         target_feature, Normal, template!(List: r#"enable = "name""#),
233         DuplicatesOk, @only_local: true,
234     ),
235     ungated!(track_caller, Normal, template!(Word), WarnFollowing),
236     ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding),
237     gated!(
238         no_sanitize, Normal,
239         template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
240         experimental!(no_sanitize)
241     ),
242     gated!(no_coverage, Normal, template!(Word), WarnFollowing, experimental!(no_coverage)),
243 
244     ungated!(
245         doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
246     ),
247 
248     // Debugging
249     ungated!(
250         debugger_visualizer, Normal,
251         template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), DuplicatesOk
252     ),
253 
254     // ==========================================================================
255     // Unstable attributes:
256     // ==========================================================================
257 
258     // Linking:
259     gated!(
260         naked, Normal, template!(Word), WarnFollowing, @only_local: true,
261         naked_functions, experimental!(naked)
262     ),
263 
264     // Plugins:
265     // BuiltinAttribute {
266     //     name: sym::plugin,
267     //     only_local: false,
268     //     type_: CrateLevel,
269     //     template: template!(List: "name"),
270     //     duplicates: DuplicatesOk,
271     //     gate: Gated(
272     //         Stability::Deprecated(
273     //             "https://github.com/rust-lang/rust/pull/64675",
274     //             Some("may be removed in a future compiler version"),
275     //         ),
276     //         sym::plugin,
277     //         "compiler plugins are deprecated",
278     //         cfg_fn!(plugin)
279     //     ),
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, @only_local: true,
290         marker_trait_attr, experimental!(marker)
291     ),
292     gated!(
293         thread_local, Normal, template!(Word), WarnFollowing,
294         "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
295     ),
296     gated!(no_core, CrateLevel, template!(Word), WarnFollowing, experimental!(no_core)),
297     // RFC 2412
298     gated!(
299         optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
300         experimental!(optimize),
301     ),
302 
303     gated!(
304         ffi_returns_twice, Normal, template!(Word), WarnFollowing, experimental!(ffi_returns_twice)
305     ),
306     gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
307     gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
308     gated!(
309         register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
310         experimental!(register_tool),
311     ),
312 
313     gated!(
314         cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
315         experimental!(cmse_nonsecure_entry)
316     ),
317     // RFC 2632
318     gated!(
319         const_trait, Normal, template!(Word), WarnFollowing, const_trait_impl,
320         "`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
321         `impls` and all default bodies as `const`, which may be removed or renamed in the \
322         future."
323     ),
324     // lang-team MCP 147
325     gated!(
326         deprecated_safe, Normal, template!(List: r#"since = "version", note = "...""#), ErrorFollowing,
327         experimental!(deprecated_safe),
328     ),
329 
330     // `#[collapse_debuginfo]`
331     gated!(
332         collapse_debuginfo, Normal, template!(Word), WarnFollowing,
333         experimental!(collapse_debuginfo)
334     ),
335 
336     // RFC 2397
337     gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
338 
339     // `#[cfi_encoding = ""]`
340     gated!(
341         cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
342         experimental!(cfi_encoding)
343     ),
344 
345     // ==========================================================================
346     // Internal attributes: Stability, deprecation, and unsafe:
347     // ==========================================================================
348 
349     ungated!(
350         feature, CrateLevel,
351         template!(List: "name1, name2, ..."), DuplicatesOk, @only_local: true,
352     ),
353     // DuplicatesOk since it has its own validation
354     ungated!(
355         stable, Normal,
356         template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, @only_local: true,
357     ),
358     ungated!(
359         unstable, Normal,
360         template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
361     ),
362     ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
363     ungated!(
364         rustc_const_stable, Normal,
365         template!(List: r#"feature = "name""#), DuplicatesOk, @only_local: true,
366     ),
367     ungated!(
368         rustc_default_body_unstable, Normal,
369         template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk
370     ),
371     gated!(
372         allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
373         "allow_internal_unstable side-steps feature gating and stability checks",
374     ),
375     gated!(
376         rustc_allow_const_fn_unstable, Normal,
377         template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
378         "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
379     ),
380     gated!(
381         allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
382         "allow_internal_unsafe side-steps the unsafe_code lint",
383     ),
384     ungated!(rustc_safe_intrinsic, Normal, template!(Word), DuplicatesOk),
385     rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
386     "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
387     through unstable paths"),
388 
389     // ==========================================================================
390     // Internal attributes: Type system related:
391     // ==========================================================================
392 
393     gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)),
394     gated!(
395         may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch,
396         "`may_dangle` has unstable semantics and may be removed in the future",
397     ),
398 
399     // ==========================================================================
400     // Internal attributes: Runtime related:
401     // ==========================================================================
402 
403     rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
404     rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
405     rustc_attr!(rustc_reallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
406     rustc_attr!(rustc_deallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
407     rustc_attr!(rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
408     gated!(
409         default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
410         experimental!(default_lib_allocator),
411     ),
412     gated!(
413         needs_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
414         experimental!(needs_allocator),
415     ),
416     gated!(panic_runtime, Normal, template!(Word), WarnFollowing, experimental!(panic_runtime)),
417     gated!(
418         needs_panic_runtime, Normal, template!(Word), WarnFollowing,
419         experimental!(needs_panic_runtime)
420     ),
421     gated!(
422         compiler_builtins, Normal, template!(Word), WarnFollowing,
423         "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
424         which contains compiler-rt intrinsics and will never be stable",
425     ),
426     gated!(
427         profiler_runtime, Normal, template!(Word), WarnFollowing,
428         "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
429         which contains the profiler runtime and will never be stable",
430     ),
431 
432     // ==========================================================================
433     // Internal attributes, Linkage:
434     // ==========================================================================
435 
436     gated!(
437         linkage, Normal, template!(NameValueStr: "external|internal|..."), ErrorPreceding, @only_local: true,
438         "the `linkage` attribute is experimental and not portable across platforms",
439     ),
440     rustc_attr!(
441         rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing, @only_local: true, INTERNAL_UNSTABLE
442     ),
443 
444     // ==========================================================================
445     // Internal attributes, Macro related:
446     // ==========================================================================
447 
448     rustc_attr!(
449         rustc_builtin_macro, Normal,
450         template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing,
451         IMPL_DETAIL,
452     ),
453     rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
454     rustc_attr!(
455         rustc_macro_transparency, Normal,
456         template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing,
457         "used internally for testing macro hygiene",
458     ),
459 
460     // ==========================================================================
461     // Internal attributes, Diagnostics related:
462     // ==========================================================================
463 
464     rustc_attr!(
465         rustc_on_unimplemented, Normal,
466         template!(
467             List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
468             NameValueStr: "message"
469         ),
470         ErrorFollowing,
471         INTERNAL_UNSTABLE
472     ),
473     // Enumerates "identity-like" conversion methods to suggest on type mismatch.
474     rustc_attr!(
475         rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
476     ),
477     // Prevents field reads in the marked trait or method to be considered
478     // during dead code analysis.
479     rustc_attr!(
480         rustc_trivial_field_reads, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
481     ),
482     // Used by the `rustc::potential_query_instability` lint to warn methods which
483     // might not be stable during incremental compilation.
484     rustc_attr!(rustc_lint_query_instability, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
485     // Used by the `rustc::untranslatable_diagnostic` and `rustc::diagnostic_outside_of_impl` lints
486     // to assist in changes to diagnostic APIs.
487     rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
488     // Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions`
489     // types (as well as any others in future).
490     rustc_attr!(rustc_lint_opt_ty, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
491     // Used by the `rustc::bad_opt_access` lint on fields
492     // types (as well as any others in future).
493     rustc_attr!(rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), WarnFollowing, INTERNAL_UNSTABLE),
494 
495     // ==========================================================================
496     // Internal attributes, Const related:
497     // ==========================================================================
498 
499     rustc_attr!(rustc_promotable, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
500     rustc_attr!(
501         rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
502         INTERNAL_UNSTABLE
503     ),
504     // Do not const-check this function's body. It will always get replaced during CTFE.
505     rustc_attr!(
506         rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
507     ),
508 
509     // ==========================================================================
510     // Internal attributes, Layout related:
511     // ==========================================================================
512 
513     rustc_attr!(
514         rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"), ErrorFollowing,
515         "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
516         niche optimizations in libcore and libstd and will never be stable",
517     ),
518     rustc_attr!(
519         rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"), ErrorFollowing,
520         "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
521         niche optimizations in libcore and libstd and will never be stable",
522     ),
523     rustc_attr!(
524         rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
525         "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
526         niche optimizations in libcore and libstd and will never be stable",
527     ),
528 
529     // ==========================================================================
530     // Internal attributes, Misc:
531     // ==========================================================================
532     gated!(
533         lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, @only_local: true, lang_items,
534         "language items are subject to change",
535     ),
536     rustc_attr!(
537         rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
538         "#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference."
539     ),
540     rustc_attr!(
541         rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, @only_local: true,
542         "#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."
543     ),
544     rustc_attr!(
545         rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, @only_local: true,
546         "#![rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver."
547     ),
548     rustc_attr!(
549         rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true,
550         "#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
551     ),
552     rustc_attr!(
553         rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: false,
554         "#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls"
555     ),
556     rustc_attr!(
557         rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word), ErrorFollowing,
558         "#[rustc_has_incoherent_inherent_impls] allows the addition of incoherent inherent impls for \
559          the given type by annotating all impl items with #[rustc_allow_incoherent_impl]."
560     ),
561     rustc_attr!(
562         rustc_box, AttributeType::Normal, template!(Word), ErrorFollowing,
563         "#[rustc_box] allows creating boxes \
564         and it is only intended to be used in `alloc`."
565     ),
566 
567     BuiltinAttribute {
568         // name: sym::rustc_diagnostic_item,
569         name: "rustc_diagnostic_item",
570         // FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
571         // only_local: false,
572         // type_: Normal,
573         template: template!(NameValueStr: "name"),
574         // duplicates: ErrorFollowing,
575         // gate: Gated(
576             // Stability::Unstable,
577             // sym::rustc_attrs,
578             // "diagnostic items compiler internal support for linting",
579             // cfg_fn!(rustc_attrs),
580         // ),
581     },
582     gated!(
583         // Used in resolve:
584         prelude_import, Normal, template!(Word), WarnFollowing,
585         "`#[prelude_import]` is for use by rustc only",
586     ),
587     gated!(
588         rustc_paren_sugar, Normal, template!(Word), WarnFollowing, unboxed_closures,
589         "unboxed_closures are still evolving",
590     ),
591     rustc_attr!(
592         rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, @only_local: true,
593         "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
594         overflow checking behavior of several libcore functions that are inlined \
595         across crates and will never be stable",
596     ),
597     rustc_attr!(
598         rustc_reservation_impl, Normal,
599         template!(NameValueStr: "reservation message"), ErrorFollowing,
600         "the `#[rustc_reservation_impl]` attribute is internally used \
601          for reserving for `for<T> From<!> for T` impl"
602     ),
603     rustc_attr!(
604         rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
605         "the `#[rustc_test_marker]` attribute is used internally to track tests",
606     ),
607     rustc_attr!(
608         rustc_unsafe_specialization_marker, Normal, template!(Word), WarnFollowing,
609         "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
610     ),
611     rustc_attr!(
612         rustc_specialization_trait, Normal, template!(Word), WarnFollowing,
613         "the `#[rustc_specialization_trait]` attribute is used to check specializations"
614     ),
615     rustc_attr!(
616         rustc_main, Normal, template!(Word), WarnFollowing,
617         "the `#[rustc_main]` attribute is used internally to specify test entry point function",
618     ),
619     rustc_attr!(
620         rustc_skip_array_during_method_dispatch, Normal, template!(Word), WarnFollowing,
621         "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
622         from method dispatch when the receiver is an array, for compatibility in editions < 2021."
623     ),
624     rustc_attr!(
625         rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), ErrorFollowing,
626         "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
627         definition of a trait, it's currently in experimental form and should be changed before \
628         being exposed outside of the std"
629     ),
630     rustc_attr!(
631         rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
632         r#"`rustc_doc_primitive` is a rustc internal attribute"#,
633     ),
634 
635     // ==========================================================================
636     // Internal attributes, Testing:
637     // ==========================================================================
638 
639     rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing),
640     rustc_attr!(TEST, rustc_outlives, Normal, template!(Word), WarnFollowing),
641     rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word), WarnFollowing),
642     rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
643     rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing),
644     rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing),
645     rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
646     rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
647     rustc_attr!(
648         TEST, rustc_error, Normal,
649         template!(Word, List: "delay_span_bug_from_inside_query"), WarnFollowingWordOnly
650     ),
651     rustc_attr!(TEST, rustc_dump_user_substs, Normal, template!(Word), WarnFollowing),
652     rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
653     rustc_attr!(
654         TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk
655     ),
656     rustc_attr!(
657         TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), DuplicatesOk
658     ),
659     rustc_attr!(
660         TEST, rustc_clean, Normal,
661         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
662         DuplicatesOk,
663     ),
664     rustc_attr!(
665         TEST, rustc_partition_reused, Normal,
666         template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
667     ),
668     rustc_attr!(
669         TEST, rustc_partition_codegened, Normal,
670         template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk,
671     ),
672     rustc_attr!(
673         TEST, rustc_expected_cgu_reuse, Normal,
674         template!(List: r#"cfg = "...", module = "...", kind = "...""#), DuplicatesOk,
675     ),
676     rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word), WarnFollowing),
677     rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word), WarnFollowing),
678     rustc_attr!(TEST, rustc_def_path, Normal, template!(Word), WarnFollowing),
679     rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), DuplicatesOk),
680     gated!(
681         custom_mir, Normal, template!(List: r#"dialect = "...", phase = "...""#),
682         ErrorFollowing, "the `#[custom_mir]` attribute is just used for the Rust test suite",
683     ),
684     rustc_attr!(TEST, rustc_dump_program_clauses, Normal, template!(Word), WarnFollowing),
685     rustc_attr!(TEST, rustc_dump_env_program_clauses, Normal, template!(Word), WarnFollowing),
686     rustc_attr!(TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing),
687     rustc_attr!(TEST, rustc_dump_vtable, Normal, template!(Word), WarnFollowing),
688     rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/), DuplicatesOk),
689     gated!(
690         omit_gdb_pretty_printer_section, Normal, template!(Word), WarnFollowing,
691         "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
692     ),
693 ];
694