]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_span/src/symbol.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_span / src / symbol.rs
CommitLineData
476ff2be 1//! An "interner" is a data structure that associates values with usize tags and
0731742a 2//! allows bidirectional lookup; i.e., given a value, one can easily find the
476ff2be
SL
3//! type, and vice versa.
4
f035d41b 5use rustc_arena::DroplessArena;
0731742a 6use rustc_data_structures::fx::FxHashMap;
dfeec247 7use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
c295e0f8 8use rustc_data_structures::sync::Lock;
3dfed10e 9use rustc_macros::HashStable_Generic;
416331ca 10use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
0731742a 11
dfeec247 12use std::cmp::{Ord, PartialEq, PartialOrd};
dc9dc135 13use std::fmt;
83c7162d 14use std::hash::{Hash, Hasher};
dc9dc135 15use std::str;
476ff2be 16
136023e0 17use crate::{with_session_globals, Edition, Span, DUMMY_SP};
0731742a 18
416331ca
XL
19#[cfg(test)]
20mod tests;
21
6a06907d 22// The proc macro code for this is in `compiler/rustc_macros/src/symbols.rs`.
48663c56
XL
23symbols! {
24 // After modifying this list adjust `is_special`, `is_used_keyword`/`is_unused_keyword`,
25 // this should be rarely necessary though if the keywords are kept in alphabetic order.
26 Keywords {
27 // Special reserved identifiers used internally for elided lifetimes,
28 // unnamed method parameters, crate root module, error recovery etc.
5869c6ff 29 Empty: "",
48663c56
XL
30 PathRoot: "{{root}}",
31 DollarCrate: "$crate",
32 Underscore: "_",
33
34 // Keywords that are used in stable Rust.
35 As: "as",
36 Break: "break",
37 Const: "const",
38 Continue: "continue",
39 Crate: "crate",
40 Else: "else",
41 Enum: "enum",
42 Extern: "extern",
43 False: "false",
44 Fn: "fn",
45 For: "for",
46 If: "if",
47 Impl: "impl",
48 In: "in",
49 Let: "let",
50 Loop: "loop",
51 Match: "match",
52 Mod: "mod",
53 Move: "move",
54 Mut: "mut",
55 Pub: "pub",
56 Ref: "ref",
57 Return: "return",
58 SelfLower: "self",
59 SelfUpper: "Self",
60 Static: "static",
61 Struct: "struct",
62 Super: "super",
63 Trait: "trait",
64 True: "true",
65 Type: "type",
66 Unsafe: "unsafe",
67 Use: "use",
68 Where: "where",
69 While: "while",
70
71 // Keywords that are used in unstable Rust or reserved for future use.
72 Abstract: "abstract",
73 Become: "become",
74 Box: "box",
75 Do: "do",
76 Final: "final",
77 Macro: "macro",
78 Override: "override",
79 Priv: "priv",
80 Typeof: "typeof",
81 Unsized: "unsized",
82 Virtual: "virtual",
83 Yield: "yield",
84
85 // Edition-specific keywords that are used in stable Rust.
e1599b0c
XL
86 Async: "async", // >= 2018 Edition only
87 Await: "await", // >= 2018 Edition only
48663c56
XL
88 Dyn: "dyn", // >= 2018 Edition only
89
90 // Edition-specific keywords that are used in unstable Rust or reserved for future use.
48663c56
XL
91 Try: "try", // >= 2018 Edition only
92
93 // Special lifetime names
94 UnderscoreLifetime: "'_",
95 StaticLifetime: "'static",
96
97 // Weak keywords, have special meaning only in specific contexts.
98 Auto: "auto",
99 Catch: "catch",
100 Default: "default",
74b04a01 101 MacroRules: "macro_rules",
60c5eb7d 102 Raw: "raw",
48663c56 103 Union: "union",
04454e1e 104 Yeet: "yeet",
48663c56
XL
105 }
106
3dfed10e
XL
107 // Pre-interned symbols that can be referred to with `rustc_span::sym::*`.
108 //
109 // The symbol is the stringified identifier unless otherwise specified, in
110 // which case the name should mention the non-identifier punctuation.
111 // E.g. `sym::proc_dash_macro` represents "proc-macro", and it shouldn't be
112 // called `sym::proc_macro` because then it's easy to mistakenly think it
113 // represents "proc_macro".
dc9dc135 114 //
1b1a35ee 115 // As well as the symbols listed, there are symbols for the strings
dc9dc135 116 // "0", "1", ..., "9", which are accessible via `sym::integer`.
3dfed10e
XL
117 //
118 // The proc macro will abort if symbols are not in alphabetical order (as
119 // defined by `impl Ord for str`) or if any symbols are duplicated. Vim
120 // users can sort the list by selecting it and executing the command
121 // `:'<,'>!LC_ALL=C sort`.
122 //
123 // There is currently no checking that all symbols are used; that would be
124 // nice to have.
48663c56 125 Symbols {
94222f64
XL
126 AcqRel,
127 Acquire,
923072b8 128 AddSubdiagnostic,
3dfed10e 129 Alignment,
136023e0 130 Any,
3dfed10e
XL
131 Arc,
132 Argument,
133 ArgumentV1,
923072b8 134 ArgumentV1Methods,
3dfed10e 135 Arguments,
136023e0
XL
136 AsMut,
137 AsRef,
064997fb
FG
138 AssertParamIsClone,
139 AssertParamIsCopy,
140 AssertParamIsEq,
94222f64
XL
141 AtomicBool,
142 AtomicI128,
143 AtomicI16,
144 AtomicI32,
145 AtomicI64,
146 AtomicI8,
147 AtomicIsize,
148 AtomicPtr,
149 AtomicU128,
150 AtomicU16,
151 AtomicU32,
152 AtomicU64,
153 AtomicU8,
154 AtomicUsize,
136023e0 155 BTreeEntry,
6a06907d
XL
156 BTreeMap,
157 BTreeSet,
158 BinaryHeap,
159 Borrow,
17df50a5 160 Break,
3dfed10e 161 C,
17df50a5 162 CStr,
29967ef6 163 CString,
923072b8 164 Capture,
3dfed10e
XL
165 Center,
166 Clone,
17df50a5 167 Continue,
3dfed10e
XL
168 Copy,
169 Count,
136023e0 170 Cow,
3dfed10e 171 Debug,
5869c6ff
XL
172 DebugStruct,
173 DebugTuple,
3dfed10e
XL
174 Decodable,
175 Decoder,
064997fb 176 DecorateLint,
3dfed10e 177 Default,
6a06907d 178 Deref,
923072b8 179 DiagnosticMessage,
136023e0 180 DirBuilder,
c295e0f8 181 Display,
136023e0
XL
182 DoubleEndedIterator,
183 Duration,
3dfed10e
XL
184 Encodable,
185 Encoder,
186 Eq,
187 Equal,
188 Err,
189 Error,
136023e0
XL
190 File,
191 FileType,
04454e1e
FG
192 Fn,
193 FnMut,
194 FnOnce,
3dfed10e
XL
195 FormatSpec,
196 Formatter,
197 From,
136023e0 198 FromIterator,
5099ac24 199 FromResidual,
3dfed10e
XL
200 Future,
201 FxHashMap,
202 FxHashSet,
203 GlobalAlloc,
204 Hash,
205 HashMap,
136023e0 206 HashMapEntry,
3dfed10e
XL
207 HashSet,
208 Hasher,
209 Implied,
210 Input,
c295e0f8 211 Into,
a2a8927a 212 IntoFuture,
3dfed10e 213 IntoIterator,
136023e0
XL
214 IoRead,
215 IoWrite,
923072b8 216 IrTyKind,
3dfed10e
XL
217 Is,
218 ItemContext,
219 Iterator,
220 Layout,
221 Left,
6a06907d 222 LinkedList,
3dfed10e 223 LintPass,
c295e0f8 224 Mutex,
5099ac24 225 N,
064997fb
FG
226 NonZeroI128,
227 NonZeroI16,
228 NonZeroI32,
229 NonZeroI64,
230 NonZeroI8,
231 NonZeroU128,
232 NonZeroU16,
233 NonZeroU32,
234 NonZeroU64,
235 NonZeroU8,
3dfed10e
XL
236 None,
237 Ok,
238 Option,
239 Ord,
240 Ordering,
6a06907d
XL
241 OsStr,
242 OsString,
3dfed10e
XL
243 Output,
244 Param,
245 PartialEq,
246 PartialOrd,
6a06907d
XL
247 Path,
248 PathBuf,
3dfed10e
XL
249 Pending,
250 Pin,
c295e0f8 251 Pointer,
3dfed10e
XL
252 Poll,
253 ProcMacro,
254 ProcMacroHack,
255 ProceduralMasqueradeDummyType,
256 Range,
257 RangeFrom,
258 RangeFull,
259 RangeInclusive,
260 RangeTo,
261 RangeToInclusive,
262 Rc,
263 Ready,
6a06907d 264 Receiver,
94222f64
XL
265 Relaxed,
266 Release,
3dfed10e
XL
267 Result,
268 Return,
269 Right,
064997fb 270 Rust,
3dfed10e
XL
271 RustcDecodable,
272 RustcEncodable,
273 Send,
94222f64 274 SeqCst,
923072b8 275 SessionDiagnostic,
04454e1e 276 SliceIndex,
3dfed10e 277 Some,
c295e0f8 278 String,
3dfed10e
XL
279 StructuralEq,
280 StructuralPartialEq,
923072b8 281 SubdiagnosticMessage,
3dfed10e
XL
282 Sync,
283 Target,
6a06907d
XL
284 ToOwned,
285 ToString,
3dfed10e 286 Try,
923072b8
FG
287 TryCaptureGeneric,
288 TryCapturePrintable,
c295e0f8
XL
289 TryFrom,
290 TryInto,
3dfed10e
XL
291 Ty,
292 TyCtxt,
293 TyKind,
294 Unknown,
c295e0f8 295 UnsafeArg,
3dfed10e 296 Vec,
c295e0f8 297 VecDeque,
923072b8 298 Wrapper,
3dfed10e
XL
299 Yield,
300 _DECLS,
301 _Self,
302 __D,
303 __H,
304 __S,
5e7ed085 305 __awaitee,
3dfed10e
XL
306 __try_var,
307 _d,
308 _e,
309 _task_context,
29967ef6 310 a32,
48663c56 311 aarch64_target_feature,
5e7ed085 312 aarch64_ver_target_feature,
48663c56
XL
313 abi,
314 abi_amdgpu_kernel,
3dfed10e 315 abi_avr_interrupt,
5869c6ff 316 abi_c_cmse_nonsecure_call,
e74abb32 317 abi_efiapi,
48663c56
XL
318 abi_msp430_interrupt,
319 abi_ptx,
320 abi_sysv64,
321 abi_thiscall,
322 abi_unadjusted,
323 abi_vectorcall,
324 abi_x86_interrupt,
ba9703b0 325 abort,
48663c56 326 aborts,
3dfed10e
XL
327 add,
328 add_assign,
60c5eb7d 329 add_with_overflow,
3dfed10e 330 address,
94222f64 331 adt_const_params,
48663c56
XL
332 advanced_slice_patterns,
333 adx_target_feature,
334 alias,
335 align,
3dfed10e 336 align_offset,
48663c56
XL
337 alignstack,
338 all,
3dfed10e
XL
339 alloc,
340 alloc_error_handler,
341 alloc_layout,
342 alloc_zeroed,
48663c56 343 allocator,
3c0e092e 344 allocator_api,
48663c56 345 allocator_internals,
48663c56 346 allow,
48663c56
XL
347 allow_fail,
348 allow_internal_unsafe,
349 allow_internal_unstable,
3dfed10e 350 allowed,
5099ac24 351 alu32,
48663c56 352 always,
dc9dc135 353 and,
3dfed10e 354 and_then,
064997fb 355 anonymous_lifetime_in_impl_trait,
48663c56 356 any,
5099ac24 357 append_const_msg,
dc9dc135 358 arbitrary_enum_discriminant,
48663c56 359 arbitrary_self_types,
5099ac24 360 args,
f9f354fc 361 arith_offset,
29967ef6 362 arm,
48663c56 363 arm_target_feature,
3dfed10e
XL
364 array,
365 arrays,
29967ef6 366 as_ptr,
5099ac24 367 as_ref,
3dfed10e 368 as_str,
48663c56 369 asm,
3c0e092e
XL
370 asm_const,
371 asm_experimental_arch,
372 asm_sym,
a2a8927a 373 asm_unwind,
416331ca 374 assert,
5099ac24 375 assert_eq_macro,
f035d41b 376 assert_inhabited,
fc512014 377 assert_macro,
5099ac24 378 assert_ne_macro,
3dfed10e 379 assert_receiver_is_total_eq,
f035d41b
XL
380 assert_uninit_valid,
381 assert_zero_valid,
923072b8 382 asserting,
5099ac24 383 associated_const_equality,
48663c56 384 associated_consts,
dc9dc135 385 associated_type_bounds,
48663c56
XL
386 associated_type_defaults,
387 associated_types,
f035d41b 388 assume,
60c5eb7d 389 assume_init,
48663c56 390 async_await,
416331ca 391 async_closure,
94222f64
XL
392 atomic,
393 atomic_mod,
f035d41b 394 atomics,
3dfed10e 395 att_syntax,
48663c56 396 attr,
48663c56 397 attr_literals,
3dfed10e 398 attributes,
48663c56 399 augmented_assignments,
fc512014 400 auto_traits,
48663c56 401 automatically_derived,
5099ac24 402 avx,
48663c56 403 avx512_target_feature,
5099ac24
FG
404 avx512bw,
405 avx512f,
48663c56 406 await_macro,
3dfed10e 407 bang,
dc9dc135
XL
408 begin_panic,
409 bench,
48663c56
XL
410 bin,
411 bind_by_move_pattern_guards,
dfeec247 412 bindings_after_at,
3dfed10e
XL
413 bitand,
414 bitand_assign,
415 bitor,
416 bitor_assign,
417 bitreverse,
418 bitxor,
419 bitxor_assign,
94222f64 420 black_box,
48663c56 421 block,
dc9dc135 422 bool,
dfeec247 423 borrowck_graphviz_format,
48663c56
XL
424 borrowck_graphviz_postflow,
425 borrowck_graphviz_preflow,
3dfed10e 426 box_free,
48663c56
XL
427 box_patterns,
428 box_syntax,
17df50a5 429 bpf_target_feature,
48663c56 430 braced_empty_structs,
17df50a5 431 branch,
f035d41b 432 breakpoint,
3dfed10e 433 bridge,
60c5eb7d 434 bswap,
29967ef6 435 c_str,
6a06907d 436 c_unwind,
3dfed10e
XL
437 c_variadic,
438 call,
439 call_mut,
440 call_once,
60c5eb7d 441 caller_location,
fc512014 442 capture_disjoint_fields,
48663c56 443 cdylib,
f035d41b
XL
444 ceilf32,
445 ceilf64,
48663c56 446 cfg,
ba9703b0 447 cfg_accessible,
48663c56
XL
448 cfg_attr,
449 cfg_attr_multi,
416331ca 450 cfg_doctest,
6a06907d 451 cfg_eval,
c295e0f8 452 cfg_hide,
5099ac24 453 cfg_macro,
29967ef6 454 cfg_panic,
60c5eb7d 455 cfg_sanitize,
136023e0 456 cfg_target_abi,
923072b8 457 cfg_target_compact,
48663c56
XL
458 cfg_target_feature,
459 cfg_target_has_atomic,
5099ac24
FG
460 cfg_target_has_atomic_equal_alignment,
461 cfg_target_has_atomic_load_store,
48663c56
XL
462 cfg_target_thread_local,
463 cfg_target_vendor,
f9f354fc 464 cfg_version,
3c0e092e 465 cfi,
dc9dc135 466 char,
3dfed10e 467 client,
416331ca 468 clippy,
94222f64 469 clobber_abi,
48663c56
XL
470 clone,
471 clone_closures,
472 clone_from,
1b1a35ee 473 closure,
064997fb 474 closure_lifetime_binder,
48663c56 475 closure_to_fn_coercion,
c295e0f8 476 closure_track_caller,
dc9dc135 477 cmp,
136023e0
XL
478 cmp_max,
479 cmp_min,
48663c56 480 cmpxchg16b_target_feature,
1b1a35ee 481 cmse_nonsecure_entry,
3dfed10e 482 coerce_unsized,
48663c56 483 cold,
416331ca 484 column,
5099ac24 485 column_macro,
94222f64
XL
486 compare_and_swap,
487 compare_exchange,
488 compare_exchange_weak,
48663c56 489 compile_error,
5099ac24
FG
490 compile_error_macro,
491 compiler,
48663c56 492 compiler_builtins,
94222f64 493 compiler_fence,
416331ca 494 concat,
a2a8927a 495 concat_bytes,
48663c56 496 concat_idents,
5099ac24 497 concat_macro,
48663c56
XL
498 conservative_impl_trait,
499 console,
fc512014 500 const_allocate,
17df50a5 501 const_async_blocks,
48663c56 502 const_compare_raw_pointers,
dc9dc135 503 const_constructor,
5099ac24 504 const_deallocate,
74b04a01 505 const_eval_limit,
c295e0f8
XL
506 const_eval_select,
507 const_eval_select_ct,
1b1a35ee 508 const_evaluatable_checked,
e74abb32 509 const_extern_fn,
48663c56 510 const_fn,
1b1a35ee
XL
511 const_fn_floating_point_arithmetic,
512 const_fn_fn_ptr_basics,
cdc7bbd5 513 const_fn_trait_bound,
f035d41b 514 const_fn_transmute,
48663c56 515 const_fn_union,
cdc7bbd5 516 const_fn_unsize,
94222f64
XL
517 const_for,
518 const_format_args,
cdc7bbd5 519 const_generic_defaults,
48663c56 520 const_generics,
5869c6ff 521 const_generics_defaults,
60c5eb7d 522 const_if_match,
29967ef6 523 const_impl_trait,
416331ca 524 const_in_array_repeat_expressions,
3dfed10e 525 const_indexing,
48663c56 526 const_let,
60c5eb7d
XL
527 const_loop,
528 const_mut_refs,
48663c56 529 const_panic,
94222f64 530 const_panic_fmt,
f035d41b 531 const_precise_live_drops,
48663c56
XL
532 const_raw_ptr_deref,
533 const_raw_ptr_to_usize_cast,
5869c6ff 534 const_refs_to_cell,
923072b8 535 const_trait,
dfeec247
XL
536 const_trait_bound_opt_out,
537 const_trait_impl,
3dfed10e 538 const_transmute,
94222f64 539 const_try,
1b1a35ee
XL
540 constant,
541 constructor,
48663c56 542 contents,
dc9dc135 543 context,
48663c56 544 convert,
f035d41b 545 copy,
3dfed10e 546 copy_closures,
f035d41b
XL
547 copy_nonoverlapping,
548 copysignf32,
549 copysignf64,
48663c56
XL
550 core,
551 core_intrinsics,
5869c6ff
XL
552 core_panic,
553 core_panic_2015_macro,
fc512014 554 core_panic_macro,
f035d41b
XL
555 cosf32,
556 cosf64,
a2a8927a 557 count,
94222f64 558 cr,
48663c56
XL
559 crate_id,
560 crate_in_paths,
dc9dc135 561 crate_local,
48663c56
XL
562 crate_name,
563 crate_type,
564 crate_visibility_modifier,
3dfed10e 565 crt_dash_static: "crt-static",
29967ef6 566 cstring_type,
3dfed10e
XL
567 ctlz,
568 ctlz_nonzero,
60c5eb7d
XL
569 ctpop,
570 cttz,
571 cttz_nonzero,
48663c56
XL
572 custom_attribute,
573 custom_derive,
574 custom_inner_attributes,
575 custom_test_frameworks,
3dfed10e 576 d,
5e7ed085 577 d32,
5099ac24 578 dbg_macro,
3dfed10e
XL
579 dead_code,
580 dealloc,
581 debug,
5099ac24 582 debug_assert_eq_macro,
fc512014 583 debug_assert_macro,
5099ac24 584 debug_assert_ne_macro,
3dfed10e
XL
585 debug_assertions,
586 debug_struct,
064997fb 587 debug_struct_fields_finish,
3dfed10e
XL
588 debug_trait_builder,
589 debug_tuple,
064997fb 590 debug_tuple_fields_finish,
04454e1e 591 debugger_visualizer,
48663c56 592 decl_macro,
3dfed10e
XL
593 declare_lint_pass,
594 decode,
29967ef6 595 default_alloc_error_handler,
48663c56 596 default_lib_allocator,
136023e0 597 default_method_body_is_const,
48663c56
XL
598 default_type_parameter_fallback,
599 default_type_params,
60c5eb7d 600 delay_span_bug_from_inside_query,
48663c56
XL
601 deny,
602 deprecated,
5e7ed085
FG
603 deprecated_safe,
604 deprecated_suggestion,
dc9dc135 605 deref,
1b1a35ee 606 deref_method,
dc9dc135 607 deref_mut,
1b1a35ee 608 deref_target,
48663c56 609 derive,
94222f64 610 derive_default_enum,
5e7ed085 611 destruct,
29967ef6 612 destructuring_assignment,
e1599b0c 613 diagnostic,
dc9dc135 614 direct,
3dfed10e
XL
615 discriminant_kind,
616 discriminant_type,
ba9703b0 617 discriminant_value,
3dfed10e 618 dispatch_from_dyn,
136023e0 619 display_trait,
3dfed10e
XL
620 div,
621 div_assign,
48663c56
XL
622 doc,
623 doc_alias,
c295e0f8 624 doc_auto_cfg,
48663c56 625 doc_cfg,
c295e0f8 626 doc_cfg_hide,
48663c56
XL
627 doc_keyword,
628 doc_masked,
cdc7bbd5 629 doc_notable_trait,
94222f64 630 doc_primitive,
3dfed10e 631 doc_spotlight,
416331ca 632 doctest,
48663c56 633 document_private_items,
5099ac24 634 dotdot: "..",
48663c56 635 dotdot_in_tuple_patterns,
3dfed10e 636 dotdoteq_in_patterns,
fc512014
XL
637 dreg,
638 dreg_low16,
639 dreg_low8,
3dfed10e
XL
640 drop,
641 drop_in_place,
642 drop_types_in_const,
48663c56
XL
643 dropck_eyepatch,
644 dropck_parametricity,
48663c56 645 dylib,
6a06907d 646 dyn_metadata,
48663c56 647 dyn_trait,
5099ac24 648 e,
5869c6ff 649 edition_macro_pats,
dc3f5686 650 edition_panic,
3dfed10e 651 eh_catch_typeinfo,
48663c56 652 eh_personality,
3dfed10e
XL
653 emit_enum,
654 emit_enum_variant,
655 emit_enum_variant_arg,
656 emit_struct,
657 emit_struct_field,
48663c56 658 enable,
3dfed10e
XL
659 enclosing_scope,
660 encode,
5099ac24 661 end,
416331ca 662 env,
5099ac24
FG
663 env_macro,
664 eprint_macro,
665 eprintln_macro,
dc9dc135 666 eq,
29967ef6 667 ermsb_target_feature,
f035d41b 668 exact_div,
48663c56 669 except,
3dfed10e 670 exchange_malloc,
48663c56
XL
671 exclusive_range_pattern,
672 exhaustive_integer_patterns,
673 exhaustive_patterns,
674 existential_type,
f035d41b
XL
675 exp2f32,
676 exp2f64,
29967ef6 677 expect,
48663c56 678 expected,
3dfed10e
XL
679 expf32,
680 expf64,
94222f64 681 explicit_generic_args_with_impl_trait,
48663c56 682 export_name,
dc9dc135 683 expr,
fc512014 684 extended_key_value_attributes,
48663c56 685 extern_absolute_paths,
48663c56
XL
686 extern_crate_item_prelude,
687 extern_crate_self,
688 extern_in_paths,
689 extern_prelude,
690 extern_types,
3dfed10e
XL
691 external_doc,
692 f,
48663c56 693 f16c_target_feature,
dc9dc135
XL
694 f32,
695 f64,
f035d41b
XL
696 fabsf32,
697 fabsf64,
3dfed10e 698 fadd_fast,
064997fb 699 fake_variadic,
f035d41b 700 fdiv_fast,
48663c56 701 feature,
94222f64 702 fence,
a2a8927a 703 ferris: "🦀",
94222f64 704 fetch_update,
29967ef6 705 ffi,
f9f354fc
XL
706 ffi_const,
707 ffi_pure,
48663c56 708 ffi_returns_twice,
dc9dc135 709 field,
48663c56
XL
710 field_init_shorthand,
711 file,
5099ac24 712 file_macro,
3dfed10e
XL
713 fill,
714 finish,
715 flags,
5099ac24 716 float,
f035d41b 717 float_to_int_unchecked,
f035d41b 718 floorf32,
3dfed10e 719 floorf64,
f035d41b
XL
720 fmaf32,
721 fmaf64,
dc9dc135 722 fmt,
94222f64 723 fmt_as_str,
dc9dc135 724 fmt_internals,
f035d41b 725 fmul_fast,
136023e0 726 fn_align,
48663c56 727 fn_must_use,
3dfed10e
XL
728 fn_mut,
729 fn_once,
730 fn_once_output,
48663c56 731 forbid,
f035d41b 732 forget,
3dfed10e 733 format,
416331ca 734 format_args,
f035d41b 735 format_args_capture,
5099ac24 736 format_args_macro,
3dfed10e 737 format_args_nl,
6a06907d 738 format_macro,
5099ac24 739 fp,
3dfed10e 740 freeze,
fc512014 741 freg,
f035d41b 742 frem_fast,
48663c56 743 from,
dc9dc135 744 from_desugaring,
48663c56 745 from_generator,
136023e0 746 from_iter,
dc9dc135 747 from_method,
17df50a5
XL
748 from_output,
749 from_residual,
3dfed10e 750 from_size_align_unchecked,
3dfed10e 751 from_usize,
04454e1e 752 from_yeet,
f035d41b 753 fsub_fast,
48663c56
XL
754 fundamental,
755 future,
3dfed10e 756 future_trait,
923072b8 757 gdb_script_file,
3dfed10e 758 ge,
48663c56 759 gen_future,
dfeec247 760 gen_kill,
3dfed10e 761 generator,
3c0e092e 762 generator_return,
3dfed10e 763 generator_state,
48663c56 764 generators,
94222f64 765 generic_arg_infer,
923072b8 766 generic_assert,
48663c56 767 generic_associated_types,
5e7ed085 768 generic_associated_types_extended,
94222f64 769 generic_const_exprs,
48663c56 770 generic_param_attrs,
ba9703b0 771 get_context,
48663c56
XL
772 global_allocator,
773 global_asm,
774 globs,
3dfed10e 775 gt,
dfeec247 776 half_open_range_patterns,
dc9dc135 777 hash,
48663c56
XL
778 hexagon_target_feature,
779 hidden,
780 homogeneous_aggregate,
781 html_favicon_url,
782 html_logo_url,
783 html_no_source,
784 html_playground_url,
785 html_root_url,
6a06907d 786 hwaddress,
3dfed10e 787 i,
48663c56
XL
788 i128,
789 i128_type,
790 i16,
791 i32,
792 i64,
793 i8,
794 ident,
795 if_let,
3dfed10e 796 if_let_guard,
48663c56
XL
797 if_while_or_patterns,
798 ignore,
799 impl_header_lifetime_elision,
416331ca 800 impl_lint_pass,
3dfed10e 801 impl_macros,
48663c56 802 impl_trait_in_bindings,
064997fb
FG
803 implied_by,
804 import,
48663c56 805 import_shadowing,
cdc7bbd5 806 imported_main,
48663c56
XL
807 in_band_lifetimes,
808 include,
416331ca 809 include_bytes,
5099ac24
FG
810 include_bytes_macro,
811 include_macro,
416331ca 812 include_str,
5099ac24 813 include_str_macro,
48663c56 814 inclusive_range_syntax,
3dfed10e
XL
815 index,
816 index_mut,
48663c56
XL
817 infer_outlives_requirements,
818 infer_static_outlives_requirements,
6a06907d 819 inherent_associated_types,
3dfed10e 820 inlateout,
48663c56 821 inline,
29967ef6 822 inline_const,
3c0e092e 823 inline_const_pat,
3dfed10e 824 inout,
29967ef6 825 instruction_set,
5099ac24
FG
826 integer_: "integer",
827 integral,
48663c56 828 intel,
a2a8927a 829 into_future,
48663c56 830 into_iter,
5869c6ff 831 intra_doc_pointers,
48663c56
XL
832 intrinsics,
833 irrefutable_let_patterns,
29967ef6 834 isa_attribute,
48663c56
XL
835 isize,
836 issue,
837 issue_5723_bootstrap,
838 issue_tracker_base_url,
dc9dc135 839 item,
48663c56
XL
840 item_like_imports,
841 iter,
136023e0 842 iter_repeat,
48663c56
XL
843 keyword,
844 kind,
fc512014 845 kreg,
04454e1e 846 kreg0,
48663c56
XL
847 label,
848 label_break_value,
849 lang,
850 lang_items,
cdc7bbd5 851 large_assignments,
f9f354fc 852 lateout,
3dfed10e
XL
853 lazy_normalization_consts,
854 le,
136023e0 855 len,
dc9dc135 856 let_chains,
94222f64 857 let_else,
dc9dc135 858 lhs,
48663c56 859 lib,
3dfed10e 860 libc,
dc9dc135 861 lifetime,
f035d41b 862 likely,
416331ca 863 line,
5099ac24 864 line_macro,
48663c56 865 link,
48663c56
XL
866 link_args,
867 link_cfg,
868 link_llvm_intrinsics,
869 link_name,
e74abb32 870 link_ordinal,
48663c56 871 link_section,
3dfed10e 872 linkage,
5099ac24 873 linker,
48663c56 874 lint_reasons,
dc9dc135 875 literal,
94222f64 876 load,
a2a8927a 877 loaded_from_disk,
fc512014 878 local,
48663c56 879 local_inner_macros,
f035d41b
XL
880 log10f32,
881 log10f64,
882 log2f32,
883 log2f64,
3dfed10e
XL
884 log_syntax,
885 logf32,
886 logf64,
48663c56 887 loop_break_value,
3dfed10e 888 lt,
48663c56 889 macro_at_most_once_rep,
6a06907d 890 macro_attributes_in_derive_output,
48663c56
XL
891 macro_escape,
892 macro_export,
893 macro_lifetime_matcher,
894 macro_literal_matcher,
5e7ed085 895 macro_metavar_expr,
48663c56 896 macro_reexport,
48663c56
XL
897 macro_use,
898 macro_vis_matcher,
3dfed10e 899 macros_in_extern,
48663c56
XL
900 main,
901 managed_boxes,
3dfed10e
XL
902 manually_drop,
903 map,
48663c56
XL
904 marker,
905 marker_trait_attr,
906 masked,
907 match_beginning_vert,
908 match_default_bindings,
5099ac24 909 matches_macro,
3dfed10e
XL
910 maxnumf32,
911 maxnumf64,
48663c56 912 may_dangle,
a2a8927a 913 may_unwind,
3dfed10e 914 maybe_uninit,
60c5eb7d
XL
915 maybe_uninit_uninit,
916 maybe_uninit_zeroed,
136023e0
XL
917 mem_discriminant,
918 mem_drop,
919 mem_forget,
920 mem_replace,
921 mem_size_of,
922 mem_size_of_val,
60c5eb7d 923 mem_uninitialized,
c295e0f8 924 mem_variant_count,
60c5eb7d 925 mem_zeroed,
dc9dc135 926 member_constraints,
74b04a01 927 memory,
5099ac24 928 memtag,
48663c56
XL
929 message,
930 meta,
6a06907d 931 metadata_type,
60c5eb7d 932 min_align_of,
f035d41b 933 min_align_of_val,
48663c56 934 min_const_fn,
3dfed10e 935 min_const_generics,
48663c56 936 min_const_unsafe_fn,
ba9703b0 937 min_specialization,
6a06907d 938 min_type_alias_impl_trait,
f035d41b
XL
939 minnumf32,
940 minnumf64,
48663c56 941 mips_target_feature,
5e7ed085 942 miri,
1b1a35ee 943 misc,
136023e0 944 mmx_reg,
17df50a5 945 modifiers,
48663c56 946 module,
416331ca 947 module_path,
5099ac24 948 module_path_macro,
17df50a5 949 more_qualified_paths,
48663c56 950 more_struct_aliases,
3dfed10e 951 movbe_target_feature,
74b04a01 952 move_ref_pattern,
cdc7bbd5 953 move_size_limit,
3dfed10e
XL
954 mul,
955 mul_assign,
60c5eb7d 956 mul_with_overflow,
c295e0f8 957 must_not_suspend,
48663c56
XL
958 must_use,
959 naked,
960 naked_functions,
961 name,
5099ac24 962 names,
17df50a5
XL
963 native_link_modifiers,
964 native_link_modifiers_as_needed,
965 native_link_modifiers_bundle,
966 native_link_modifiers_verbatim,
967 native_link_modifiers_whole_archive,
04454e1e 968 natvis_file,
3dfed10e 969 ne,
f035d41b
XL
970 nearbyintf32,
971 nearbyintf64,
48663c56 972 needs_allocator,
60c5eb7d 973 needs_drop,
48663c56 974 needs_panic_runtime,
3dfed10e 975 neg,
48663c56 976 negate_unsigned,
ba9703b0 977 negative_impls,
5099ac24 978 neon,
48663c56
XL
979 never,
980 never_type,
60c5eb7d 981 never_type_fallback,
dc9dc135 982 new,
3dfed10e 983 new_unchecked,
48663c56 984 next,
48663c56 985 nll,
3dfed10e 986 no,
48663c56
XL
987 no_builtins,
988 no_core,
cdc7bbd5 989 no_coverage,
48663c56
XL
990 no_crate_inject,
991 no_debug,
992 no_default_passes,
993 no_implicit_prelude,
994 no_inline,
995 no_link,
996 no_main,
997 no_mangle,
3dfed10e
XL
998 no_sanitize,
999 no_stack_check,
1000 no_start,
1001 no_std,
f9f354fc 1002 nomem,
48663c56 1003 non_ascii_idents,
48663c56 1004 non_exhaustive,
c295e0f8 1005 non_exhaustive_omitted_patterns_lint,
48663c56 1006 non_modrs_mods,
3dfed10e 1007 none_error,
f035d41b 1008 nontemporal_store,
6a06907d
XL
1009 noop_method_borrow,
1010 noop_method_clone,
1011 noop_method_deref,
f9f354fc 1012 noreturn,
f9f354fc 1013 nostack,
48663c56 1014 not,
cdc7bbd5 1015 notable_trait,
48663c56 1016 note,
e74abb32 1017 object_safe_for_dispatch,
3dfed10e 1018 of,
f9f354fc 1019 offset,
48663c56
XL
1020 omit_gdb_pretty_printer_section,
1021 on,
1022 on_unimplemented,
1023 oom,
3dfed10e 1024 opaque,
48663c56 1025 ops,
3dfed10e 1026 opt_out_copy,
48663c56
XL
1027 optimize,
1028 optimize_attribute,
1029 optin_builtin_traits,
1030 option,
416331ca 1031 option_env,
5099ac24 1032 option_env_macro,
f9f354fc 1033 options,
dc9dc135 1034 or,
e1599b0c 1035 or_patterns,
3dfed10e 1036 other,
f9f354fc 1037 out,
48663c56 1038 overlapping_marker_traits,
3dfed10e 1039 owned_box,
48663c56 1040 packed,
dc9dc135 1041 panic,
5869c6ff
XL
1042 panic_2015,
1043 panic_2021,
3dfed10e
XL
1044 panic_abort,
1045 panic_bounds_check,
c295e0f8 1046 panic_display,
94222f64 1047 panic_fmt,
48663c56
XL
1048 panic_handler,
1049 panic_impl,
1050 panic_implementation,
3dfed10e
XL
1051 panic_info,
1052 panic_location,
5099ac24 1053 panic_no_unwind,
48663c56 1054 panic_runtime,
29967ef6 1055 panic_str,
3dfed10e 1056 panic_unwind,
fc512014 1057 panicking,
3dfed10e 1058 param_attrs,
dc9dc135 1059 partial_cmp,
3dfed10e 1060 partial_ord,
48663c56 1061 passes,
dc9dc135 1062 pat,
cdc7bbd5 1063 pat_param,
48663c56
XL
1064 path,
1065 pattern_parentheses,
3dfed10e 1066 phantom_data,
48663c56 1067 pin,
48663c56
XL
1068 platform_intrinsics,
1069 plugin,
1070 plugin_registrar,
1071 plugins,
6a06907d 1072 pointee_trait,
3dfed10e 1073 pointer,
29967ef6 1074 pointer_trait_fmt,
ba9703b0 1075 poll,
3dfed10e
XL
1076 position,
1077 post_dash_lto: "post-lto",
48663c56 1078 powerpc_target_feature,
f035d41b
XL
1079 powf32,
1080 powf64,
1081 powif32,
1082 powif64,
3dfed10e 1083 pre_dash_lto: "pre-lto",
48663c56 1084 precise_pointer_size_matching,
3dfed10e 1085 precision,
60c5eb7d 1086 pref_align_of,
f035d41b
XL
1087 prefetch_read_data,
1088 prefetch_read_instruction,
1089 prefetch_write_data,
1090 prefetch_write_instruction,
136023e0 1091 preg,
48663c56
XL
1092 prelude,
1093 prelude_import,
f9f354fc 1094 preserves_flags,
48663c56 1095 primitive,
5099ac24
FG
1096 print_macro,
1097 println_macro,
48663c56
XL
1098 proc_dash_macro: "proc-macro",
1099 proc_macro,
1100 proc_macro_attribute,
dc9dc135 1101 proc_macro_def_site,
48663c56
XL
1102 proc_macro_derive,
1103 proc_macro_expr,
1104 proc_macro_gen,
1105 proc_macro_hygiene,
416331ca 1106 proc_macro_internals,
48663c56
XL
1107 proc_macro_mod,
1108 proc_macro_non_items,
1109 proc_macro_path_invoc,
f035d41b 1110 profiler_builtins,
48663c56 1111 profiler_runtime,
5e7ed085 1112 ptr,
f035d41b
XL
1113 ptr_guaranteed_eq,
1114 ptr_guaranteed_ne,
cdc7bbd5
XL
1115 ptr_null,
1116 ptr_null_mut,
60c5eb7d 1117 ptr_offset_from,
04454e1e 1118 ptr_offset_from_unsigned,
6a06907d 1119 pub_macro_rules,
48663c56 1120 pub_restricted,
f9f354fc 1121 pure,
48663c56 1122 pushpop_unsafe,
fc512014
XL
1123 qreg,
1124 qreg_low4,
1125 qreg_low8,
48663c56
XL
1126 quad_precision_float,
1127 question_mark,
1128 quote,
3dfed10e 1129 range_inclusive_new,
e74abb32 1130 raw_dylib,
136023e0 1131 raw_eq,
48663c56 1132 raw_identifiers,
60c5eb7d 1133 raw_ref_op,
3dfed10e
XL
1134 re_rebalance_coherence,
1135 read_enum,
1136 read_enum_variant,
1137 read_enum_variant_arg,
1138 read_struct,
1139 read_struct_field,
f9f354fc 1140 readonly,
3dfed10e 1141 realloc,
48663c56 1142 reason,
3dfed10e 1143 receiver,
48663c56
XL
1144 recursion_limit,
1145 reexport_test_harness_main,
136023e0 1146 ref_unwind_safe_trait,
3dfed10e 1147 reference,
48663c56 1148 reflect,
fc512014
XL
1149 reg,
1150 reg16,
1151 reg32,
1152 reg64,
1153 reg_abcd,
1154 reg_byte,
a2a8927a 1155 reg_iw,
17df50a5 1156 reg_nonzero,
a2a8927a
XL
1157 reg_pair,
1158 reg_ptr,
1159 reg_upper,
60c5eb7d
XL
1160 register_attr,
1161 register_tool,
48663c56 1162 relaxed_adts,
5869c6ff 1163 relaxed_struct_unsize,
3dfed10e
XL
1164 rem,
1165 rem_assign,
48663c56
XL
1166 repr,
1167 repr128,
1168 repr_align,
1169 repr_align_enum,
1170 repr_packed,
1171 repr_simd,
1172 repr_transparent,
17df50a5 1173 residual,
48663c56 1174 result,
dc9dc135 1175 rhs,
f035d41b
XL
1176 rintf32,
1177 rintf64,
f9f354fc 1178 riscv_target_feature,
48663c56 1179 rlib,
60c5eb7d
XL
1180 rotate_left,
1181 rotate_right,
f035d41b
XL
1182 roundf32,
1183 roundf64,
dc9dc135 1184 rt,
48663c56
XL
1185 rtm_target_feature,
1186 rust,
6a06907d 1187 rust_2015,
48663c56 1188 rust_2015_preview,
6a06907d 1189 rust_2018,
48663c56 1190 rust_2018_preview,
6a06907d 1191 rust_2021,
5869c6ff 1192 rust_2021_preview,
04454e1e
FG
1193 rust_2024,
1194 rust_2024_preview,
48663c56 1195 rust_begin_unwind,
923072b8 1196 rust_cold_cc,
1b1a35ee 1197 rust_eh_catch_typeinfo,
3dfed10e
XL
1198 rust_eh_personality,
1199 rust_eh_register_frames,
1200 rust_eh_unregister_frames,
1201 rust_oom,
dc9dc135
XL
1202 rustc,
1203 rustc_allocator,
48663c56 1204 rustc_allocator_nounwind,
064997fb 1205 rustc_allocator_zeroed,
29967ef6 1206 rustc_allow_const_fn_unstable,
5e7ed085 1207 rustc_allow_incoherent_impl,
064997fb 1208 rustc_allowed_through_unstable_modules,
48663c56 1209 rustc_attrs,
923072b8 1210 rustc_box,
416331ca 1211 rustc_builtin_macro,
fc512014 1212 rustc_capture_analysis,
48663c56 1213 rustc_clean,
5e7ed085 1214 rustc_coherence_is_core,
60c5eb7d 1215 rustc_const_stable,
3dfed10e 1216 rustc_const_unstable,
48663c56 1217 rustc_conversion_suggestion,
064997fb 1218 rustc_deallocator,
48663c56 1219 rustc_def_path,
e1599b0c 1220 rustc_diagnostic_item,
48663c56
XL
1221 rustc_diagnostic_macros,
1222 rustc_dirty,
c295e0f8 1223 rustc_do_not_const_check,
dc9dc135 1224 rustc_dummy,
48663c56
XL
1225 rustc_dump_env_program_clauses,
1226 rustc_dump_program_clauses,
1227 rustc_dump_user_substs,
94222f64 1228 rustc_dump_vtable,
48663c56 1229 rustc_error,
17df50a5 1230 rustc_evaluate_where_clauses,
48663c56 1231 rustc_expected_cgu_reuse,
04454e1e 1232 rustc_has_incoherent_inherent_impls,
48663c56
XL
1233 rustc_if_this_changed,
1234 rustc_inherit_overflow_checks,
17df50a5 1235 rustc_insignificant_dtor,
48663c56
XL
1236 rustc_layout,
1237 rustc_layout_scalar_valid_range_end,
1238 rustc_layout_scalar_valid_range_start,
6a06907d 1239 rustc_legacy_const_generics,
923072b8 1240 rustc_lint_diagnostics,
064997fb
FG
1241 rustc_lint_opt_deny_field_access,
1242 rustc_lint_opt_ty,
5099ac24 1243 rustc_lint_query_instability,
416331ca 1244 rustc_macro_transparency,
cdc7bbd5 1245 rustc_main,
48663c56 1246 rustc_mir,
5099ac24 1247 rustc_must_implement_one_of,
dc9dc135 1248 rustc_nonnull_optimization_guaranteed,
48663c56
XL
1249 rustc_object_lifetime_default,
1250 rustc_on_unimplemented,
1251 rustc_outlives,
1252 rustc_paren_sugar,
1253 rustc_partition_codegened,
1254 rustc_partition_reused,
5099ac24 1255 rustc_pass_by_value,
48663c56
XL
1256 rustc_peek,
1257 rustc_peek_definite_init,
f9f354fc 1258 rustc_peek_liveness,
48663c56
XL
1259 rustc_peek_maybe_init,
1260 rustc_peek_maybe_uninit,
3dfed10e 1261 rustc_polymorphize_error,
48663c56
XL
1262 rustc_private,
1263 rustc_proc_macro_decls,
1264 rustc_promotable,
064997fb 1265 rustc_reallocator,
48663c56 1266 rustc_regions,
3dfed10e
XL
1267 rustc_reservation_impl,
1268 rustc_serialize,
cdc7bbd5 1269 rustc_skip_array_during_method_dispatch,
ba9703b0 1270 rustc_specialization_trait,
48663c56
XL
1271 rustc_stable,
1272 rustc_std_internal_symbol,
3c0e092e 1273 rustc_strict_coherence,
48663c56 1274 rustc_symbol_name,
48663c56
XL
1275 rustc_test_marker,
1276 rustc_then_this_would_need,
c295e0f8 1277 rustc_trivial_field_reads,
3dfed10e 1278 rustc_unsafe_specialization_marker,
48663c56 1279 rustc_variance,
6a06907d 1280 rustdoc,
3c0e092e 1281 rustdoc_internals,
416331ca 1282 rustfmt,
48663c56 1283 rvalue_static_promotion,
136023e0 1284 s,
60c5eb7d 1285 sanitize,
48663c56 1286 sanitizer_runtime,
60c5eb7d
XL
1287 saturating_add,
1288 saturating_sub,
48663c56
XL
1289 self_in_typedefs,
1290 self_struct_ctor,
3dfed10e 1291 semitransparent,
064997fb 1292 shadow_call_stack,
3dfed10e
XL
1293 shl,
1294 shl_assign,
48663c56 1295 should_panic,
3dfed10e
XL
1296 shr,
1297 shr_assign,
48663c56 1298 simd,
3dfed10e
XL
1299 simd_add,
1300 simd_and,
04454e1e 1301 simd_arith_offset,
5099ac24 1302 simd_as,
3dfed10e
XL
1303 simd_bitmask,
1304 simd_cast,
1305 simd_ceil,
1306 simd_div,
1307 simd_eq,
60c5eb7d 1308 simd_extract,
3dfed10e
XL
1309 simd_fabs,
1310 simd_fcos,
1311 simd_fexp,
1312 simd_fexp2,
48663c56 1313 simd_ffi,
3dfed10e
XL
1314 simd_flog,
1315 simd_flog10,
1316 simd_flog2,
1317 simd_floor,
1318 simd_fma,
1319 simd_fmax,
1320 simd_fmin,
1321 simd_fpow,
1322 simd_fpowi,
1323 simd_fsin,
1324 simd_fsqrt,
1325 simd_gather,
1326 simd_ge,
1327 simd_gt,
60c5eb7d 1328 simd_insert,
3dfed10e
XL
1329 simd_le,
1330 simd_lt,
1331 simd_mul,
1332 simd_ne,
6a06907d 1333 simd_neg,
3dfed10e
XL
1334 simd_or,
1335 simd_reduce_add_ordered,
1336 simd_reduce_add_unordered,
1337 simd_reduce_all,
1338 simd_reduce_and,
1339 simd_reduce_any,
1340 simd_reduce_max,
1341 simd_reduce_max_nanless,
1342 simd_reduce_min,
1343 simd_reduce_min_nanless,
1344 simd_reduce_mul_ordered,
1345 simd_reduce_mul_unordered,
1346 simd_reduce_or,
1347 simd_reduce_xor,
1348 simd_rem,
cdc7bbd5 1349 simd_round,
3dfed10e
XL
1350 simd_saturating_add,
1351 simd_saturating_sub,
1352 simd_scatter,
1353 simd_select,
1354 simd_select_bitmask,
1355 simd_shl,
1356 simd_shr,
c295e0f8 1357 simd_shuffle,
3dfed10e 1358 simd_sub,
cdc7bbd5 1359 simd_trunc,
3dfed10e 1360 simd_xor,
48663c56 1361 since,
f035d41b
XL
1362 sinf32,
1363 sinf64,
48663c56 1364 size,
60c5eb7d 1365 size_of,
f035d41b 1366 size_of_val,
3dfed10e 1367 sized,
6a06907d 1368 skip,
3dfed10e 1369 slice,
136023e0 1370 slice_len_fn,
48663c56
XL
1371 slice_patterns,
1372 slicing_syntax,
416331ca 1373 soft,
48663c56
XL
1374 specialization,
1375 speed,
3dfed10e 1376 spotlight,
f035d41b
XL
1377 sqrtf32,
1378 sqrtf64,
fc512014
XL
1379 sreg,
1380 sreg_low16,
5099ac24 1381 sse,
48663c56
XL
1382 sse4a_target_feature,
1383 stable,
1384 staged_api,
1385 start,
3dfed10e 1386 state,
48663c56 1387 static_in_const,
48663c56
XL
1388 static_nobundle,
1389 static_recursion,
3dfed10e 1390 staticlib,
48663c56 1391 std,
416331ca 1392 std_inject,
5869c6ff
XL
1393 std_panic,
1394 std_panic_2015_macro,
fc512014 1395 std_panic_macro,
dc9dc135 1396 stmt,
48663c56
XL
1397 stmt_expr_attributes,
1398 stop_after_dataflow,
94222f64 1399 store,
3dfed10e 1400 str,
5e7ed085
FG
1401 str_split_whitespace,
1402 str_trim,
1403 str_trim_end,
1404 str_trim_start,
04454e1e 1405 strict_provenance,
3dfed10e 1406 stringify,
5099ac24 1407 stringify_macro,
48663c56
XL
1408 struct_field_attributes,
1409 struct_inherit,
48663c56 1410 struct_variant,
3dfed10e
XL
1411 structural_match,
1412 structural_peq,
1413 structural_teq,
dc9dc135 1414 sty,
3dfed10e
XL
1415 sub,
1416 sub_assign,
60c5eb7d 1417 sub_with_overflow,
48663c56 1418 suggestion,
f9f354fc 1419 sym,
3dfed10e 1420 sync,
29967ef6 1421 t32,
923072b8 1422 target,
136023e0 1423 target_abi,
3dfed10e
XL
1424 target_arch,
1425 target_endian,
1426 target_env,
1427 target_family,
48663c56 1428 target_feature,
f9f354fc 1429 target_feature_11,
48663c56 1430 target_has_atomic,
1b1a35ee 1431 target_has_atomic_equal_alignment,
e74abb32 1432 target_has_atomic_load_store,
3dfed10e
XL
1433 target_os,
1434 target_pointer_width,
1435 target_target_vendor,
48663c56 1436 target_thread_local,
3dfed10e 1437 target_vendor,
48663c56
XL
1438 task,
1439 tbm_target_feature,
3dfed10e 1440 termination,
48663c56
XL
1441 termination_trait,
1442 termination_trait_test,
1443 test,
1444 test_2018_feature,
1445 test_accepted_feature,
dc9dc135 1446 test_case,
48663c56
XL
1447 test_removed_feature,
1448 test_runner,
5e7ed085 1449 test_unstable_lint,
dc9dc135 1450 then_with,
74b04a01 1451 thread,
48663c56 1452 thread_local,
5099ac24
FG
1453 thread_local_macro,
1454 thumb2,
1455 thumb_mode: "thumb-mode",
923072b8 1456 tmm_reg,
064997fb
FG
1457 to_string,
1458 to_vec,
5099ac24 1459 todo_macro,
48663c56
XL
1460 tool_attributes,
1461 tool_lints,
1462 trace_macros,
e74abb32 1463 track_caller,
48663c56 1464 trait_alias,
94222f64 1465 trait_upcasting,
48663c56 1466 transmute,
064997fb 1467 transmute_trait,
48663c56 1468 transparent,
dc9dc135
XL
1469 transparent_enums,
1470 transparent_unions,
48663c56 1471 trivial_bounds,
f035d41b
XL
1472 truncf32,
1473 truncf64,
48663c56 1474 try_blocks,
923072b8 1475 try_capture,
136023e0 1476 try_from,
136023e0 1477 try_into,
17df50a5 1478 try_trait_v2,
dc9dc135 1479 tt,
3dfed10e 1480 tuple,
29967ef6 1481 tuple_from_req,
48663c56 1482 tuple_indexing,
dfeec247 1483 two_phase,
48663c56
XL
1484 ty,
1485 type_alias_enum_variants,
3dfed10e 1486 type_alias_impl_trait,
48663c56 1487 type_ascription,
3c0e092e 1488 type_changing_struct_update,
3dfed10e 1489 type_id,
48663c56
XL
1490 type_length_limit,
1491 type_macros,
3dfed10e 1492 type_name,
48663c56
XL
1493 u128,
1494 u16,
1495 u32,
1496 u64,
1497 u8,
f035d41b
XL
1498 unaligned_volatile_load,
1499 unaligned_volatile_store,
48663c56 1500 unboxed_closures,
74b04a01
XL
1501 unchecked_add,
1502 unchecked_div,
1503 unchecked_mul,
1504 unchecked_rem,
60c5eb7d
XL
1505 unchecked_shl,
1506 unchecked_shr,
74b04a01 1507 unchecked_sub,
48663c56
XL
1508 underscore_const_names,
1509 underscore_imports,
1510 underscore_lifetimes,
1511 uniform_paths,
5099ac24 1512 unimplemented_macro,
3dfed10e 1513 unit,
48663c56 1514 universal_impl_trait,
3dfed10e 1515 unix,
f035d41b 1516 unlikely,
48663c56 1517 unmarked_api,
3dfed10e 1518 unpin,
f035d41b 1519 unreachable,
a2a8927a
XL
1520 unreachable_2015,
1521 unreachable_2015_macro,
1522 unreachable_2021,
1523 unreachable_2021_macro,
48663c56 1524 unreachable_code,
a2a8927a
XL
1525 unreachable_display,
1526 unreachable_macro,
48663c56 1527 unrestricted_attribute_tokens,
f9f354fc 1528 unsafe_block_in_unsafe_fn,
3dfed10e 1529 unsafe_cell,
48663c56 1530 unsafe_no_drop_flag,
5099ac24 1531 unsafe_pin_internals,
3dfed10e 1532 unsize,
29967ef6 1533 unsized_fn_params,
48663c56
XL
1534 unsized_locals,
1535 unsized_tuple_coercion,
1536 unstable,
064997fb
FG
1537 unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
1538 unstable location; did you mean to load this crate \
1539 from crates.io via `Cargo.toml` instead?",
48663c56 1540 untagged_unions,
923072b8 1541 unused_imports,
3dfed10e 1542 unused_qualifications,
48663c56
XL
1543 unwind,
1544 unwind_attributes,
136023e0 1545 unwind_safe_trait,
29967ef6 1546 unwrap,
dc9dc135 1547 unwrap_or,
48663c56
XL
1548 use_extern_macros,
1549 use_nested_groups,
3dfed10e 1550 used,
5099ac24 1551 used_with_arg,
064997fb 1552 using,
48663c56
XL
1553 usize,
1554 v1,
f035d41b
XL
1555 va_arg,
1556 va_copy,
1557 va_end,
3dfed10e 1558 va_list,
f035d41b 1559 va_start,
3dfed10e 1560 val,
5099ac24 1561 values,
3dfed10e
XL
1562 var,
1563 variant_count,
dc9dc135 1564 vec,
5099ac24 1565 vec_macro,
f9f354fc 1566 version,
5099ac24 1567 vfp2,
48663c56
XL
1568 vis,
1569 visible_private_types,
1570 volatile,
f035d41b
XL
1571 volatile_copy_memory,
1572 volatile_copy_nonoverlapping_memory,
1573 volatile_load,
1574 volatile_set_memory,
1575 volatile_store,
fc512014
XL
1576 vreg,
1577 vreg_low16,
064997fb
FG
1578 vtable_align,
1579 vtable_size,
48663c56 1580 warn,
cdc7bbd5 1581 wasm_abi,
48663c56
XL
1582 wasm_import_module,
1583 wasm_target_feature,
1584 while_let,
3dfed10e 1585 width,
48663c56
XL
1586 windows,
1587 windows_subsystem,
5099ac24 1588 with_negative_coherence,
60c5eb7d 1589 wrapping_add,
60c5eb7d 1590 wrapping_mul,
3dfed10e 1591 wrapping_sub,
17df50a5 1592 wreg,
f035d41b 1593 write_bytes,
5099ac24 1594 write_macro,
c295e0f8 1595 write_str,
5099ac24 1596 writeln_macro,
136023e0 1597 x87_reg,
94222f64 1598 xer,
fc512014 1599 xmm_reg,
04454e1e
FG
1600 yeet_desugar_details,
1601 yeet_expr,
fc512014
XL
1602 ymm_reg,
1603 zmm_reg,
48663c56
XL
1604 }
1605}
1606
3dfed10e 1607#[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)]
cc61c64b
XL
1608pub struct Ident {
1609 pub name: Symbol,
83c7162d 1610 pub span: Span,
cc61c64b
XL
1611}
1612
1613impl Ident {
83c7162d 1614 #[inline]
dc9dc135 1615 /// Constructs a new identifier from a symbol and a span.
83c7162d
XL
1616 pub const fn new(name: Symbol, span: Span) -> Ident {
1617 Ident { name, span }
1618 }
0731742a 1619
e1599b0c 1620 /// Constructs a new identifier with a dummy span.
83c7162d 1621 #[inline]
e1599b0c 1622 pub const fn with_dummy_span(name: Symbol) -> Ident {
83c7162d
XL
1623 Ident::new(name, DUMMY_SP)
1624 }
1625
dc9dc135 1626 #[inline]
3c0e092e 1627 pub fn empty() -> Ident {
5869c6ff 1628 Ident::with_dummy_span(kw::Empty)
dc9dc135
XL
1629 }
1630
e1599b0c 1631 /// Maps a string to an identifier with a dummy span.
cc61c64b 1632 pub fn from_str(string: &str) -> Ident {
e1599b0c 1633 Ident::with_dummy_span(Symbol::intern(string))
cc61c64b
XL
1634 }
1635
dc9dc135
XL
1636 /// Maps a string and a span to an identifier.
1637 pub fn from_str_and_span(string: &str, span: Span) -> Ident {
1638 Ident::new(Symbol::intern(string), span)
1639 }
1640
9fa01778 1641 /// Replaces `lo` and `hi` with those from `span`, but keep hygiene context.
83c7162d
XL
1642 pub fn with_span_pos(self, span: Span) -> Ident {
1643 Ident::new(self.name, span.with_ctxt(self.span.ctxt()))
1644 }
1645
1646 pub fn without_first_quote(self) -> Ident {
0731742a 1647 Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
ff7c6d11
XL
1648 }
1649
8faf50e0 1650 /// "Normalize" ident for use in comparisons using "item hygiene".
ba9703b0 1651 /// Identifiers with same string value become same if they came from the same macro 2.0 macro
0731742a 1652 /// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
ba9703b0 1653 /// different macro 2.0 macros.
8faf50e0 1654 /// Technically, this operation strips all non-opaque marks from ident's syntactic context.
ba9703b0
XL
1655 pub fn normalize_to_macros_2_0(self) -> Ident {
1656 Ident::new(self.name, self.span.normalize_to_macros_2_0())
83c7162d
XL
1657 }
1658
8faf50e0
XL
1659 /// "Normalize" ident for use in comparisons using "local variable hygiene".
1660 /// Identifiers with same string value become same if they came from the same non-transparent
0731742a 1661 /// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
8faf50e0
XL
1662 /// non-transparent macros.
1663 /// Technically, this operation strips all transparent marks from ident's syntactic context.
ba9703b0
XL
1664 pub fn normalize_to_macro_rules(self) -> Ident {
1665 Ident::new(self.name, self.span.normalize_to_macro_rules())
8faf50e0
XL
1666 }
1667
a2a8927a
XL
1668 /// Access the underlying string. This is a slowish operation because it
1669 /// requires locking the symbol interner.
1670 ///
1671 /// Note that the lifetime of the return value is a lie. See
1672 /// `Symbol::as_str()` for details.
1673 pub fn as_str(&self) -> &str {
94b46f34
XL
1674 self.name.as_str()
1675 }
83c7162d
XL
1676}
1677
1678impl PartialEq for Ident {
1679 fn eq(&self, rhs: &Self) -> bool {
923072b8 1680 self.name == rhs.name && self.span.eq_ctxt(rhs.span)
83c7162d
XL
1681 }
1682}
1683
1684impl Hash for Ident {
1685 fn hash<H: Hasher>(&self, state: &mut H) {
1686 self.name.hash(state);
1687 self.span.ctxt().hash(state);
cc61c64b
XL
1688 }
1689}
1690
1691impl fmt::Debug for Ident {
9fa01778 1692 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74b04a01
XL
1693 fmt::Display::fmt(self, f)?;
1694 fmt::Debug::fmt(&self.span.ctxt(), f)
cc61c64b
XL
1695 }
1696}
1697
74b04a01
XL
1698/// This implementation is supposed to be used in error messages, so it's expected to be identical
1699/// to printing the original identifier token written in source code (`token_to_string`),
1700/// except that AST identifiers don't keep the rawness flag, so we have to guess it.
cc61c64b 1701impl fmt::Display for Ident {
9fa01778 1702 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74b04a01 1703 fmt::Display::fmt(&IdentPrinter::new(self.name, self.is_raw_guess(), None), f)
cc61c64b
XL
1704 }
1705}
1706
74b04a01
XL
1707/// This is the most general way to print identifiers.
1708/// AST pretty-printer is used as a fallback for turning AST structures into token streams for
1709/// proc macros. Additionally, proc macros may stringify their input and expect it survive the
1710/// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30).
1711/// So we need to somehow pretty-print `$crate` in a way preserving at least some of its
1712/// hygiene data, most importantly name of the crate it refers to.
1713/// As a result we print `$crate` as `crate` if it refers to the local crate
1714/// and as `::other_crate_name` if it refers to some other crate.
5e7ed085 1715/// Note, that this is only done if the ident token is printed from inside of AST pretty-printing,
74b04a01
XL
1716/// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
1717/// so we should not perform this lossy conversion if the top level call to the pretty-printer was
1718/// done for a token stream or a single token.
1719pub struct IdentPrinter {
1720 symbol: Symbol,
1721 is_raw: bool,
1722 /// Span used for retrieving the crate name to which `$crate` refers to,
1723 /// if this field is `None` then the `$crate` conversion doesn't happen.
1724 convert_dollar_crate: Option<Span>,
1725}
1726
1727impl IdentPrinter {
1728 /// The most general `IdentPrinter` constructor. Do not use this.
1729 pub fn new(symbol: Symbol, is_raw: bool, convert_dollar_crate: Option<Span>) -> IdentPrinter {
1730 IdentPrinter { symbol, is_raw, convert_dollar_crate }
1731 }
1732
1733 /// This implementation is supposed to be used when printing identifiers
1734 /// as a part of pretty-printing for larger AST pieces.
1735 /// Do not use this either.
1736 pub fn for_ast_ident(ident: Ident, is_raw: bool) -> IdentPrinter {
1737 IdentPrinter::new(ident.name, is_raw, Some(ident.span))
1738 }
1739}
1740
1741impl fmt::Display for IdentPrinter {
1742 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1743 if self.is_raw {
1744 f.write_str("r#")?;
fc512014
XL
1745 } else if self.symbol == kw::DollarCrate {
1746 if let Some(span) = self.convert_dollar_crate {
1747 let converted = span.ctxt().dollar_crate_name();
1748 if !converted.is_path_segment_keyword() {
1749 f.write_str("::")?;
74b04a01 1750 }
fc512014 1751 return fmt::Display::fmt(&converted, f);
74b04a01
XL
1752 }
1753 }
1754 fmt::Display::fmt(&self.symbol, f)
1755 }
1756}
1757
ba9703b0
XL
1758/// An newtype around `Ident` that calls [Ident::normalize_to_macro_rules] on
1759/// construction.
1760// FIXME(matthewj, petrochenkov) Use this more often, add a similar
1761// `ModernIdent` struct and use that as well.
1762#[derive(Copy, Clone, Eq, PartialEq, Hash)]
1763pub struct MacroRulesNormalizedIdent(Ident);
1764
1765impl MacroRulesNormalizedIdent {
1766 pub fn new(ident: Ident) -> Self {
1767 Self(ident.normalize_to_macro_rules())
1768 }
1769}
1770
1771impl fmt::Debug for MacroRulesNormalizedIdent {
1772 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1773 fmt::Debug::fmt(&self.0, f)
1774 }
1775}
1776
1777impl fmt::Display for MacroRulesNormalizedIdent {
1778 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1779 fmt::Display::fmt(&self.0, f)
1780 }
1781}
1782
e74abb32 1783/// An interned string.
48663c56 1784///
e74abb32 1785/// Internally, a `Symbol` is implemented as an index, and all operations
48663c56 1786/// (including hashing, equality, and ordering) operate on that index. The use
e74abb32
XL
1787/// of `rustc_index::newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
1788/// because `rustc_index::newtype_index!` reserves the last 256 values for tagging purposes.
0731742a 1789///
e74abb32 1790/// Note that `Symbol` cannot directly be a `rustc_index::newtype_index!` because it
dc9dc135 1791/// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
476ff2be 1792#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
0731742a
XL
1793pub struct Symbol(SymbolIndex);
1794
e74abb32 1795rustc_index::newtype_index! {
c295e0f8 1796 struct SymbolIndex { .. }
0731742a 1797}
476ff2be 1798
476ff2be 1799impl Symbol {
0731742a 1800 const fn new(n: u32) -> Self {
ba9703b0 1801 Symbol(SymbolIndex::from_u32(n))
0731742a
XL
1802 }
1803
476ff2be
SL
1804 /// Maps a string to its interned representation.
1805 pub fn intern(string: &str) -> Self {
c295e0f8 1806 with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
476ff2be
SL
1807 }
1808
a2a8927a 1809 /// Access the underlying string. This is a slowish operation because it
60c5eb7d 1810 /// requires locking the symbol interner.
a2a8927a
XL
1811 ///
1812 /// Note that the lifetime of the return value is a lie. It's not the same
1813 /// as `&self`, but actually tied to the lifetime of the underlying
1814 /// interner. Interners are long-lived, and there are very few of them, and
1815 /// this function is typically used for short-lived things, so in practice
1816 /// it works out ok.
1817 pub fn as_str(&self) -> &str {
1818 with_session_globals(|session_globals| unsafe {
1819 std::mem::transmute::<&str, &str>(session_globals.symbol_interner.get(*self))
476ff2be
SL
1820 })
1821 }
1822
83c7162d 1823 pub fn as_u32(self) -> u32 {
0731742a 1824 self.0.as_u32()
ea8adc8c 1825 }
74b04a01 1826
fc512014 1827 pub fn is_empty(self) -> bool {
5869c6ff 1828 self == kw::Empty
fc512014
XL
1829 }
1830
74b04a01
XL
1831 /// This method is supposed to be used in error messages, so it's expected to be
1832 /// identical to printing the original identifier token written in source code
1833 /// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag
1834 /// or edition, so we have to guess the rawness using the global edition.
1835 pub fn to_ident_string(self) -> String {
1836 Ident::with_dummy_span(self).to_string()
1837 }
ea8adc8c
XL
1838}
1839
476ff2be 1840impl fmt::Debug for Symbol {
9fa01778 1841 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
a2a8927a 1842 fmt::Debug::fmt(self.as_str(), f)
476ff2be
SL
1843 }
1844}
1845
1846impl fmt::Display for Symbol {
9fa01778 1847 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
a2a8927a 1848 fmt::Display::fmt(self.as_str(), f)
476ff2be
SL
1849 }
1850}
1851
3dfed10e 1852impl<S: Encoder> Encodable<S> for Symbol {
923072b8
FG
1853 fn encode(&self, s: &mut S) {
1854 s.emit_str(self.as_str());
476ff2be
SL
1855 }
1856}
1857
3dfed10e 1858impl<D: Decoder> Decodable<D> for Symbol {
74b04a01 1859 #[inline]
5099ac24
FG
1860 fn decode(d: &mut D) -> Symbol {
1861 Symbol::intern(&d.read_str())
476ff2be
SL
1862 }
1863}
1864
60c5eb7d
XL
1865impl<CTX> HashStable<CTX> for Symbol {
1866 #[inline]
1867 fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
1868 self.as_str().hash_stable(hcx, hasher);
1869 }
1870}
1871
1872impl<CTX> ToStableHashKey<CTX> for Symbol {
a2a8927a 1873 type KeyType = String;
60c5eb7d 1874 #[inline]
a2a8927a
XL
1875 fn to_stable_hash_key(&self, _: &CTX) -> String {
1876 self.as_str().to_string()
60c5eb7d
XL
1877 }
1878}
1879
c295e0f8
XL
1880#[derive(Default)]
1881pub(crate) struct Interner(Lock<InternerInner>);
1882
0731742a 1883// The `&'static str`s in this type actually point into the arena.
3dfed10e
XL
1884//
1885// The `FxHashMap`+`Vec` pair could be replaced by `FxIndexSet`, but #75278
1886// found that to regress performance up to 2% in some cases. This might be
1887// revisited after further improvements to `indexmap`.
c295e0f8 1888//
a2a8927a 1889// This type is private to prevent accidentally constructing more than one
5e7ed085 1890// `Interner` on the same thread, which makes it easy to mix up `Symbol`s
a2a8927a 1891// between `Interner`s.
0bf4aa26 1892#[derive(Default)]
c295e0f8 1893struct InternerInner {
94b46f34
XL
1894 arena: DroplessArena,
1895 names: FxHashMap<&'static str, Symbol>,
1896 strings: Vec<&'static str>,
476ff2be
SL
1897}
1898
1899impl Interner {
dc9dc135 1900 fn prefill(init: &[&'static str]) -> Self {
c295e0f8 1901 Interner(Lock::new(InternerInner {
dc9dc135
XL
1902 strings: init.into(),
1903 names: init.iter().copied().zip((0..).map(Symbol::new)).collect(),
1904 ..Default::default()
c295e0f8 1905 }))
476ff2be
SL
1906 }
1907
74b04a01 1908 #[inline]
c295e0f8
XL
1909 fn intern(&self, string: &str) -> Symbol {
1910 let mut inner = self.0.lock();
1911 if let Some(&name) = inner.names.get(string) {
476ff2be
SL
1912 return name;
1913 }
1914
c295e0f8 1915 let name = Symbol::new(inner.strings.len() as u32);
94b46f34 1916
a2a8927a
XL
1917 // SAFETY: we convert from `&str` to `&[u8]`, clone it into the arena,
1918 // and immediately convert the clone back to `&[u8], all because there
1919 // is no `inner.arena.alloc_str()` method. This is clearly safe.
dfeec247 1920 let string: &str =
c295e0f8 1921 unsafe { str::from_utf8_unchecked(inner.arena.alloc_slice(string.as_bytes())) };
a2a8927a
XL
1922
1923 // SAFETY: we can extend the arena allocation to `'static` because we
1924 // only access these while the arena is still alive.
dfeec247 1925 let string: &'static str = unsafe { &*(string as *const str) };
c295e0f8 1926 inner.strings.push(string);
a2a8927a
XL
1927
1928 // This second hash table lookup can be avoided by using `RawEntryMut`,
1929 // but this code path isn't hot enough for it to be worth it. See
1930 // #91445 for details.
c295e0f8 1931 inner.names.insert(string, name);
476ff2be
SL
1932 name
1933 }
60c5eb7d 1934
48663c56
XL
1935 // Get the symbol as a string. `Symbol::as_str()` should be used in
1936 // preference to this function.
c295e0f8
XL
1937 fn get(&self, symbol: Symbol) -> &str {
1938 self.0.lock().strings[symbol.0.as_usize()]
476ff2be
SL
1939 }
1940}
1941
dc9dc135 1942// This module has a very short name because it's used a lot.
ba9703b0
XL
1943/// This module contains all the defined keyword `Symbol`s.
1944///
1945/// Given that `kw` is imported, use them like `kw::keyword_name`.
1946/// For example `kw::Loop` or `kw::Break`.
dc9dc135 1947pub mod kw {
fc512014 1948 pub use super::kw_generated::*;
48663c56
XL
1949}
1950
1951// This module has a very short name because it's used a lot.
ba9703b0
XL
1952/// This module contains all the defined non-keyword `Symbol`s.
1953///
1954/// Given that `sym` is imported, use them like `sym::symbol_name`.
1955/// For example `sym::rustfmt` or `sym::u8`.
48663c56
XL
1956pub mod sym {
1957 use super::Symbol;
dfeec247 1958 use std::convert::TryInto;
dc9dc135 1959
6a06907d 1960 #[doc(inline)]
fc512014 1961 pub use super::sym_generated::*;
74b04a01
XL
1962
1963 // Used from a macro in `librustc_feature/accepted.rs`
1964 pub use super::kw::MacroRules as macro_rules;
dc9dc135 1965
fc512014
XL
1966 /// Get the symbol for an integer.
1967 ///
1968 /// The first few non-negative integers each have a static symbol and therefore
1969 /// are fast.
dc9dc135
XL
1970 pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
1971 if let Result::Ok(idx) = n.try_into() {
fc512014
XL
1972 if idx < 10 {
1973 return Symbol::new(super::SYMBOL_DIGITS_BASE + idx as u32);
dc9dc135
XL
1974 }
1975 }
1976 Symbol::intern(&n.to_string())
1977 }
94b46f34
XL
1978}
1979
1980impl Symbol {
fc512014
XL
1981 fn is_special(self) -> bool {
1982 self <= kw::Underscore
1983 }
1984
1985 fn is_used_keyword_always(self) -> bool {
1986 self >= kw::As && self <= kw::While
0731742a
XL
1987 }
1988
fc512014
XL
1989 fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
1990 (self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018
dc9dc135
XL
1991 }
1992
fc512014
XL
1993 fn is_unused_keyword_always(self) -> bool {
1994 self >= kw::Abstract && self <= kw::Yield
1995 }
1996
1997 fn is_unused_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
1998 self == kw::Try && edition() >= Edition::Edition2018
1999 }
2000
2001 pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool {
2002 self.is_special()
2003 || self.is_used_keyword_always()
2004 || self.is_unused_keyword_always()
2005 || self.is_used_keyword_conditional(edition)
2006 || self.is_unused_keyword_conditional(edition)
dc9dc135
XL
2007 }
2008
2009 /// A keyword or reserved identifier that can be used as a path segment.
2010 pub fn is_path_segment_keyword(self) -> bool {
dfeec247
XL
2011 self == kw::Super
2012 || self == kw::SelfLower
2013 || self == kw::SelfUpper
2014 || self == kw::Crate
2015 || self == kw::PathRoot
2016 || self == kw::DollarCrate
dc9dc135
XL
2017 }
2018
e1599b0c
XL
2019 /// Returns `true` if the symbol is `true` or `false`.
2020 pub fn is_bool_lit(self) -> bool {
2021 self == kw::True || self == kw::False
2022 }
2023
fc512014 2024 /// Returns `true` if this symbol can be a raw identifier.
dc9dc135 2025 pub fn can_be_raw(self) -> bool {
5869c6ff 2026 self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
94b46f34
XL
2027 }
2028}
2029
2030impl Ident {
0731742a 2031 // Returns `true` for reserved identifiers used internally for elided lifetimes,
94b46f34
XL
2032 // unnamed method parameters, crate root module, error recovery etc.
2033 pub fn is_special(self) -> bool {
fc512014 2034 self.name.is_special()
94b46f34
XL
2035 }
2036
2037 /// Returns `true` if the token is a keyword used in the language.
2038 pub fn is_used_keyword(self) -> bool {
0731742a 2039 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
fc512014
XL
2040 self.name.is_used_keyword_always()
2041 || self.name.is_used_keyword_conditional(|| self.span.edition())
94b46f34
XL
2042 }
2043
2044 /// Returns `true` if the token is a keyword reserved for possible future use.
2045 pub fn is_unused_keyword(self) -> bool {
2046 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
fc512014
XL
2047 self.name.is_unused_keyword_always()
2048 || self.name.is_unused_keyword_conditional(|| self.span.edition())
94b46f34
XL
2049 }
2050
2051 /// Returns `true` if the token is either a special identifier or a keyword.
2052 pub fn is_reserved(self) -> bool {
fc512014
XL
2053 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
2054 self.name.is_reserved(|| self.span.edition())
94b46f34
XL
2055 }
2056
2057 /// A keyword or reserved identifier that can be used as a path segment.
2058 pub fn is_path_segment_keyword(self) -> bool {
dc9dc135 2059 self.name.is_path_segment_keyword()
532ac7d7
XL
2060 }
2061
2062 /// We see this identifier in a normal identifier position, like variable name or a type.
2063 /// How was it written originally? Did it use the raw form? Let's try to guess.
2064 pub fn is_raw_guess(self) -> bool {
dc9dc135 2065 self.name.can_be_raw() && self.is_reserved()
94b46f34 2066 }
476ff2be 2067}