]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_feature/src/builtin_attrs.rs
Stabilize File::options()
[rust.git] / compiler / rustc_feature / src / builtin_attrs.rs
1 //! Built-in attributes and `cfg` flag gating.
2
3 use AttributeGate::*;
4 use AttributeType::*;
5
6 use crate::{Features, Stability};
7
8 use rustc_data_structures::fx::FxHashMap;
9 use rustc_span::symbol::{sym, Symbol};
10
11 use std::lazy::SyncLazy;
12
13 type GateFn = fn(&Features) -> bool;
14
15 macro_rules! cfg_fn {
16     ($field: ident) => {
17         (|features| features.$field) as GateFn
18     };
19 }
20
21 pub type GatedCfg = (Symbol, Symbol, GateFn);
22
23 /// `cfg(...)`'s that are feature gated.
24 const GATED_CFGS: &[GatedCfg] = &[
25     // (name in cfg, feature, function to check if the feature is enabled)
26     (sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
27     (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
28     (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
29     (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
30     (
31         sym::target_has_atomic_equal_alignment,
32         sym::cfg_target_has_atomic,
33         cfg_fn!(cfg_target_has_atomic),
34     ),
35     (sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
36     (sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
37     (sym::panic, sym::cfg_panic, cfg_fn!(cfg_panic)),
38 ];
39
40 /// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
41 pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg> {
42     GATED_CFGS.iter().find(|(cfg_sym, ..)| pred(*cfg_sym))
43 }
44
45 // If you change this, please modify `src/doc/unstable-book` as well. You must
46 // move that documentation into the relevant place in the other docs, and
47 // remove the chapter on the flag.
48
49 #[derive(Copy, Clone, PartialEq, Debug)]
50 pub enum AttributeType {
51     /// Normal, builtin attribute that is consumed
52     /// by the compiler before the unused_attribute check
53     Normal,
54
55     /// Builtin attribute that is only allowed at the crate level
56     CrateLevel,
57 }
58
59 #[derive(Clone, Copy)]
60 pub enum AttributeGate {
61     /// Is gated by a given feature gate, reason
62     /// and function to check if enabled
63     Gated(Stability, Symbol, &'static str, fn(&Features) -> bool),
64
65     /// Ungated attribute, can be used on all release channels
66     Ungated,
67 }
68
69 // fn() is not Debug
70 impl std::fmt::Debug for AttributeGate {
71     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72         match *self {
73             Self::Gated(ref stab, name, expl, _) => {
74                 write!(fmt, "Gated({:?}, {}, {})", stab, name, expl)
75             }
76             Self::Ungated => write!(fmt, "Ungated"),
77         }
78     }
79 }
80
81 impl AttributeGate {
82     fn is_deprecated(&self) -> bool {
83         matches!(*self, Self::Gated(Stability::Deprecated(_, _), ..))
84     }
85 }
86
87 /// A template that the attribute input must match.
88 /// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
89 #[derive(Clone, Copy, Default)]
90 pub struct AttributeTemplate {
91     pub word: bool,
92     pub list: Option<&'static str>,
93     pub name_value_str: Option<&'static str>,
94 }
95
96 /// A convenience macro for constructing attribute templates.
97 /// E.g., `template!(Word, List: "description")` means that the attribute
98 /// supports forms `#[attr]` and `#[attr(description)]`.
99 macro_rules! template {
100     (Word) => { template!(@ true, None, None) };
101     (List: $descr: expr) => { template!(@ false, Some($descr), None) };
102     (NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
103     (Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
104     (Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
105     (List: $descr1: expr, NameValueStr: $descr2: expr) => {
106         template!(@ false, Some($descr1), Some($descr2))
107     };
108     (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
109         template!(@ true, Some($descr1), Some($descr2))
110     };
111     (@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
112         word: $word, list: $list, name_value_str: $name_value_str
113     } };
114 }
115
116 macro_rules! ungated {
117     ($attr:ident, $typ:expr, $tpl:expr $(,)?) => {
118         (sym::$attr, $typ, $tpl, Ungated)
119     };
120 }
121
122 macro_rules! gated {
123     ($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => {
124         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)))
125     };
126     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
127         (sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)))
128     };
129 }
130
131 macro_rules! rustc_attr {
132     (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => {
133         rustc_attr!(
134             $attr,
135             $typ,
136             $tpl,
137             concat!(
138                 "the `#[",
139                 stringify!($attr),
140                 "]` attribute is just used for rustc unit tests \
141                 and will never be stable",
142             ),
143         )
144     };
145     ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
146         (
147             sym::$attr,
148             $typ,
149             $tpl,
150             Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
151         )
152     };
153 }
154
155 macro_rules! experimental {
156     ($attr:ident) => {
157         concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature")
158     };
159 }
160
161 const IMPL_DETAIL: &str = "internal implementation detail";
162 const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable";
163
164 pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);
165
166 /// Attributes that have a special meaning to rustc or rustdoc.
167 #[rustfmt::skip]
168 pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
169     // ==========================================================================
170     // Stable attributes:
171     // ==========================================================================
172
173     // Conditional compilation:
174     ungated!(cfg, Normal, template!(List: "predicate")),
175     ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ...")),
176
177     // Testing:
178     ungated!(ignore, Normal, template!(Word, NameValueStr: "reason")),
179     ungated!(
180         should_panic, Normal,
181         template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"),
182     ),
183     // FIXME(Centril): This can be used on stable but shouldn't.
184     ungated!(reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name")),
185
186     // Macros:
187     ungated!(automatically_derived, Normal, template!(Word)),
188     // FIXME(#14407)
189     ungated!(macro_use, Normal, template!(Word, List: "name1, name2, ...")),
190     ungated!(macro_escape, Normal, template!(Word)), // Deprecated synonym for `macro_use`.
191     ungated!(macro_export, Normal, template!(Word, List: "local_inner_macros")),
192     ungated!(proc_macro, Normal, template!(Word)),
193     ungated!(
194         proc_macro_derive, Normal,
195         template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"),
196     ),
197     ungated!(proc_macro_attribute, Normal, template!(Word)),
198
199     // Lints:
200     ungated!(warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
201     ungated!(allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
202     ungated!(forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
203     ungated!(deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#)),
204     ungated!(must_use, Normal, template!(Word, NameValueStr: "reason")),
205     gated!(
206         must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), must_not_suspend,
207         experimental!(must_not_suspend)
208     ),
209     // FIXME(#14407)
210     ungated!(
211         deprecated, Normal,
212         template!(
213             Word,
214             List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
215             NameValueStr: "reason"
216         ),
217     ),
218
219     // Crate properties:
220     ungated!(crate_name, CrateLevel, template!(NameValueStr: "name")),
221     ungated!(crate_type, CrateLevel, template!(NameValueStr: "bin|lib|...")),
222     ungated!(crate_id, CrateLevel, template!(NameValueStr: "ignored")),
223
224     // ABI, linking, symbols, and FFI
225     ungated!(
226         link, Normal,
227         template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
228     ),
229     ungated!(link_name, Normal, template!(NameValueStr: "name")),
230     ungated!(no_link, Normal, template!(Word)),
231     ungated!(repr, Normal, template!(List: "C")),
232     ungated!(export_name, Normal, template!(NameValueStr: "name")),
233     ungated!(link_section, Normal, template!(NameValueStr: "name")),
234     ungated!(no_mangle, Normal, template!(Word)),
235     ungated!(used, Normal, template!(Word)),
236
237     // Limits:
238     ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
239     ungated!(type_length_limit, CrateLevel, template!(NameValueStr: "N")),
240     gated!(
241         const_eval_limit, CrateLevel, template!(NameValueStr: "N"), const_eval_limit,
242         experimental!(const_eval_limit)
243     ),
244     gated!(
245         move_size_limit, CrateLevel, template!(NameValueStr: "N"), large_assignments,
246         experimental!(move_size_limit)
247     ),
248
249     // Entry point:
250     ungated!(main, Normal, template!(Word)),
251     ungated!(start, Normal, template!(Word)),
252     ungated!(no_start, CrateLevel, template!(Word)),
253     ungated!(no_main, CrateLevel, template!(Word)),
254
255     // Modules, prelude, and resolution:
256     ungated!(path, Normal, template!(NameValueStr: "file")),
257     ungated!(no_std, CrateLevel, template!(Word)),
258     ungated!(no_implicit_prelude, Normal, template!(Word)),
259     ungated!(non_exhaustive, Normal, template!(Word)),
260
261     // Runtime
262     ungated!(windows_subsystem, Normal, template!(NameValueStr: "windows|console")),
263     ungated!(panic_handler, Normal, template!(Word)), // RFC 2070
264
265     // Code generation:
266     ungated!(inline, Normal, template!(Word, List: "always|never")),
267     ungated!(cold, Normal, template!(Word)),
268     ungated!(no_builtins, Normal, template!(Word)),
269     ungated!(target_feature, Normal, template!(List: r#"enable = "name""#)),
270     ungated!(track_caller, Normal, template!(Word)),
271     gated!(
272         no_sanitize, Normal,
273         template!(List: "address, memory, thread"),
274         experimental!(no_sanitize)
275     ),
276     gated!(no_coverage, Normal, template!(Word), experimental!(no_coverage)),
277
278     // FIXME: #14408 assume docs are used since rustdoc looks at them.
279     ungated!(doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string")),
280
281     // ==========================================================================
282     // Unstable attributes:
283     // ==========================================================================
284
285     // Linking:
286     gated!(naked, Normal, template!(Word), naked_functions, experimental!(naked)),
287     gated!(
288         link_ordinal, Normal, template!(List: "ordinal"), raw_dylib,
289         experimental!(link_ordinal)
290     ),
291
292     // Plugins:
293     (
294         sym::plugin, CrateLevel, template!(List: "name"),
295         Gated(
296             Stability::Deprecated(
297                 "https://github.com/rust-lang/rust/pull/64675",
298                 Some("may be removed in a future compiler version"),
299             ),
300             sym::plugin,
301             "compiler plugins are deprecated",
302             cfg_fn!(plugin)
303         )
304     ),
305
306     // Testing:
307     gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
308     gated!(
309         test_runner, CrateLevel, template!(List: "path"), custom_test_frameworks,
310         "custom test frameworks are an unstable feature",
311     ),
312     // RFC #1268
313     gated!(marker, Normal, template!(Word), marker_trait_attr, experimental!(marker)),
314     gated!(
315         thread_local, Normal, template!(Word),
316         "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
317     ),
318     gated!(no_core, CrateLevel, template!(Word), experimental!(no_core)),
319     // RFC 2412
320     gated!(
321         optimize, Normal, template!(List: "size|speed"), optimize_attribute,
322         experimental!(optimize),
323     ),
324     // RFC 2867
325     gated!(instruction_set, Normal, template!(List: "set"), isa_attribute, experimental!(instruction_set)),
326
327     gated!(ffi_returns_twice, Normal, template!(Word), experimental!(ffi_returns_twice)),
328     gated!(ffi_pure, Normal, template!(Word), experimental!(ffi_pure)),
329     gated!(ffi_const, Normal, template!(Word), experimental!(ffi_const)),
330     gated!(
331         register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
332         experimental!(register_attr),
333     ),
334     gated!(
335         register_tool, CrateLevel, template!(List: "tool1, tool2, ..."),
336         experimental!(register_tool),
337     ),
338
339     gated!(cmse_nonsecure_entry, Normal, template!(Word), experimental!(cmse_nonsecure_entry)),
340     // RFC 2632
341     gated!(
342         default_method_body_is_const, Normal, template!(Word), const_trait_impl,
343         "`default_method_body_is_const` is a temporary placeholder for declaring default bodies \
344         as `const`, which may be removed or renamed in the future."
345     ),
346
347     // ==========================================================================
348     // Internal attributes: Stability, deprecation, and unsafe:
349     // ==========================================================================
350
351     ungated!(feature, CrateLevel, template!(List: "name1, name1, ...")),
352     // FIXME(#14407) -- only looked at on-demand so we can't
353     // guarantee they'll have already been checked.
354     ungated!(
355         rustc_deprecated, Normal,
356         template!(List: r#"since = "version", reason = "...""#)
357     ),
358     // FIXME(#14407)
359     ungated!(stable, Normal, template!(List: r#"feature = "name", since = "version""#)),
360     // FIXME(#14407)
361     ungated!(
362         unstable, Normal,
363         template!(List: r#"feature = "name", reason = "...", issue = "N""#),
364     ),
365     // FIXME(#14407)
366     ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#)),
367     // FIXME(#14407)
368     ungated!(rustc_const_stable, Normal, template!(List: r#"feature = "name""#)),
369     gated!(
370         allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."),
371         "allow_internal_unstable side-steps feature gating and stability checks",
372     ),
373     gated!(
374         rustc_allow_const_fn_unstable, Normal, template!(Word, List: "feat1, feat2, ..."),
375         "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
376     ),
377     gated!(
378         allow_internal_unsafe, Normal, template!(Word),
379         "allow_internal_unsafe side-steps the unsafe_code lint",
380     ),
381
382     // ==========================================================================
383     // Internal attributes: Type system related:
384     // ==========================================================================
385
386     gated!(fundamental, Normal, template!(Word), experimental!(fundamental)),
387     gated!(
388         may_dangle, Normal, template!(Word), dropck_eyepatch,
389         "`may_dangle` has unstable semantics and may be removed in the future",
390     ),
391
392     // ==========================================================================
393     // Internal attributes: Runtime related:
394     // ==========================================================================
395
396     rustc_attr!(rustc_allocator, Normal, template!(Word), IMPL_DETAIL),
397     rustc_attr!(rustc_allocator_nounwind, Normal, template!(Word), IMPL_DETAIL),
398     gated!(alloc_error_handler, Normal, template!(Word), experimental!(alloc_error_handler)),
399     gated!(
400         default_lib_allocator, Normal, template!(Word), allocator_internals,
401         experimental!(default_lib_allocator),
402     ),
403     gated!(
404         needs_allocator, Normal, template!(Word), allocator_internals,
405         experimental!(needs_allocator),
406     ),
407     gated!(panic_runtime, Normal, template!(Word), experimental!(panic_runtime)),
408     gated!(needs_panic_runtime, Normal, template!(Word), experimental!(needs_panic_runtime)),
409     gated!(
410         compiler_builtins, Normal, template!(Word),
411         "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
412         which contains compiler-rt intrinsics and will never be stable",
413     ),
414     gated!(
415         profiler_runtime, Normal, template!(Word),
416         "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
417         which contains the profiler runtime and will never be stable",
418     ),
419
420     // ==========================================================================
421     // Internal attributes, Linkage:
422     // ==========================================================================
423
424     gated!(
425         linkage, Normal, template!(NameValueStr: "external|internal|..."),
426         "the `linkage` attribute is experimental and not portable across platforms",
427     ),
428     rustc_attr!(rustc_std_internal_symbol, Normal, template!(Word), INTERNAL_UNSTABLE),
429
430     // ==========================================================================
431     // Internal attributes, Macro related:
432     // ==========================================================================
433
434     rustc_attr!(
435         rustc_builtin_macro, Normal,
436         template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"),
437         IMPL_DETAIL,
438     ),
439     rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
440     rustc_attr!(
441         rustc_macro_transparency, Normal,
442         template!(NameValueStr: "transparent|semitransparent|opaque"),
443         "used internally for testing macro hygiene",
444     ),
445
446     // ==========================================================================
447     // Internal attributes, Diagnostics related:
448     // ==========================================================================
449
450     rustc_attr!(
451         rustc_on_unimplemented, Normal,
452         template!(
453             List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#,
454             NameValueStr: "message"
455         ),
456         INTERNAL_UNSTABLE
457     ),
458     // Enumerates "identity-like" conversion methods to suggest on type mismatch.
459     rustc_attr!(rustc_conversion_suggestion, Normal, template!(Word), INTERNAL_UNSTABLE),
460     // Prevents field reads in the marked trait or method to be considered
461     // during dead code analysis.
462     rustc_attr!(rustc_trivial_field_reads, Normal, template!(Word), INTERNAL_UNSTABLE),
463
464     // ==========================================================================
465     // Internal attributes, Const related:
466     // ==========================================================================
467
468     rustc_attr!(rustc_promotable, Normal, template!(Word), IMPL_DETAIL),
469     rustc_attr!(rustc_legacy_const_generics, Normal, template!(List: "N"), INTERNAL_UNSTABLE),
470     // Do not const-check this function's body. It will always get replaced during CTFE.
471     rustc_attr!(rustc_do_not_const_check, Normal, template!(Word), INTERNAL_UNSTABLE),
472
473     // ==========================================================================
474     // Internal attributes, Layout related:
475     // ==========================================================================
476
477     rustc_attr!(
478         rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"),
479         "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
480         niche optimizations in libcore and will never be stable",
481     ),
482     rustc_attr!(
483         rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"),
484         "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
485         niche optimizations in libcore and will never be stable",
486     ),
487     rustc_attr!(
488         rustc_nonnull_optimization_guaranteed, Normal, template!(Word),
489         "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to enable \
490         niche optimizations in libcore and will never be stable",
491     ),
492
493     // ==========================================================================
494     // Internal attributes, Misc:
495     // ==========================================================================
496     gated!(
497         lang, Normal, template!(NameValueStr: "name"), lang_items,
498         "language items are subject to change",
499     ),
500     (
501         sym::rustc_diagnostic_item,
502         Normal,
503         template!(NameValueStr: "name"),
504         Gated(
505             Stability::Unstable,
506             sym::rustc_attrs,
507             "diagnostic items compiler internal support for linting",
508             cfg_fn!(rustc_attrs),
509         ),
510     ),
511     gated!(
512         // Used in resolve:
513         prelude_import, Normal, template!(Word),
514         "`#[prelude_import]` is for use by rustc only",
515     ),
516     gated!(
517         rustc_paren_sugar, Normal, template!(Word), unboxed_closures,
518         "unboxed_closures are still evolving",
519     ),
520     rustc_attr!(
521         rustc_inherit_overflow_checks, Normal, template!(Word),
522         "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
523         overflow checking behavior of several libcore functions that are inlined \
524         across crates and will never be stable",
525     ),
526     rustc_attr!(rustc_reservation_impl, Normal, template!(NameValueStr: "reservation message"),
527                 "the `#[rustc_reservation_impl]` attribute is internally used \
528                  for reserving for `for<T> From<!> for T` impl"
529     ),
530     rustc_attr!(
531         rustc_test_marker, Normal, template!(Word),
532         "the `#[rustc_test_marker]` attribute is used internally to track tests",
533     ),
534     rustc_attr!(
535         rustc_unsafe_specialization_marker, Normal, template!(Word),
536         "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
537     ),
538     rustc_attr!(
539         rustc_specialization_trait, Normal, template!(Word),
540         "the `#[rustc_specialization_trait]` attribute is used to check specializations"
541     ),
542     rustc_attr!(
543         rustc_main, Normal, template!(Word),
544         "the `#[rustc_main]` attribute is used internally to specify test entry point function",
545     ),
546     rustc_attr!(
547         rustc_skip_array_during_method_dispatch, Normal, template!(Word),
548         "the `#[rustc_skip_array_during_method_dispatch]` attribute is used to exclude a trait \
549         from method dispatch when the receiver is an array, for compatibility in editions < 2021."
550     ),
551
552     // ==========================================================================
553     // Internal attributes, Testing:
554     // ==========================================================================
555
556     rustc_attr!(TEST, rustc_outlives, Normal, template!(Word)),
557     rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word)),
558     rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word)),
559     rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word)),
560     rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
561     rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
562     rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
563     rustc_attr!(
564         TEST, rustc_error, Normal,
565         template!(Word, List: "delay_span_bug_from_inside_query")
566     ),
567     rustc_attr!(TEST, rustc_dump_user_substs, Normal, template!(Word)),
568     rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word)),
569     rustc_attr!(TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode")),
570     rustc_attr!(TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode")),
571     rustc_attr!(
572         TEST, rustc_clean, Normal,
573         template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#),
574     ),
575     rustc_attr!(
576         TEST, rustc_partition_reused, Normal,
577         template!(List: r#"cfg = "...", module = "...""#),
578     ),
579     rustc_attr!(
580         TEST, rustc_partition_codegened, Normal,
581         template!(List: r#"cfg = "...", module = "...""#),
582     ),
583     rustc_attr!(
584         TEST, rustc_expected_cgu_reuse, Normal,
585         template!(List: r#"cfg = "...", module = "...", kind = "...""#),
586     ),
587     rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)),
588     rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)),
589     rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)),
590     rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)),
591     rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ...")),
592     rustc_attr!(TEST, rustc_dump_program_clauses, Normal, template!(Word)),
593     rustc_attr!(TEST, rustc_dump_env_program_clauses, Normal, template!(Word)),
594     rustc_attr!(TEST, rustc_object_lifetime_default, Normal, template!(Word)),
595     rustc_attr!(TEST, rustc_dump_vtable, Normal, template!(Word)),
596     rustc_attr!(TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/)),
597     gated!(
598         omit_gdb_pretty_printer_section, Normal, template!(Word),
599         "the `#[omit_gdb_pretty_printer_section]` attribute is just used for the Rust test suite",
600     ),
601 ];
602
603 pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
604     BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
605 }
606
607 pub fn is_builtin_attr_name(name: Symbol) -> bool {
608     BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
609 }
610
611 pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
612     SyncLazy::new(|| {
613         let mut map = FxHashMap::default();
614         for attr in BUILTIN_ATTRIBUTES.iter() {
615             if map.insert(attr.0, attr).is_some() {
616                 panic!("duplicate builtin attribute `{}`", attr.0);
617             }
618         }
619         map
620     });