symbol.rs - source (original) (raw)

rustc_span/

symbol.rs

1//! An "interner" is a data structure that associates values with usize tags and
2//! allows bidirectional lookup; i.e., given a value, one can easily find the
3//! type, and vice versa.
4
5use std::hash::{Hash, Hasher};
6use std::{fmt, str};
7
8use rustc_arena::DroplessArena;
9use rustc_data_structures::fx::FxIndexSet;
10use rustc_data_structures::stable_hasher::{
11    HashStable, StableCompare, StableHasher, ToStableHashKey,
12};
13use rustc_data_structures::sync::Lock;
14use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols};
15
16use crate::{DUMMY_SP, Edition, Span, with_session_globals};
17
18#[cfg(test)]
19mod tests;
20
21// The proc macro code for this is in `compiler/rustc_macros/src/symbols.rs`.
22symbols! {
23    // This list includes things that are definitely keywords (e.g. `if`),
24    // a few things that are definitely not keywords (e.g. the empty symbol,
25    // `{{root}}`) and things where there is disagreement between people and/or
26    // documents (such as the Rust Reference) about whether it is a keyword
27    // (e.g. `_`).
28    //
29    // If you modify this list, adjust any relevant `Symbol::{is,can_be}_*`
30    // predicates and `used_keywords`. Also consider adding new keywords to the
31    // `ui/parser/raw/raw-idents.rs` test.
32    Keywords {
33        // Special reserved identifiers used internally for elided lifetimes,
34        // unnamed method parameters, crate root module, error recovery etc.
35        // Matching predicates: `is_special`/`is_reserved`
36        //
37        // Notes about `kw::Empty`:
38        // - Its use can blur the lines between "empty symbol" and "no symbol".
39        //   Using `Option<Symbol>` is preferable, where possible, because that
40        //   is unambiguous.
41        // - For dummy symbols that are never used and absolutely must be
42        //   present, it's better to use `sym::dummy` than `kw::Empty`, because
43        //   it's clearer that it's intended as a dummy value, and more likely
44        //   to be detected if it accidentally does get used.
45        // tidy-alphabetical-start
46        DollarCrate:        "$crate",
47        Empty:              "",
48        PathRoot:           "{{root}}",
49        Underscore:         "_",
50        // tidy-alphabetical-end
51
52        // Keywords that are used in stable Rust.
53        // Matching predicates: `is_used_keyword_always`/`is_reserved`
54        // tidy-alphabetical-start
55        As:                 "as",
56        Break:              "break",
57        Const:              "const",
58        Continue:           "continue",
59        Crate:              "crate",
60        Else:               "else",
61        Enum:               "enum",
62        Extern:             "extern",
63        False:              "false",
64        Fn:                 "fn",
65        For:                "for",
66        If:                 "if",
67        Impl:               "impl",
68        In:                 "in",
69        Let:                "let",
70        Loop:               "loop",
71        Match:              "match",
72        Mod:                "mod",
73        Move:               "move",
74        Mut:                "mut",
75        Pub:                "pub",
76        Ref:                "ref",
77        Return:             "return",
78        SelfLower:          "self",
79        SelfUpper:          "Self",
80        Static:             "static",
81        Struct:             "struct",
82        Super:              "super",
83        Trait:              "trait",
84        True:               "true",
85        Type:               "type",
86        Unsafe:             "unsafe",
87        Use:                "use",
88        Where:              "where",
89        While:              "while",
90        // tidy-alphabetical-end
91
92        // Keywords that are used in unstable Rust or reserved for future use.
93        // Matching predicates: `is_unused_keyword_always`/`is_reserved`
94        // tidy-alphabetical-start
95        Abstract:           "abstract",
96        Become:             "become",
97        Box:                "box",
98        Do:                 "do",
99        Final:              "final",
100        Macro:              "macro",
101        Override:           "override",
102        Priv:               "priv",
103        Typeof:             "typeof",
104        Unsized:            "unsized",
105        Virtual:            "virtual",
106        Yield:              "yield",
107        // tidy-alphabetical-end
108
109        // Edition-specific keywords that are used in stable Rust.
110        // Matching predicates: `is_used_keyword_conditional`/`is_reserved` (if
111        // the edition suffices)
112        // tidy-alphabetical-start
113        Async:              "async", // >= 2018 Edition only
114        Await:              "await", // >= 2018 Edition only
115        Dyn:                "dyn", // >= 2018 Edition only
116        // tidy-alphabetical-end
117
118        // Edition-specific keywords that are used in unstable Rust or reserved for future use.
119        // Matching predicates: `is_unused_keyword_conditional`/`is_reserved` (if
120        // the edition suffices)
121        // tidy-alphabetical-start
122        Gen:                "gen", // >= 2024 Edition only
123        Try:                "try", // >= 2018 Edition only
124        // tidy-alphabetical-end
125
126        // "Lifetime keywords": regular keywords with a leading `'`.
127        // Matching predicates: none
128        // tidy-alphabetical-start
129        StaticLifetime:     "'static",
130        UnderscoreLifetime: "'_",
131        // tidy-alphabetical-end
132
133        // Weak keywords, have special meaning only in specific contexts.
134        // Matching predicates: `is_weak`
135        // tidy-alphabetical-start
136        Auto:               "auto",
137        Builtin:            "builtin",
138        Catch:              "catch",
139        ContractEnsures:    "contract_ensures",
140        ContractRequires:   "contract_requires",
141        Default:            "default",
142        MacroRules:         "macro_rules",
143        Raw:                "raw",
144        Reuse:              "reuse",
145        Safe:               "safe",
146        Union:              "union",
147        Yeet:               "yeet",
148        // tidy-alphabetical-end
149    }
150
151    // Pre-interned symbols that can be referred to with `rustc_span::sym::*`.
152    //
153    // The symbol is the stringified identifier unless otherwise specified, in
154    // which case the name should mention the non-identifier punctuation.
155    // E.g. `sym::proc_dash_macro` represents "proc-macro", and it shouldn't be
156    // called `sym::proc_macro` because then it's easy to mistakenly think it
157    // represents "proc_macro".
158    //
159    // As well as the symbols listed, there are symbols for the strings
160    // "0", "1", ..., "9", which are accessible via `sym::integer`.
161    //
162    // The proc macro will abort if symbols are not in alphabetical order (as
163    // defined by `impl Ord for str`) or if any symbols are duplicated. Vim
164    // users can sort the list by selecting it and executing the command
165    // `:'<,'>!LC_ALL=C sort`.
166    //
167    // There is currently no checking that all symbols are used; that would be
168    // nice to have.
169    Symbols {
170        Abi,
171        AcqRel,
172        Acquire,
173        Any,
174        Arc,
175        ArcWeak,
176        Argument,
177        ArrayIntoIter,
178        AsMut,
179        AsRef,
180        AssertParamIsClone,
181        AssertParamIsCopy,
182        AssertParamIsEq,
183        AsyncGenFinished,
184        AsyncGenPending,
185        AsyncGenReady,
186        AtomicBool,
187        AtomicI128,
188        AtomicI16,
189        AtomicI32,
190        AtomicI64,
191        AtomicI8,
192        AtomicIsize,
193        AtomicPtr,
194        AtomicU128,
195        AtomicU16,
196        AtomicU32,
197        AtomicU64,
198        AtomicU8,
199        AtomicUsize,
200        BTreeEntry,
201        BTreeMap,
202        BTreeSet,
203        BinaryHeap,
204        Borrow,
205        BorrowMut,
206        Break,
207        C,
208        CStr,
209        C_dash_unwind: "C-unwind",
210        CallOnceFuture,
211        CallRefFuture,
212        Capture,
213        Cell,
214        Center,
215        Child,
216        Cleanup,
217        Clone,
218        CoercePointee,
219        CoercePointeeValidated,
220        CoerceUnsized,
221        Command,
222        ConstParamTy,
223        ConstParamTy_,
224        Context,
225        Continue,
226        ControlFlow,
227        Copy,
228        Cow,
229        Debug,
230        DebugStruct,
231        Decodable,
232        Decoder,
233        Default,
234        Deref,
235        DiagMessage,
236        Diagnostic,
237        DirBuilder,
238        DispatchFromDyn,
239        Display,
240        DoubleEndedIterator,
241        Duration,
242        Encodable,
243        Encoder,
244        Enumerate,
245        Eq,
246        Equal,
247        Err,
248        Error,
249        File,
250        FileType,
251        FmtArgumentsNew,
252        Fn,
253        FnMut,
254        FnOnce,
255        Formatter,
256        From,
257        FromIterator,
258        FromResidual,
259        FsOpenOptions,
260        FsPermissions,
261        FusedIterator,
262        Future,
263        GlobalAlloc,
264        Hash,
265        HashMap,
266        HashMapEntry,
267        HashSet,
268        Hasher,
269        Implied,
270        InCleanup,
271        IndexOutput,
272        Input,
273        Instant,
274        Into,
275        IntoFuture,
276        IntoIterator,
277        IoBufRead,
278        IoLines,
279        IoRead,
280        IoSeek,
281        IoWrite,
282        IpAddr,
283        IrTyKind,
284        Is,
285        Item,
286        ItemContext,
287        IterEmpty,
288        IterOnce,
289        IterPeekable,
290        Iterator,
291        IteratorItem,
292        Layout,
293        Left,
294        LinkedList,
295        LintDiagnostic,
296        LintPass,
297        LocalKey,
298        Mutex,
299        MutexGuard,
300        N,
301        NonNull,
302        NonZero,
303        None,
304        Normal,
305        Ok,
306        Option,
307        Ord,
308        Ordering,
309        OsStr,
310        OsString,
311        Output,
312        Param,
313        ParamSet,
314        PartialEq,
315        PartialOrd,
316        Path,
317        PathBuf,
318        Pending,
319        PinCoerceUnsized,
320        Pointer,
321        Poll,
322        ProcMacro,
323        ProceduralMasqueradeDummyType,
324        Range,
325        RangeBounds,
326        RangeCopy,
327        RangeFrom,
328        RangeFromCopy,
329        RangeFull,
330        RangeInclusive,
331        RangeInclusiveCopy,
332        RangeMax,
333        RangeMin,
334        RangeSub,
335        RangeTo,
336        RangeToInclusive,
337        Rc,
338        RcWeak,
339        Ready,
340        Receiver,
341        RefCell,
342        RefCellRef,
343        RefCellRefMut,
344        Relaxed,
345        Release,
346        Result,
347        ResumeTy,
348        Return,
349        Right,
350        Rust,
351        RustaceansAreAwesome,
352        RwLock,
353        RwLockReadGuard,
354        RwLockWriteGuard,
355        Saturating,
356        SeekFrom,
357        SelfTy,
358        Send,
359        SeqCst,
360        Sized,
361        SliceIndex,
362        SliceIter,
363        Some,
364        SpanCtxt,
365        Stdin,
366        String,
367        StructuralPartialEq,
368        SubdiagMessage,
369        Subdiagnostic,
370        SymbolIntern,
371        Sync,
372        SyncUnsafeCell,
373        T,
374        Target,
375        This,
376        ToOwned,
377        ToString,
378        TokenStream,
379        Trait,
380        Try,
381        TryCaptureGeneric,
382        TryCapturePrintable,
383        TryFrom,
384        TryInto,
385        Ty,
386        TyCtxt,
387        TyKind,
388        Unknown,
389        Unsize,
390        UnsizedConstParamTy,
391        Upvars,
392        Vec,
393        VecDeque,
394        Waker,
395        Wrapper,
396        Wrapping,
397        Yield,
398        _DECLS,
399        _Self,
400        __D,
401        __H,
402        __S,
403        __awaitee,
404        __try_var,
405        _d,
406        _e,
407        _task_context,
408        a32,
409        aarch64_target_feature,
410        aarch64_unstable_target_feature,
411        aarch64_ver_target_feature,
412        abi,
413        abi_amdgpu_kernel,
414        abi_avr_interrupt,
415        abi_c_cmse_nonsecure_call,
416        abi_efiapi,
417        abi_gpu_kernel,
418        abi_msp430_interrupt,
419        abi_ptx,
420        abi_riscv_interrupt,
421        abi_sysv64,
422        abi_thiscall,
423        abi_unadjusted,
424        abi_vectorcall,
425        abi_x86_interrupt,
426        abort,
427        add,
428        add_assign,
429        add_with_overflow,
430        address,
431        adt_const_params,
432        advanced_slice_patterns,
433        adx_target_feature,
434        aes,
435        aggregate_raw_ptr,
436        alias,
437        align,
438        alignment,
439        all,
440        alloc,
441        alloc_error_handler,
442        alloc_layout,
443        alloc_zeroed,
444        allocator,
445        allocator_api,
446        allocator_internals,
447        allow,
448        allow_fail,
449        allow_internal_unsafe,
450        allow_internal_unstable,
451        altivec,
452        alu32,
453        always,
454        and,
455        and_then,
456        anon,
457        anon_adt,
458        anon_assoc,
459        anonymous_lifetime_in_impl_trait,
460        any,
461        append_const_msg,
462        arbitrary_enum_discriminant,
463        arbitrary_self_types,
464        arbitrary_self_types_pointers,
465        areg,
466        args,
467        arith_offset,
468        arm,
469        arm_target_feature,
470        array,
471        as_ptr,
472        as_ref,
473        as_str,
474        asm,
475        asm_const,
476        asm_experimental_arch,
477        asm_experimental_reg,
478        asm_goto,
479        asm_goto_with_outputs,
480        asm_sym,
481        asm_unwind,
482        assert,
483        assert_eq,
484        assert_eq_macro,
485        assert_inhabited,
486        assert_macro,
487        assert_mem_uninitialized_valid,
488        assert_ne_macro,
489        assert_receiver_is_total_eq,
490        assert_zero_valid,
491        asserting,
492        associated_const_equality,
493        associated_consts,
494        associated_type_bounds,
495        associated_type_defaults,
496        associated_types,
497        assume,
498        assume_init,
499        asterisk: "*",
500        async_await,
501        async_call,
502        async_call_mut,
503        async_call_once,
504        async_closure,
505        async_drop,
506        async_drop_in_place,
507        async_fn,
508        async_fn_in_dyn_trait,
509        async_fn_in_trait,
510        async_fn_kind_helper,
511        async_fn_kind_upvars,
512        async_fn_mut,
513        async_fn_once,
514        async_fn_once_output,
515        async_fn_track_caller,
516        async_fn_traits,
517        async_for_loop,
518        async_iterator,
519        async_iterator_poll_next,
520        async_trait_bounds,
521        atomic,
522        atomic_mod,
523        atomics,
524        att_syntax,
525        attr,
526        attr_literals,
527        attributes,
528        audit_that,
529        augmented_assignments,
530        auto_traits,
531        autodiff,
532        automatically_derived,
533        avx,
534        avx10_target_feature,
535        avx512_target_feature,
536        avx512bw,
537        avx512f,
538        await_macro,
539        bang,
540        begin_panic,
541        bench,
542        bevy_ecs,
543        bikeshed_guaranteed_no_drop,
544        bin,
545        binaryheap_iter,
546        bind_by_move_pattern_guards,
547        bindings_after_at,
548        bitand,
549        bitand_assign,
550        bitor,
551        bitor_assign,
552        bitreverse,
553        bitxor,
554        bitxor_assign,
555        black_box,
556        block,
557        bool,
558        bool_then,
559        borrowck_graphviz_format,
560        borrowck_graphviz_postflow,
561        box_new,
562        box_patterns,
563        box_syntax,
564        bpf_target_feature,
565        braced_empty_structs,
566        branch,
567        breakpoint,
568        bridge,
569        bswap,
570        btreemap_contains_key,
571        btreemap_insert,
572        btreeset_iter,
573        builtin_syntax,
574        c,
575        c_dash_variadic,
576        c_str,
577        c_str_literals,
578        c_unwind,
579        c_variadic,
580        c_void,
581        call,
582        call_mut,
583        call_once,
584        call_once_future,
585        call_ref_future,
586        caller_location,
587        capture_disjoint_fields,
588        carrying_mul_add,
589        catch_unwind,
590        cause,
591        cdylib,
592        ceilf128,
593        ceilf16,
594        ceilf32,
595        ceilf64,
596        cfg,
597        cfg_accessible,
598        cfg_attr,
599        cfg_attr_multi,
600        cfg_attr_trace: "<cfg_attr>", // must not be a valid identifier
601        cfg_boolean_literals,
602        cfg_contract_checks,
603        cfg_doctest,
604        cfg_emscripten_wasm_eh,
605        cfg_eval,
606        cfg_fmt_debug,
607        cfg_hide,
608        cfg_overflow_checks,
609        cfg_panic,
610        cfg_relocation_model,
611        cfg_sanitize,
612        cfg_sanitizer_cfi,
613        cfg_target_abi,
614        cfg_target_compact,
615        cfg_target_feature,
616        cfg_target_has_atomic,
617        cfg_target_has_atomic_equal_alignment,
618        cfg_target_has_reliable_f16_f128,
619        cfg_target_thread_local,
620        cfg_target_vendor,
621        cfg_trace: "<cfg>", // must not be a valid identifier
622        cfg_ub_checks,
623        cfg_version,
624        cfi,
625        cfi_encoding,
626        char,
627        char_is_ascii,
628        child_id,
629        child_kill,
630        client,
631        clippy,
632        clobber_abi,
633        clone,
634        clone_closures,
635        clone_fn,
636        clone_from,
637        closure,
638        closure_lifetime_binder,
639        closure_to_fn_coercion,
640        closure_track_caller,
641        cmp,
642        cmp_max,
643        cmp_min,
644        cmp_ord_max,
645        cmp_ord_min,
646        cmp_partialeq_eq,
647        cmp_partialeq_ne,
648        cmp_partialord_cmp,
649        cmp_partialord_ge,
650        cmp_partialord_gt,
651        cmp_partialord_le,
652        cmp_partialord_lt,
653        cmpxchg16b_target_feature,
654        cmse_nonsecure_entry,
655        coerce_pointee_validated,
656        coerce_unsized,
657        cold,
658        cold_path,
659        collapse_debuginfo,
660        column,
661        compare_bytes,
662        compare_exchange,
663        compare_exchange_weak,
664        compile_error,
665        compiler,
666        compiler_builtins,
667        compiler_fence,
668        concat,
669        concat_bytes,
670        concat_idents,
671        conservative_impl_trait,
672        console,
673        const_allocate,
674        const_async_blocks,
675        const_closures,
676        const_compare_raw_pointers,
677        const_constructor,
678        const_deallocate,
679        const_destruct,
680        const_eval_limit,
681        const_eval_select,
682        const_evaluatable_checked,
683        const_extern_fn,
684        const_fn,
685        const_fn_floating_point_arithmetic,
686        const_fn_fn_ptr_basics,
687        const_fn_trait_bound,
688        const_fn_transmute,
689        const_fn_union,
690        const_fn_unsize,
691        const_for,
692        const_format_args,
693        const_generics,
694        const_generics_defaults,
695        const_if_match,
696        const_impl_trait,
697        const_in_array_repeat_expressions,
698        const_indexing,
699        const_let,
700        const_loop,
701        const_mut_refs,
702        const_panic,
703        const_panic_fmt,
704        const_param_ty,
705        const_precise_live_drops,
706        const_ptr_cast,
707        const_raw_ptr_deref,
708        const_raw_ptr_to_usize_cast,
709        const_refs_to_cell,
710        const_refs_to_static,
711        const_trait,
712        const_trait_bound_opt_out,
713        const_trait_impl,
714        const_try,
715        const_ty_placeholder: "<const_ty>",
716        constant,
717        constructor,
718        contract_build_check_ensures,
719        contract_check_ensures,
720        contract_check_requires,
721        contract_checks,
722        contracts,
723        contracts_ensures,
724        contracts_internals,
725        contracts_requires,
726        convert_identity,
727        copy,
728        copy_closures,
729        copy_nonoverlapping,
730        copysignf128,
731        copysignf16,
732        copysignf32,
733        copysignf64,
734        core,
735        core_panic,
736        core_panic_2015_macro,
737        core_panic_2021_macro,
738        core_panic_macro,
739        coroutine,
740        coroutine_clone,
741        coroutine_resume,
742        coroutine_return,
743        coroutine_state,
744        coroutine_yield,
745        coroutines,
746        cosf128,
747        cosf16,
748        cosf32,
749        cosf64,
750        count,
751        coverage,
752        coverage_attribute,
753        cr,
754        crate_in_paths,
755        crate_local,
756        crate_name,
757        crate_type,
758        crate_visibility_modifier,
759        crt_dash_static: "crt-static",
760        csky_target_feature,
761        cstr_type,
762        cstring_as_c_str,
763        cstring_type,
764        ctlz,
765        ctlz_nonzero,
766        ctpop,
767        cttz,
768        cttz_nonzero,
769        custom_attribute,
770        custom_code_classes_in_docs,
771        custom_derive,
772        custom_inner_attributes,
773        custom_mir,
774        custom_test_frameworks,
775        d,
776        d32,
777        dbg_macro,
778        dead_code,
779        dealloc,
780        debug,
781        debug_assert_eq_macro,
782        debug_assert_macro,
783        debug_assert_ne_macro,
784        debug_assertions,
785        debug_struct,
786        debug_struct_fields_finish,
787        debug_tuple,
788        debug_tuple_fields_finish,
789        debugger_visualizer,
790        decl_macro,
791        declare_lint_pass,
792        decode,
793        default_alloc_error_handler,
794        default_field_values,
795        default_fn,
796        default_lib_allocator,
797        default_method_body_is_const,
798        // --------------------------
799        // Lang items which are used only for experiments with auto traits with default bounds.
800        // These lang items are not actually defined in core/std. Experiment is a part of
801        // `MCP: Low level components for async drop`(https://github.com/rust-lang/compiler-team/issues/727)
802        default_trait1,
803        default_trait2,
804        default_trait3,
805        default_trait4,
806        // --------------------------
807        default_type_parameter_fallback,
808        default_type_params,
809        define_opaque,
810        delayed_bug_from_inside_query,
811        deny,
812        deprecated,
813        deprecated_safe,
814        deprecated_suggestion,
815        deref,
816        deref_method,
817        deref_mut,
818        deref_mut_method,
819        deref_patterns,
820        deref_pure,
821        deref_target,
822        derive,
823        derive_coerce_pointee,
824        derive_const,
825        derive_default_enum,
826        derive_smart_pointer,
827        destruct,
828        destructuring_assignment,
829        diagnostic,
830        diagnostic_namespace,
831        direct,
832        discriminant_kind,
833        discriminant_type,
834        discriminant_value,
835        disjoint_bitor,
836        dispatch_from_dyn,
837        div,
838        div_assign,
839        diverging_block_default,
840        do_not_recommend,
841        doc,
842        doc_alias,
843        doc_auto_cfg,
844        doc_cfg,
845        doc_cfg_hide,
846        doc_keyword,
847        doc_masked,
848        doc_notable_trait,
849        doc_primitive,
850        doc_spotlight,
851        doctest,
852        document_private_items,
853        dotdot: "..",
854        dotdot_in_tuple_patterns,
855        dotdoteq_in_patterns,
856        dreg,
857        dreg_low16,
858        dreg_low8,
859        drop,
860        drop_in_place,
861        drop_types_in_const,
862        dropck_eyepatch,
863        dropck_parametricity,
864        dummy: "<!dummy!>", // use this instead of `kw::Empty` for symbols that won't be used
865        dummy_cgu_name,
866        dylib,
867        dyn_compatible_for_dispatch,
868        dyn_metadata,
869        dyn_star,
870        dyn_trait,
871        dynamic_no_pic: "dynamic-no-pic",
872        e,
873        edition_panic,
874        effects,
875        eh_catch_typeinfo,
876        eh_personality,
877        emit,
878        emit_enum,
879        emit_enum_variant,
880        emit_enum_variant_arg,
881        emit_struct,
882        emit_struct_field,
883        emscripten_wasm_eh,
884        enable,
885        encode,
886        end,
887        entry_nops,
888        enumerate_method,
889        env,
890        env_CFG_RELEASE: env!("CFG_RELEASE"),
891        eprint_macro,
892        eprintln_macro,
893        eq,
894        ergonomic_clones,
895        ermsb_target_feature,
896        exact_div,
897        except,
898        exchange_malloc,
899        exclusive_range_pattern,
900        exhaustive_integer_patterns,
901        exhaustive_patterns,
902        existential_type,
903        exp2f128,
904        exp2f16,
905        exp2f32,
906        exp2f64,
907        expect,
908        expected,
909        expf128,
910        expf16,
911        expf32,
912        expf64,
913        explicit_extern_abis,
914        explicit_generic_args_with_impl_trait,
915        explicit_tail_calls,
916        export_name,
917        export_stable,
918        expr,
919        expr_2021,
920        expr_fragment_specifier_2024,
921        extended_key_value_attributes,
922        extended_varargs_abi_support,
923        extern_absolute_paths,
924        extern_crate_item_prelude,
925        extern_crate_self,
926        extern_in_paths,
927        extern_prelude,
928        extern_system_varargs,
929        extern_types,
930        external,
931        external_doc,
932        f,
933        f128,
934        f128_nan,
935        f16,
936        f16_nan,
937        f16c_target_feature,
938        f32,
939        f32_epsilon,
940        f32_legacy_const_digits,
941        f32_legacy_const_epsilon,
942        f32_legacy_const_infinity,
943        f32_legacy_const_mantissa_dig,
944        f32_legacy_const_max,
945        f32_legacy_const_max_10_exp,
946        f32_legacy_const_max_exp,
947        f32_legacy_const_min,
948        f32_legacy_const_min_10_exp,
949        f32_legacy_const_min_exp,
950        f32_legacy_const_min_positive,
951        f32_legacy_const_nan,
952        f32_legacy_const_neg_infinity,
953        f32_legacy_const_radix,
954        f32_nan,
955        f64,
956        f64_epsilon,
957        f64_legacy_const_digits,
958        f64_legacy_const_epsilon,
959        f64_legacy_const_infinity,
960        f64_legacy_const_mantissa_dig,
961        f64_legacy_const_max,
962        f64_legacy_const_max_10_exp,
963        f64_legacy_const_max_exp,
964        f64_legacy_const_min,
965        f64_legacy_const_min_10_exp,
966        f64_legacy_const_min_exp,
967        f64_legacy_const_min_positive,
968        f64_legacy_const_nan,
969        f64_legacy_const_neg_infinity,
970        f64_legacy_const_radix,
971        f64_nan,
972        fabsf128,
973        fabsf16,
974        fabsf32,
975        fabsf64,
976        fadd_algebraic,
977        fadd_fast,
978        fake_variadic,
979        fallback,
980        fdiv_algebraic,
981        fdiv_fast,
982        feature,
983        fence,
984        ferris: "🦀",
985        fetch_update,
986        ffi,
987        ffi_const,
988        ffi_pure,
989        ffi_returns_twice,
990        field,
991        field_init_shorthand,
992        file,
993        file_options,
994        flags,
995        float,
996        float_to_int_unchecked,
997        floorf128,
998        floorf16,
999        floorf32,
1000        floorf64,
1001        fmaf128,
1002        fmaf16,
1003        fmaf32,
1004        fmaf64,
1005        fmt,
1006        fmt_debug,
1007        fmul_algebraic,
1008        fmul_fast,
1009        fmuladdf128,
1010        fmuladdf16,
1011        fmuladdf32,
1012        fmuladdf64,
1013        fn_align,
1014        fn_body,
1015        fn_delegation,
1016        fn_must_use,
1017        fn_mut,
1018        fn_once,
1019        fn_once_output,
1020        fn_ptr_addr,
1021        fn_ptr_trait,
1022        forbid,
1023        forget,
1024        format,
1025        format_args,
1026        format_args_capture,
1027        format_args_macro,
1028        format_args_nl,
1029        format_argument,
1030        format_arguments,
1031        format_count,
1032        format_macro,
1033        format_placeholder,
1034        format_unsafe_arg,
1035        freeze,
1036        freeze_impls,
1037        freg,
1038        frem_algebraic,
1039        frem_fast,
1040        from,
1041        from_desugaring,
1042        from_fn,
1043        from_iter,
1044        from_iter_fn,
1045        from_output,
1046        from_residual,
1047        from_size_align_unchecked,
1048        from_str_method,
1049        from_u16,
1050        from_usize,
1051        from_yeet,
1052        frontmatter,
1053        fs_create_dir,
1054        fsub_algebraic,
1055        fsub_fast,
1056        fsxr,
1057        full,
1058        fundamental,
1059        fused_iterator,
1060        future,
1061        future_drop_poll,
1062        future_output,
1063        future_trait,
1064        gdb_script_file,
1065        ge,
1066        gen_blocks,
1067        gen_future,
1068        generator_clone,
1069        generators,
1070        generic_arg_infer,
1071        generic_assert,
1072        generic_associated_types,
1073        generic_associated_types_extended,
1074        generic_const_exprs,
1075        generic_const_items,
1076        generic_const_parameter_types,
1077        generic_param_attrs,
1078        generic_pattern_types,
1079        get_context,
1080        global_alloc_ty,
1081        global_allocator,
1082        global_asm,
1083        global_registration,
1084        globs,
1085        gt,
1086        guard_patterns,
1087        half_open_range_patterns,
1088        half_open_range_patterns_in_slices,
1089        hash,
1090        hashmap_contains_key,
1091        hashmap_drain_ty,
1092        hashmap_insert,
1093        hashmap_iter_mut_ty,
1094        hashmap_iter_ty,
1095        hashmap_keys_ty,
1096        hashmap_values_mut_ty,
1097        hashmap_values_ty,
1098        hashset_drain_ty,
1099        hashset_iter,
1100        hashset_iter_ty,
1101        hexagon_target_feature,
1102        hidden,
1103        hint,
1104        homogeneous_aggregate,
1105        host,
1106        html_favicon_url,
1107        html_logo_url,
1108        html_no_source,
1109        html_playground_url,
1110        html_root_url,
1111        hwaddress,
1112        i,
1113        i128,
1114        i128_legacy_const_max,
1115        i128_legacy_const_min,
1116        i128_legacy_fn_max_value,
1117        i128_legacy_fn_min_value,
1118        i128_legacy_mod,
1119        i128_type,
1120        i16,
1121        i16_legacy_const_max,
1122        i16_legacy_const_min,
1123        i16_legacy_fn_max_value,
1124        i16_legacy_fn_min_value,
1125        i16_legacy_mod,
1126        i32,
1127        i32_legacy_const_max,
1128        i32_legacy_const_min,
1129        i32_legacy_fn_max_value,
1130        i32_legacy_fn_min_value,
1131        i32_legacy_mod,
1132        i64,
1133        i64_legacy_const_max,
1134        i64_legacy_const_min,
1135        i64_legacy_fn_max_value,
1136        i64_legacy_fn_min_value,
1137        i64_legacy_mod,
1138        i8,
1139        i8_legacy_const_max,
1140        i8_legacy_const_min,
1141        i8_legacy_fn_max_value,
1142        i8_legacy_fn_min_value,
1143        i8_legacy_mod,
1144        ident,
1145        if_let,
1146        if_let_guard,
1147        if_let_rescope,
1148        if_while_or_patterns,
1149        ignore,
1150        impl_header_lifetime_elision,
1151        impl_lint_pass,
1152        impl_trait_in_assoc_type,
1153        impl_trait_in_bindings,
1154        impl_trait_in_fn_trait_return,
1155        impl_trait_projections,
1156        implement_via_object,
1157        implied_by,
1158        import,
1159        import_name_type,
1160        import_shadowing,
1161        import_trait_associated_functions,
1162        imported_main,
1163        in_band_lifetimes,
1164        include,
1165        include_bytes,
1166        include_bytes_macro,
1167        include_str,
1168        include_str_macro,
1169        inclusive_range_syntax,
1170        index,
1171        index_mut,
1172        infer_outlives_requirements,
1173        infer_static_outlives_requirements,
1174        inherent_associated_types,
1175        inherit,
1176        inlateout,
1177        inline,
1178        inline_const,
1179        inline_const_pat,
1180        inout,
1181        instant_now,
1182        instruction_set,
1183        integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
1184        integral,
1185        internal_features,
1186        into_async_iter_into_iter,
1187        into_future,
1188        into_iter,
1189        intra_doc_pointers,
1190        intrinsics,
1191        intrinsics_unaligned_volatile_load,
1192        intrinsics_unaligned_volatile_store,
1193        io_stderr,
1194        io_stdout,
1195        irrefutable_let_patterns,
1196        is,
1197        is_val_statically_known,
1198        isa_attribute,
1199        isize,
1200        isize_legacy_const_max,
1201        isize_legacy_const_min,
1202        isize_legacy_fn_max_value,
1203        isize_legacy_fn_min_value,
1204        isize_legacy_mod,
1205        issue,
1206        issue_5723_bootstrap,
1207        issue_tracker_base_url,
1208        item,
1209        item_like_imports,
1210        iter,
1211        iter_cloned,
1212        iter_copied,
1213        iter_filter,
1214        iter_mut,
1215        iter_repeat,
1216        iterator,
1217        iterator_collect_fn,
1218        kcfi,
1219        keylocker_x86,
1220        keyword,
1221        kind,
1222        kreg,
1223        kreg0,
1224        label,
1225        label_break_value,
1226        lahfsahf_target_feature,
1227        lang,
1228        lang_items,
1229        large_assignments,
1230        lateout,
1231        lazy_normalization_consts,
1232        lazy_type_alias,
1233        le,
1234        legacy_receiver,
1235        len,
1236        let_chains,
1237        let_else,
1238        lhs,
1239        lib,
1240        libc,
1241        lifetime,
1242        lifetime_capture_rules_2024,
1243        lifetimes,
1244        likely,
1245        line,
1246        link,
1247        link_arg_attribute,
1248        link_args,
1249        link_cfg,
1250        link_llvm_intrinsics,
1251        link_name,
1252        link_ordinal,
1253        link_section,
1254        linkage,
1255        linker,
1256        linker_messages,
1257        lint_reasons,
1258        literal,
1259        load,
1260        loaded_from_disk,
1261        local,
1262        local_inner_macros,
1263        log10f128,
1264        log10f16,
1265        log10f32,
1266        log10f64,
1267        log2f128,
1268        log2f16,
1269        log2f32,
1270        log2f64,
1271        log_syntax,
1272        logf128,
1273        logf16,
1274        logf32,
1275        logf64,
1276        loongarch_target_feature,
1277        loop_break_value,
1278        lt,
1279        m68k_target_feature,
1280        macro_at_most_once_rep,
1281        macro_attributes_in_derive_output,
1282        macro_escape,
1283        macro_export,
1284        macro_lifetime_matcher,
1285        macro_literal_matcher,
1286        macro_metavar_expr,
1287        macro_metavar_expr_concat,
1288        macro_reexport,
1289        macro_use,
1290        macro_vis_matcher,
1291        macros_in_extern,
1292        main,
1293        managed_boxes,
1294        manually_drop,
1295        map,
1296        map_err,
1297        marker,
1298        marker_trait_attr,
1299        masked,
1300        match_beginning_vert,
1301        match_default_bindings,
1302        matches_macro,
1303        maxnumf128,
1304        maxnumf16,
1305        maxnumf32,
1306        maxnumf64,
1307        may_dangle,
1308        may_unwind,
1309        maybe_uninit,
1310        maybe_uninit_uninit,
1311        maybe_uninit_zeroed,
1312        mem_discriminant,
1313        mem_drop,
1314        mem_forget,
1315        mem_replace,
1316        mem_size_of,
1317        mem_size_of_val,
1318        mem_swap,
1319        mem_uninitialized,
1320        mem_variant_count,
1321        mem_zeroed,
1322        member_constraints,
1323        memory,
1324        memtag,
1325        message,
1326        meta,
1327        metadata_type,
1328        min_align_of,
1329        min_align_of_val,
1330        min_const_fn,
1331        min_const_generics,
1332        min_const_unsafe_fn,
1333        min_exhaustive_patterns,
1334        min_generic_const_args,
1335        min_specialization,
1336        min_type_alias_impl_trait,
1337        minnumf128,
1338        minnumf16,
1339        minnumf32,
1340        minnumf64,
1341        mips_target_feature,
1342        mir_assume,
1343        mir_basic_block,
1344        mir_call,
1345        mir_cast_ptr_to_ptr,
1346        mir_cast_transmute,
1347        mir_checked,
1348        mir_copy_for_deref,
1349        mir_debuginfo,
1350        mir_deinit,
1351        mir_discriminant,
1352        mir_drop,
1353        mir_field,
1354        mir_goto,
1355        mir_len,
1356        mir_make_place,
1357        mir_move,
1358        mir_offset,
1359        mir_ptr_metadata,
1360        mir_retag,
1361        mir_return,
1362        mir_return_to,
1363        mir_set_discriminant,
1364        mir_static,
1365        mir_static_mut,
1366        mir_storage_dead,
1367        mir_storage_live,
1368        mir_tail_call,
1369        mir_unreachable,
1370        mir_unwind_cleanup,
1371        mir_unwind_continue,
1372        mir_unwind_resume,
1373        mir_unwind_terminate,
1374        mir_unwind_terminate_reason,
1375        mir_unwind_unreachable,
1376        mir_variant,
1377        miri,
1378        mmx_reg,
1379        modifiers,
1380        module,
1381        module_path,
1382        more_maybe_bounds,
1383        more_qualified_paths,
1384        more_struct_aliases,
1385        movbe_target_feature,
1386        move_ref_pattern,
1387        move_size_limit,
1388        movrs_target_feature,
1389        mul,
1390        mul_assign,
1391        mul_with_overflow,
1392        multiple_supertrait_upcastable,
1393        must_not_suspend,
1394        must_use,
1395        mut_preserve_binding_mode_2024,
1396        mut_ref,
1397        naked,
1398        naked_asm,
1399        naked_functions,
1400        naked_functions_rustic_abi,
1401        naked_functions_target_feature,
1402        name,
1403        names,
1404        native_link_modifiers,
1405        native_link_modifiers_as_needed,
1406        native_link_modifiers_bundle,
1407        native_link_modifiers_verbatim,
1408        native_link_modifiers_whole_archive,
1409        natvis_file,
1410        ne,
1411        needs_allocator,
1412        needs_drop,
1413        needs_panic_runtime,
1414        neg,
1415        negate_unsigned,
1416        negative_bounds,
1417        negative_impls,
1418        neon,
1419        nested,
1420        never,
1421        never_patterns,
1422        never_type,
1423        never_type_fallback,
1424        new,
1425        new_binary,
1426        new_const,
1427        new_debug,
1428        new_debug_noop,
1429        new_display,
1430        new_lower_exp,
1431        new_lower_hex,
1432        new_octal,
1433        new_pointer,
1434        new_range,
1435        new_unchecked,
1436        new_upper_exp,
1437        new_upper_hex,
1438        new_v1,
1439        new_v1_formatted,
1440        next,
1441        niko,
1442        nll,
1443        no,
1444        no_builtins,
1445        no_core,
1446        no_coverage,
1447        no_crate_inject,
1448        no_debug,
1449        no_default_passes,
1450        no_implicit_prelude,
1451        no_inline,
1452        no_link,
1453        no_main,
1454        no_mangle,
1455        no_sanitize,
1456        no_stack_check,
1457        no_std,
1458        nomem,
1459        non_ascii_idents,
1460        non_exhaustive,
1461        non_exhaustive_omitted_patterns_lint,
1462        non_lifetime_binders,
1463        non_modrs_mods,
1464        none,
1465        nontemporal_store,
1466        noop_method_borrow,
1467        noop_method_clone,
1468        noop_method_deref,
1469        noreturn,
1470        nostack,
1471        not,
1472        notable_trait,
1473        note,
1474        object_safe_for_dispatch,
1475        of,
1476        off,
1477        offset,
1478        offset_of,
1479        offset_of_enum,
1480        offset_of_nested,
1481        offset_of_slice,
1482        ok_or_else,
1483        omit_gdb_pretty_printer_section,
1484        on,
1485        on_unimplemented,
1486        opaque,
1487        opaque_module_name_placeholder: "<opaque>",
1488        open_options_new,
1489        ops,
1490        opt_out_copy,
1491        optimize,
1492        optimize_attribute,
1493        optin_builtin_traits,
1494        option,
1495        option_env,
1496        option_expect,
1497        option_unwrap,
1498        options,
1499        or,
1500        or_patterns,
1501        ord_cmp_method,
1502        os_str_to_os_string,
1503        os_string_as_os_str,
1504        other,
1505        out,
1506        overflow_checks,
1507        overlapping_marker_traits,
1508        owned_box,
1509        packed,
1510        packed_bundled_libs,
1511        panic,
1512        panic_2015,
1513        panic_2021,
1514        panic_abort,
1515        panic_any,
1516        panic_bounds_check,
1517        panic_cannot_unwind,
1518        panic_const_add_overflow,
1519        panic_const_async_fn_resumed,
1520        panic_const_async_fn_resumed_drop,
1521        panic_const_async_fn_resumed_panic,
1522        panic_const_async_gen_fn_resumed,
1523        panic_const_async_gen_fn_resumed_drop,
1524        panic_const_async_gen_fn_resumed_panic,
1525        panic_const_coroutine_resumed,
1526        panic_const_coroutine_resumed_drop,
1527        panic_const_coroutine_resumed_panic,
1528        panic_const_div_by_zero,
1529        panic_const_div_overflow,
1530        panic_const_gen_fn_none,
1531        panic_const_gen_fn_none_drop,
1532        panic_const_gen_fn_none_panic,
1533        panic_const_mul_overflow,
1534        panic_const_neg_overflow,
1535        panic_const_rem_by_zero,
1536        panic_const_rem_overflow,
1537        panic_const_shl_overflow,
1538        panic_const_shr_overflow,
1539        panic_const_sub_overflow,
1540        panic_fmt,
1541        panic_handler,
1542        panic_impl,
1543        panic_implementation,
1544        panic_in_cleanup,
1545        panic_info,
1546        panic_location,
1547        panic_misaligned_pointer_dereference,
1548        panic_nounwind,
1549        panic_null_pointer_dereference,
1550        panic_runtime,
1551        panic_str_2015,
1552        panic_unwind,
1553        panicking,
1554        param_attrs,
1555        parent_label,
1556        partial_cmp,
1557        partial_ord,
1558        passes,
1559        pat,
1560        pat_param,
1561        patchable_function_entry,
1562        path,
1563        path_main_separator,
1564        path_to_pathbuf,
1565        pathbuf_as_path,
1566        pattern_complexity_limit,
1567        pattern_parentheses,
1568        pattern_type,
1569        pattern_type_range_trait,
1570        pattern_types,
1571        permissions_from_mode,
1572        phantom_data,
1573        pic,
1574        pie,
1575        pin,
1576        pin_ergonomics,
1577        platform_intrinsics,
1578        plugin,
1579        plugin_registrar,
1580        plugins,
1581        pointee,
1582        pointee_trait,
1583        pointer,
1584        pointer_like,
1585        poll,
1586        poll_next,
1587        position,
1588        post_dash_lto: "post-lto",
1589        postfix_match,
1590        powerpc_target_feature,
1591        powf128,
1592        powf16,
1593        powf32,
1594        powf64,
1595        powif128,
1596        powif16,
1597        powif32,
1598        powif64,
1599        pre_dash_lto: "pre-lto",
1600        precise_capturing,
1601        precise_capturing_in_traits,
1602        precise_pointer_size_matching,
1603        precision,
1604        pref_align_of,
1605        prefetch_read_data,
1606        prefetch_read_instruction,
1607        prefetch_write_data,
1608        prefetch_write_instruction,
1609        prefix_nops,
1610        preg,
1611        prelude,
1612        prelude_import,
1613        preserves_flags,
1614        prfchw_target_feature,
1615        print_macro,
1616        println_macro,
1617        proc_dash_macro: "proc-macro",
1618        proc_macro,
1619        proc_macro_attribute,
1620        proc_macro_derive,
1621        proc_macro_expr,
1622        proc_macro_gen,
1623        proc_macro_hygiene,
1624        proc_macro_internals,
1625        proc_macro_mod,
1626        proc_macro_non_items,
1627        proc_macro_path_invoc,
1628        process_abort,
1629        process_exit,
1630        profiler_builtins,
1631        profiler_runtime,
1632        ptr,
1633        ptr_cast,
1634        ptr_cast_const,
1635        ptr_cast_mut,
1636        ptr_const_is_null,
1637        ptr_copy,
1638        ptr_copy_nonoverlapping,
1639        ptr_eq,
1640        ptr_from_ref,
1641        ptr_guaranteed_cmp,
1642        ptr_is_null,
1643        ptr_mask,
1644        ptr_metadata,
1645        ptr_null,
1646        ptr_null_mut,
1647        ptr_offset_from,
1648        ptr_offset_from_unsigned,
1649        ptr_read,
1650        ptr_read_unaligned,
1651        ptr_read_volatile,
1652        ptr_replace,
1653        ptr_slice_from_raw_parts,
1654        ptr_slice_from_raw_parts_mut,
1655        ptr_swap,
1656        ptr_swap_nonoverlapping,
1657        ptr_unique,
1658        ptr_write,
1659        ptr_write_bytes,
1660        ptr_write_unaligned,
1661        ptr_write_volatile,
1662        pub_macro_rules,
1663        pub_restricted,
1664        public,
1665        pure,
1666        pushpop_unsafe,
1667        qreg,
1668        qreg_low4,
1669        qreg_low8,
1670        quad_precision_float,
1671        question_mark,
1672        quote,
1673        range_inclusive_new,
1674        raw_dylib,
1675        raw_dylib_elf,
1676        raw_eq,
1677        raw_identifiers,
1678        raw_ref_op,
1679        re_rebalance_coherence,
1680        read_enum,
1681        read_enum_variant,
1682        read_enum_variant_arg,
1683        read_struct,
1684        read_struct_field,
1685        read_via_copy,
1686        readonly,
1687        realloc,
1688        reason,
1689        receiver,
1690        receiver_target,
1691        recursion_limit,
1692        reexport_test_harness_main,
1693        ref_pat_eat_one_layer_2024,
1694        ref_pat_eat_one_layer_2024_structural,
1695        ref_pat_everywhere,
1696        ref_unwind_safe_trait,
1697        reference,
1698        reflect,
1699        reg,
1700        reg16,
1701        reg32,
1702        reg64,
1703        reg_abcd,
1704        reg_addr,
1705        reg_byte,
1706        reg_data,
1707        reg_iw,
1708        reg_nonzero,
1709        reg_pair,
1710        reg_ptr,
1711        reg_upper,
1712        register_attr,
1713        register_tool,
1714        relaxed_adts,
1715        relaxed_struct_unsize,
1716        relocation_model,
1717        rem,
1718        rem_assign,
1719        repr,
1720        repr128,
1721        repr_align,
1722        repr_align_enum,
1723        repr_packed,
1724        repr_simd,
1725        repr_transparent,
1726        require,
1727        reserve_x18: "reserve-x18",
1728        residual,
1729        result,
1730        result_ffi_guarantees,
1731        result_ok_method,
1732        resume,
1733        return_position_impl_trait_in_trait,
1734        return_type_notation,
1735        rhs,
1736        riscv_target_feature,
1737        rlib,
1738        ropi,
1739        ropi_rwpi: "ropi-rwpi",
1740        rotate_left,
1741        rotate_right,
1742        round_ties_even_f128,
1743        round_ties_even_f16,
1744        round_ties_even_f32,
1745        round_ties_even_f64,
1746        roundf128,
1747        roundf16,
1748        roundf32,
1749        roundf64,
1750        rt,
1751        rtm_target_feature,
1752        rust,
1753        rust_2015,
1754        rust_2018,
1755        rust_2018_preview,
1756        rust_2021,
1757        rust_2024,
1758        rust_analyzer,
1759        rust_begin_unwind,
1760        rust_cold_cc,
1761        rust_eh_catch_typeinfo,
1762        rust_eh_personality,
1763        rust_future,
1764        rust_logo,
1765        rust_out,
1766        rustc,
1767        rustc_abi,
1768        rustc_allocator,
1769        rustc_allocator_zeroed,
1770        rustc_allow_const_fn_unstable,
1771        rustc_allow_incoherent_impl,
1772        rustc_allowed_through_unstable_modules,
1773        rustc_as_ptr,
1774        rustc_attrs,
1775        rustc_autodiff,
1776        rustc_builtin_macro,
1777        rustc_capture_analysis,
1778        rustc_clean,
1779        rustc_coherence_is_core,
1780        rustc_coinductive,
1781        rustc_confusables,
1782        rustc_const_panic_str,
1783        rustc_const_stable,
1784        rustc_const_stable_indirect,
1785        rustc_const_unstable,
1786        rustc_conversion_suggestion,
1787        rustc_deallocator,
1788        rustc_def_path,
1789        rustc_default_body_unstable,
1790        rustc_delayed_bug_from_inside_query,
1791        rustc_deny_explicit_impl,
1792        rustc_deprecated_safe_2024,
1793        rustc_diagnostic_item,
1794        rustc_diagnostic_macros,
1795        rustc_dirty,
1796        rustc_do_not_const_check,
1797        rustc_do_not_implement_via_object,
1798        rustc_doc_primitive,
1799        rustc_driver,
1800        rustc_dummy,
1801        rustc_dump_def_parents,
1802        rustc_dump_item_bounds,
1803        rustc_dump_predicates,
1804        rustc_dump_user_args,
1805        rustc_dump_vtable,
1806        rustc_effective_visibility,
1807        rustc_evaluate_where_clauses,
1808        rustc_expected_cgu_reuse,
1809        rustc_force_inline,
1810        rustc_has_incoherent_inherent_impls,
1811        rustc_hidden_type_of_opaques,
1812        rustc_if_this_changed,
1813        rustc_inherit_overflow_checks,
1814        rustc_insignificant_dtor,
1815        rustc_intrinsic,
1816        rustc_intrinsic_const_stable_indirect,
1817        rustc_layout,
1818        rustc_layout_scalar_valid_range_end,
1819        rustc_layout_scalar_valid_range_start,
1820        rustc_legacy_const_generics,
1821        rustc_lint_diagnostics,
1822        rustc_lint_opt_deny_field_access,
1823        rustc_lint_opt_ty,
1824        rustc_lint_query_instability,
1825        rustc_lint_untracked_query_information,
1826        rustc_macro_transparency,
1827        rustc_main,
1828        rustc_mir,
1829        rustc_must_implement_one_of,
1830        rustc_never_returns_null_ptr,
1831        rustc_never_type_options,
1832        rustc_no_implicit_autorefs,
1833        rustc_no_mir_inline,
1834        rustc_nonnull_optimization_guaranteed,
1835        rustc_nounwind,
1836        rustc_object_lifetime_default,
1837        rustc_on_unimplemented,
1838        rustc_outlives,
1839        rustc_paren_sugar,
1840        rustc_partition_codegened,
1841        rustc_partition_reused,
1842        rustc_pass_by_value,
1843        rustc_peek,
1844        rustc_peek_liveness,
1845        rustc_peek_maybe_init,
1846        rustc_peek_maybe_uninit,
1847        rustc_preserve_ub_checks,
1848        rustc_private,
1849        rustc_proc_macro_decls,
1850        rustc_promotable,
1851        rustc_pub_transparent,
1852        rustc_reallocator,
1853        rustc_regions,
1854        rustc_reservation_impl,
1855        rustc_serialize,
1856        rustc_skip_during_method_dispatch,
1857        rustc_specialization_trait,
1858        rustc_std_internal_symbol,
1859        rustc_strict_coherence,
1860        rustc_symbol_name,
1861        rustc_test_marker,
1862        rustc_then_this_would_need,
1863        rustc_trivial_field_reads,
1864        rustc_unsafe_specialization_marker,
1865        rustc_variance,
1866        rustc_variance_of_opaques,
1867        rustdoc,
1868        rustdoc_internals,
1869        rustdoc_missing_doc_code_examples,
1870        rustfmt,
1871        rvalue_static_promotion,
1872        rwpi,
1873        s,
1874        s390x_target_feature,
1875        safety,
1876        sanitize,
1877        sanitizer_cfi_generalize_pointers,
1878        sanitizer_cfi_normalize_integers,
1879        sanitizer_runtime,
1880        saturating_add,
1881        saturating_div,
1882        saturating_sub,
1883        sdylib,
1884        search_unbox,
1885        select_unpredictable,
1886        self_in_typedefs,
1887        self_struct_ctor,
1888        semiopaque,
1889        semitransparent,
1890        sha2,
1891        sha3,
1892        sha512_sm_x86,
1893        shadow_call_stack,
1894        shallow,
1895        shl,
1896        shl_assign,
1897        shorter_tail_lifetimes,
1898        should_panic,
1899        shr,
1900        shr_assign,
1901        sig_dfl,
1902        sig_ign,
1903        simd,
1904        simd_add,
1905        simd_and,
1906        simd_arith_offset,
1907        simd_as,
1908        simd_bitmask,
1909        simd_bitreverse,
1910        simd_bswap,
1911        simd_cast,
1912        simd_cast_ptr,
1913        simd_ceil,
1914        simd_ctlz,
1915        simd_ctpop,
1916        simd_cttz,
1917        simd_div,
1918        simd_eq,
1919        simd_expose_provenance,
1920        simd_extract,
1921        simd_extract_dyn,
1922        simd_fabs,
1923        simd_fcos,
1924        simd_fexp,
1925        simd_fexp2,
1926        simd_ffi,
1927        simd_flog,
1928        simd_flog10,
1929        simd_flog2,
1930        simd_floor,
1931        simd_fma,
1932        simd_fmax,
1933        simd_fmin,
1934        simd_fsin,
1935        simd_fsqrt,
1936        simd_gather,
1937        simd_ge,
1938        simd_gt,
1939        simd_insert,
1940        simd_insert_dyn,
1941        simd_le,
1942        simd_lt,
1943        simd_masked_load,
1944        simd_masked_store,
1945        simd_mul,
1946        simd_ne,
1947        simd_neg,
1948        simd_or,
1949        simd_reduce_add_ordered,
1950        simd_reduce_add_unordered,
1951        simd_reduce_all,
1952        simd_reduce_and,
1953        simd_reduce_any,
1954        simd_reduce_max,
1955        simd_reduce_min,
1956        simd_reduce_mul_ordered,
1957        simd_reduce_mul_unordered,
1958        simd_reduce_or,
1959        simd_reduce_xor,
1960        simd_relaxed_fma,
1961        simd_rem,
1962        simd_round,
1963        simd_saturating_add,
1964        simd_saturating_sub,
1965        simd_scatter,
1966        simd_select,
1967        simd_select_bitmask,
1968        simd_shl,
1969        simd_shr,
1970        simd_shuffle,
1971        simd_shuffle_const_generic,
1972        simd_sub,
1973        simd_trunc,
1974        simd_with_exposed_provenance,
1975        simd_xor,
1976        since,
1977        sinf128,
1978        sinf16,
1979        sinf32,
1980        sinf64,
1981        size,
1982        size_of,
1983        size_of_val,
1984        sized,
1985        skip,
1986        slice,
1987        slice_from_raw_parts,
1988        slice_from_raw_parts_mut,
1989        slice_into_vec,
1990        slice_iter,
1991        slice_len_fn,
1992        slice_patterns,
1993        slicing_syntax,
1994        soft,
1995        sparc_target_feature,
1996        specialization,
1997        speed,
1998        spotlight,
1999        sqrtf128,
2000        sqrtf16,
2001        sqrtf32,
2002        sqrtf64,
2003        sreg,
2004        sreg_low16,
2005        sse,
2006        sse2,
2007        sse4a_target_feature,
2008        stable,
2009        staged_api,
2010        start,
2011        state,
2012        static_in_const,
2013        static_nobundle,
2014        static_recursion,
2015        staticlib,
2016        std,
2017        std_panic,
2018        std_panic_2015_macro,
2019        std_panic_macro,
2020        stmt,
2021        stmt_expr_attributes,
2022        stop_after_dataflow,
2023        store,
2024        str,
2025        str_chars,
2026        str_ends_with,
2027        str_from_utf8,
2028        str_from_utf8_mut,
2029        str_from_utf8_unchecked,
2030        str_from_utf8_unchecked_mut,
2031        str_inherent_from_utf8,
2032        str_inherent_from_utf8_mut,
2033        str_inherent_from_utf8_unchecked,
2034        str_inherent_from_utf8_unchecked_mut,
2035        str_len,
2036        str_split_whitespace,
2037        str_starts_with,
2038        str_trim,
2039        str_trim_end,
2040        str_trim_start,
2041        strict_provenance_lints,
2042        string_as_mut_str,
2043        string_as_str,
2044        string_deref_patterns,
2045        string_from_utf8,
2046        string_insert_str,
2047        string_new,
2048        string_push_str,
2049        stringify,
2050        struct_field_attributes,
2051        struct_inherit,
2052        struct_variant,
2053        structural_match,
2054        structural_peq,
2055        sub,
2056        sub_assign,
2057        sub_with_overflow,
2058        suggestion,
2059        super_let,
2060        supertrait_item_shadowing,
2061        sym,
2062        sync,
2063        synthetic,
2064        t32,
2065        target,
2066        target_abi,
2067        target_arch,
2068        target_endian,
2069        target_env,
2070        target_family,
2071        target_feature,
2072        target_feature_11,
2073        target_has_atomic,
2074        target_has_atomic_equal_alignment,
2075        target_has_atomic_load_store,
2076        target_has_reliable_f128,
2077        target_has_reliable_f128_math,
2078        target_has_reliable_f16,
2079        target_has_reliable_f16_math,
2080        target_os,
2081        target_pointer_width,
2082        target_thread_local,
2083        target_vendor,
2084        tbm_target_feature,
2085        termination,
2086        termination_trait,
2087        termination_trait_test,
2088        test,
2089        test_2018_feature,
2090        test_accepted_feature,
2091        test_case,
2092        test_removed_feature,
2093        test_runner,
2094        test_unstable_lint,
2095        thread,
2096        thread_local,
2097        thread_local_macro,
2098        three_way_compare,
2099        thumb2,
2100        thumb_mode: "thumb-mode",
2101        time,
2102        tmm_reg,
2103        to_owned_method,
2104        to_string,
2105        to_string_method,
2106        to_vec,
2107        todo_macro,
2108        tool_attributes,
2109        tool_lints,
2110        trace_macros,
2111        track_caller,
2112        trait_alias,
2113        trait_upcasting,
2114        transmute,
2115        transmute_generic_consts,
2116        transmute_opts,
2117        transmute_trait,
2118        transmute_unchecked,
2119        transparent,
2120        transparent_enums,
2121        transparent_unions,
2122        trivial_bounds,
2123        truncf128,
2124        truncf16,
2125        truncf32,
2126        truncf64,
2127        try_blocks,
2128        try_capture,
2129        try_from,
2130        try_from_fn,
2131        try_into,
2132        try_trait_v2,
2133        tt,
2134        tuple,
2135        tuple_indexing,
2136        tuple_trait,
2137        two_phase,
2138        ty,
2139        type_alias_enum_variants,
2140        type_alias_impl_trait,
2141        type_ascribe,
2142        type_ascription,
2143        type_changing_struct_update,
2144        type_const,
2145        type_id,
2146        type_ir_infer_ctxt_like,
2147        type_ir_inherent,
2148        type_ir_interner,
2149        type_length_limit,
2150        type_macros,
2151        type_name,
2152        type_privacy_lints,
2153        typed_swap_nonoverlapping,
2154        u128,
2155        u128_legacy_const_max,
2156        u128_legacy_const_min,
2157        u128_legacy_fn_max_value,
2158        u128_legacy_fn_min_value,
2159        u128_legacy_mod,
2160        u16,
2161        u16_legacy_const_max,
2162        u16_legacy_const_min,
2163        u16_legacy_fn_max_value,
2164        u16_legacy_fn_min_value,
2165        u16_legacy_mod,
2166        u32,
2167        u32_legacy_const_max,
2168        u32_legacy_const_min,
2169        u32_legacy_fn_max_value,
2170        u32_legacy_fn_min_value,
2171        u32_legacy_mod,
2172        u64,
2173        u64_legacy_const_max,
2174        u64_legacy_const_min,
2175        u64_legacy_fn_max_value,
2176        u64_legacy_fn_min_value,
2177        u64_legacy_mod,
2178        u8,
2179        u8_legacy_const_max,
2180        u8_legacy_const_min,
2181        u8_legacy_fn_max_value,
2182        u8_legacy_fn_min_value,
2183        u8_legacy_mod,
2184        ub_checks,
2185        unaligned_volatile_load,
2186        unaligned_volatile_store,
2187        unboxed_closures,
2188        unchecked_add,
2189        unchecked_div,
2190        unchecked_mul,
2191        unchecked_rem,
2192        unchecked_shl,
2193        unchecked_shr,
2194        unchecked_sub,
2195        underscore_const_names,
2196        underscore_imports,
2197        underscore_lifetimes,
2198        uniform_paths,
2199        unimplemented_macro,
2200        unit,
2201        universal_impl_trait,
2202        unix,
2203        unlikely,
2204        unmarked_api,
2205        unnamed_fields,
2206        unpin,
2207        unqualified_local_imports,
2208        unreachable,
2209        unreachable_2015,
2210        unreachable_2015_macro,
2211        unreachable_2021,
2212        unreachable_code,
2213        unreachable_display,
2214        unreachable_macro,
2215        unrestricted_attribute_tokens,
2216        unsafe_attributes,
2217        unsafe_binders,
2218        unsafe_block_in_unsafe_fn,
2219        unsafe_cell,
2220        unsafe_cell_raw_get,
2221        unsafe_extern_blocks,
2222        unsafe_fields,
2223        unsafe_no_drop_flag,
2224        unsafe_pinned,
2225        unsafe_unpin,
2226        unsize,
2227        unsized_const_param_ty,
2228        unsized_const_params,
2229        unsized_fn_params,
2230        unsized_locals,
2231        unsized_tuple_coercion,
2232        unstable,
2233        unstable_location_reason_default: "this crate is being loaded from the sysroot, an \
2234                          unstable location; did you mean to load this crate \
2235                          from crates.io via `Cargo.toml` instead?",
2236        untagged_unions,
2237        unused_imports,
2238        unwind,
2239        unwind_attributes,
2240        unwind_safe_trait,
2241        unwrap,
2242        unwrap_binder,
2243        unwrap_or,
2244        use_cloned,
2245        use_extern_macros,
2246        use_nested_groups,
2247        used,
2248        used_with_arg,
2249        using,
2250        usize,
2251        usize_legacy_const_max,
2252        usize_legacy_const_min,
2253        usize_legacy_fn_max_value,
2254        usize_legacy_fn_min_value,
2255        usize_legacy_mod,
2256        v8plus,
2257        va_arg,
2258        va_copy,
2259        va_end,
2260        va_list,
2261        va_start,
2262        val,
2263        validity,
2264        values,
2265        var,
2266        variant_count,
2267        vec,
2268        vec_as_mut_slice,
2269        vec_as_slice,
2270        vec_from_elem,
2271        vec_is_empty,
2272        vec_macro,
2273        vec_new,
2274        vec_pop,
2275        vec_reserve,
2276        vec_with_capacity,
2277        vecdeque_iter,
2278        vecdeque_reserve,
2279        vector,
2280        version,
2281        vfp2,
2282        vis,
2283        visible_private_types,
2284        volatile,
2285        volatile_copy_memory,
2286        volatile_copy_nonoverlapping_memory,
2287        volatile_load,
2288        volatile_set_memory,
2289        volatile_store,
2290        vreg,
2291        vreg_low16,
2292        vsx,
2293        vtable_align,
2294        vtable_size,
2295        warn,
2296        wasip2,
2297        wasm_abi,
2298        wasm_import_module,
2299        wasm_target_feature,
2300        where_clause_attrs,
2301        while_let,
2302        width,
2303        windows,
2304        windows_subsystem,
2305        with_negative_coherence,
2306        wrap_binder,
2307        wrapping_add,
2308        wrapping_div,
2309        wrapping_mul,
2310        wrapping_rem,
2311        wrapping_rem_euclid,
2312        wrapping_sub,
2313        wreg,
2314        write_bytes,
2315        write_fmt,
2316        write_macro,
2317        write_str,
2318        write_via_move,
2319        writeln_macro,
2320        x86_amx_intrinsics,
2321        x87_reg,
2322        x87_target_feature,
2323        xer,
2324        xmm_reg,
2325        xop_target_feature,
2326        yeet_desugar_details,
2327        yeet_expr,
2328        yes,
2329        yield_expr,
2330        ymm_reg,
2331        yreg,
2332        zfh,
2333        zfhmin,
2334        zmm_reg,
2335    }
2336}
2337
2338/// Symbols for crates that are part of the stable standard library: `std`, `core`, `alloc`, and
2339/// `proc_macro`.
2340pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, sym::proc_macro];
2341
2342#[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)]
2343pub struct Ident {
2344    pub name: Symbol,
2345    pub span: Span,
2346}
2347
2348impl Ident {
2349    #[inline]
2350    /// Constructs a new identifier from a symbol and a span.
2351    pub const fn new(name: Symbol, span: Span) -> Ident {
2352        Ident { name, span }
2353    }
2354
2355    /// Constructs a new identifier with a dummy span.
2356    #[inline]
2357    pub const fn with_dummy_span(name: Symbol) -> Ident {
2358        Ident::new(name, DUMMY_SP)
2359    }
2360
2361    /// This is best avoided, because it blurs the lines between "empty
2362    /// identifier" and "no identifier". Using `Option<Ident>` is preferable,
2363    /// where possible, because that is unambiguous.
2364    #[inline]
2365    pub fn empty() -> Ident {
2366        Ident::with_dummy_span(kw::Empty)
2367    }
2368
2369    // For dummy identifiers that are never used and absolutely must be
2370    // present, it's better to use `Ident::dummy` than `Ident::Empty`, because
2371    // it's clearer that it's intended as a dummy value, and more likely to be
2372    // detected if it accidentally does get used.
2373    #[inline]
2374    pub fn dummy() -> Ident {
2375        Ident::with_dummy_span(sym::dummy)
2376    }
2377
2378    /// Maps a string to an identifier with a dummy span.
2379    pub fn from_str(string: &str) -> Ident {
2380        Ident::with_dummy_span(Symbol::intern(string))
2381    }
2382
2383    /// Maps a string and a span to an identifier.
2384    pub fn from_str_and_span(string: &str, span: Span) -> Ident {
2385        Ident::new(Symbol::intern(string), span)
2386    }
2387
2388    /// Replaces `lo` and `hi` with those from `span`, but keep hygiene context.
2389    pub fn with_span_pos(self, span: Span) -> Ident {
2390        Ident::new(self.name, span.with_ctxt(self.span.ctxt()))
2391    }
2392
2393    pub fn without_first_quote(self) -> Ident {
2394        Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
2395    }
2396
2397    /// "Normalize" ident for use in comparisons using "item hygiene".
2398    /// Identifiers with same string value become same if they came from the same macro 2.0 macro
2399    /// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
2400    /// different macro 2.0 macros.
2401    /// Technically, this operation strips all non-opaque marks from ident's syntactic context.
2402    pub fn normalize_to_macros_2_0(self) -> Ident {
2403        Ident::new(self.name, self.span.normalize_to_macros_2_0())
2404    }
2405
2406    /// "Normalize" ident for use in comparisons using "local variable hygiene".
2407    /// Identifiers with same string value become same if they came from the same non-transparent
2408    /// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
2409    /// non-transparent macros.
2410    /// Technically, this operation strips all transparent marks from ident's syntactic context.
2411    #[inline]
2412    pub fn normalize_to_macro_rules(self) -> Ident {
2413        Ident::new(self.name, self.span.normalize_to_macro_rules())
2414    }
2415
2416    /// Access the underlying string. This is a slowish operation because it
2417    /// requires locking the symbol interner.
2418    ///
2419    /// Note that the lifetime of the return value is a lie. See
2420    /// `Symbol::as_str()` for details.
2421    pub fn as_str(&self) -> &str {
2422        self.name.as_str()
2423    }
2424}
2425
2426impl PartialEq for Ident {
2427    #[inline]
2428    fn eq(&self, rhs: &Self) -> bool {
2429        self.name == rhs.name && self.span.eq_ctxt(rhs.span)
2430    }
2431}
2432
2433impl Hash for Ident {
2434    fn hash<H: Hasher>(&self, state: &mut H) {
2435        self.name.hash(state);
2436        self.span.ctxt().hash(state);
2437    }
2438}
2439
2440impl fmt::Debug for Ident {
2441    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2442        fmt::Display::fmt(self, f)?;
2443        fmt::Debug::fmt(&self.span.ctxt(), f)
2444    }
2445}
2446
2447/// This implementation is supposed to be used in error messages, so it's expected to be identical
2448/// to printing the original identifier token written in source code (`token_to_string`),
2449/// except that AST identifiers don't keep the rawness flag, so we have to guess it.
2450impl fmt::Display for Ident {
2451    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2452        fmt::Display::fmt(&IdentPrinter::new(self.name, self.is_raw_guess(), None), f)
2453    }
2454}
2455
2456/// The most general type to print identifiers.
2457///
2458/// AST pretty-printer is used as a fallback for turning AST structures into token streams for
2459/// proc macros. Additionally, proc macros may stringify their input and expect it survive the
2460/// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30).
2461/// So we need to somehow pretty-print `$crate` in a way preserving at least some of its
2462/// hygiene data, most importantly name of the crate it refers to.
2463/// As a result we print `$crate` as `crate` if it refers to the local crate
2464/// and as `::other_crate_name` if it refers to some other crate.
2465/// Note, that this is only done if the ident token is printed from inside of AST pretty-printing,
2466/// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
2467/// so we should not perform this lossy conversion if the top level call to the pretty-printer was
2468/// done for a token stream or a single token.
2469pub struct IdentPrinter {
2470    symbol: Symbol,
2471    is_raw: bool,
2472    /// Span used for retrieving the crate name to which `$crate` refers to,
2473    /// if this field is `None` then the `$crate` conversion doesn't happen.
2474    convert_dollar_crate: Option<Span>,
2475}
2476
2477impl IdentPrinter {
2478    /// The most general `IdentPrinter` constructor. Do not use this.
2479    pub fn new(symbol: Symbol, is_raw: bool, convert_dollar_crate: Option<Span>) -> IdentPrinter {
2480        IdentPrinter { symbol, is_raw, convert_dollar_crate }
2481    }
2482
2483    /// This implementation is supposed to be used when printing identifiers
2484    /// as a part of pretty-printing for larger AST pieces.
2485    /// Do not use this either.
2486    pub fn for_ast_ident(ident: Ident, is_raw: bool) -> IdentPrinter {
2487        IdentPrinter::new(ident.name, is_raw, Some(ident.span))
2488    }
2489}
2490
2491impl fmt::Display for IdentPrinter {
2492    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2493        if self.is_raw {
2494            f.write_str("r#")?;
2495        } else if self.symbol == kw::DollarCrate {
2496            if let Some(span) = self.convert_dollar_crate {
2497                let converted = span.ctxt().dollar_crate_name();
2498                if !converted.is_path_segment_keyword() {
2499                    f.write_str("::")?;
2500                }
2501                return fmt::Display::fmt(&converted, f);
2502            }
2503        }
2504        fmt::Display::fmt(&self.symbol, f)
2505    }
2506}
2507
2508/// An newtype around `Ident` that calls [Ident::normalize_to_macro_rules] on
2509/// construction.
2510// FIXME(matthewj, petrochenkov) Use this more often, add a similar
2511// `ModernIdent` struct and use that as well.
2512#[derive(Copy, Clone, Eq, PartialEq, Hash)]
2513pub struct MacroRulesNormalizedIdent(Ident);
2514
2515impl MacroRulesNormalizedIdent {
2516    #[inline]
2517    pub fn new(ident: Ident) -> Self {
2518        Self(ident.normalize_to_macro_rules())
2519    }
2520}
2521
2522impl fmt::Debug for MacroRulesNormalizedIdent {
2523    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2524        fmt::Debug::fmt(&self.0, f)
2525    }
2526}
2527
2528impl fmt::Display for MacroRulesNormalizedIdent {
2529    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2530        fmt::Display::fmt(&self.0, f)
2531    }
2532}
2533
2534/// An interned string.
2535///
2536/// Internally, a `Symbol` is implemented as an index, and all operations
2537/// (including hashing, equality, and ordering) operate on that index. The use
2538/// of `rustc_index::newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
2539/// because `rustc_index::newtype_index!` reserves the last 256 values for tagging purposes.
2540///
2541/// Note that `Symbol` cannot directly be a `rustc_index::newtype_index!` because it
2542/// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
2543#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2544pub struct Symbol(SymbolIndex);
2545
2546rustc_index::newtype_index! {
2547    #[orderable]
2548    struct SymbolIndex {}
2549}
2550
2551impl Symbol {
2552    pub const fn new(n: u32) -> Self {
2553        Symbol(SymbolIndex::from_u32(n))
2554    }
2555
2556    /// Maps a string to its interned representation.
2557    #[rustc_diagnostic_item = "SymbolIntern"]
2558    pub fn intern(string: &str) -> Self {
2559        with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
2560    }
2561
2562    /// Access the underlying string. This is a slowish operation because it
2563    /// requires locking the symbol interner.
2564    ///
2565    /// Note that the lifetime of the return value is a lie. It's not the same
2566    /// as `&self`, but actually tied to the lifetime of the underlying
2567    /// interner. Interners are long-lived, and there are very few of them, and
2568    /// this function is typically used for short-lived things, so in practice
2569    /// it works out ok.
2570    pub fn as_str(&self) -> &str {
2571        with_session_globals(|session_globals| unsafe {
2572            std::mem::transmute::<&str, &str>(session_globals.symbol_interner.get(*self))
2573        })
2574    }
2575
2576    pub fn as_u32(self) -> u32 {
2577        self.0.as_u32()
2578    }
2579
2580    pub fn is_empty(self) -> bool {
2581        self == kw::Empty
2582    }
2583
2584    /// This method is supposed to be used in error messages, so it's expected to be
2585    /// identical to printing the original identifier token written in source code
2586    /// (`token_to_string`, `Ident::to_string`), except that symbols don't keep the rawness flag
2587    /// or edition, so we have to guess the rawness using the global edition.
2588    pub fn to_ident_string(self) -> String {
2589        Ident::with_dummy_span(self).to_string()
2590    }
2591}
2592
2593impl fmt::Debug for Symbol {
2594    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2595        fmt::Debug::fmt(self.as_str(), f)
2596    }
2597}
2598
2599impl fmt::Display for Symbol {
2600    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2601        fmt::Display::fmt(self.as_str(), f)
2602    }
2603}
2604
2605impl<CTX> HashStable<CTX> for Symbol {
2606    #[inline]
2607    fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
2608        self.as_str().hash_stable(hcx, hasher);
2609    }
2610}
2611
2612impl<CTX> ToStableHashKey<CTX> for Symbol {
2613    type KeyType = String;
2614    #[inline]
2615    fn to_stable_hash_key(&self, _: &CTX) -> String {
2616        self.as_str().to_string()
2617    }
2618}
2619
2620impl StableCompare for Symbol {
2621    const CAN_USE_UNSTABLE_SORT: bool = true;
2622
2623    fn stable_cmp(&self, other: &Self) -> std::cmp::Ordering {
2624        self.as_str().cmp(other.as_str())
2625    }
2626}
2627
2628pub(crate) struct Interner(Lock<InternerInner>);
2629
2630// The `&'static str`s in this type actually point into the arena.
2631//
2632// This type is private to prevent accidentally constructing more than one
2633// `Interner` on the same thread, which makes it easy to mix up `Symbol`s
2634// between `Interner`s.
2635struct InternerInner {
2636    arena: DroplessArena,
2637    strings: FxIndexSet<&'static str>,
2638}
2639
2640impl Interner {
2641    fn prefill(init: &[&'static str], extra: &[&'static str]) -> Self {
2642        let strings = FxIndexSet::from_iter(init.iter().copied().chain(extra.iter().copied()));
2643        assert_eq!(
2644            strings.len(),
2645            init.len() + extra.len(),
2646            "`init` or `extra` contain duplicate symbols",
2647        );
2648        Interner(Lock::new(InternerInner { arena: Default::default(), strings }))
2649    }
2650
2651    #[inline]
2652    fn intern(&self, string: &str) -> Symbol {
2653        let mut inner = self.0.lock();
2654        if let Some(idx) = inner.strings.get_index_of(string) {
2655            return Symbol::new(idx as u32);
2656        }
2657
2658        let string: &str = inner.arena.alloc_str(string);
2659
2660        // SAFETY: we can extend the arena allocation to `'static` because we
2661        // only access these while the arena is still alive.
2662        let string: &'static str = unsafe { &*(string as *const str) };
2663
2664        // This second hash table lookup can be avoided by using `RawEntryMut`,
2665        // but this code path isn't hot enough for it to be worth it. See
2666        // #91445 for details.
2667        let (idx, is_new) = inner.strings.insert_full(string);
2668        debug_assert!(is_new); // due to the get_index_of check above
2669
2670        Symbol::new(idx as u32)
2671    }
2672
2673    /// Get the symbol as a string.
2674    ///
2675    /// [`Symbol::as_str()`] should be used in preference to this function.
2676    fn get(&self, symbol: Symbol) -> &str {
2677        self.0.lock().strings.get_index(symbol.0.as_usize()).unwrap()
2678    }
2679}
2680
2681// This module has a very short name because it's used a lot.
2682/// This module contains all the defined keyword `Symbol`s.
2683///
2684/// Given that `kw` is imported, use them like `kw::keyword_name`.
2685/// For example `kw::Loop` or `kw::Break`.
2686pub mod kw {
2687    pub use super::kw_generated::*;
2688}
2689
2690// This module has a very short name because it's used a lot.
2691/// This module contains all the defined non-keyword `Symbol`s.
2692///
2693/// Given that `sym` is imported, use them like `sym::symbol_name`.
2694/// For example `sym::rustfmt` or `sym::u8`.
2695pub mod sym {
2696    // Used from a macro in `librustc_feature/accepted.rs`
2697    use super::Symbol;
2698    pub use super::kw::MacroRules as macro_rules;
2699    #[doc(inline)]
2700    pub use super::sym_generated::*;
2701
2702    /// Get the symbol for an integer.
2703    ///
2704    /// The first few non-negative integers each have a static symbol and therefore
2705    /// are fast.
2706    pub fn integer<N: TryInto<usize> + Copy + itoa::Integer>(n: N) -> Symbol {
2707        if let Result::Ok(idx) = n.try_into() {
2708            if idx < 10 {
2709                return Symbol::new(super::SYMBOL_DIGITS_BASE + idx as u32);
2710            }
2711        }
2712        let mut buffer = itoa::Buffer::new();
2713        let printed = buffer.format(n);
2714        Symbol::intern(printed)
2715    }
2716}
2717
2718impl Symbol {
2719    fn is_special(self) -> bool {
2720        self <= kw::Underscore
2721    }
2722
2723    fn is_used_keyword_always(self) -> bool {
2724        self >= kw::As && self <= kw::While
2725    }
2726
2727    fn is_unused_keyword_always(self) -> bool {
2728        self >= kw::Abstract && self <= kw::Yield
2729    }
2730
2731    fn is_used_keyword_conditional(self, edition: impl FnOnce() -> Edition) -> bool {
2732        (self >= kw::Async && self <= kw::Dyn) && edition() >= Edition::Edition2018
2733    }
2734
2735    fn is_unused_keyword_conditional(self, edition: impl Copy + FnOnce() -> Edition) -> bool {
2736        self == kw::Gen && edition().at_least_rust_2024()
2737            || self == kw::Try && edition().at_least_rust_2018()
2738    }
2739
2740    pub fn is_reserved(self, edition: impl Copy + FnOnce() -> Edition) -> bool {
2741        self.is_special()
2742            || self.is_used_keyword_always()
2743            || self.is_unused_keyword_always()
2744            || self.is_used_keyword_conditional(edition)
2745            || self.is_unused_keyword_conditional(edition)
2746    }
2747
2748    pub fn is_weak(self) -> bool {
2749        self >= kw::Auto && self <= kw::Yeet
2750    }
2751
2752    /// A keyword or reserved identifier that can be used as a path segment.
2753    pub fn is_path_segment_keyword(self) -> bool {
2754        self == kw::Super
2755            || self == kw::SelfLower
2756            || self == kw::SelfUpper
2757            || self == kw::Crate
2758            || self == kw::PathRoot
2759            || self == kw::DollarCrate
2760    }
2761
2762    /// Returns `true` if the symbol is `true` or `false`.
2763    pub fn is_bool_lit(self) -> bool {
2764        self == kw::True || self == kw::False
2765    }
2766
2767    /// Returns `true` if this symbol can be a raw identifier.
2768    pub fn can_be_raw(self) -> bool {
2769        self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
2770    }
2771
2772    /// Was this symbol predefined in the compiler's `symbols!` macro
2773    pub fn is_predefined(self) -> bool {
2774        self.as_u32() < PREDEFINED_SYMBOLS_COUNT
2775    }
2776}
2777
2778impl Ident {
2779    /// Returns `true` for reserved identifiers used internally for elided lifetimes,
2780    /// unnamed method parameters, crate root module, error recovery etc.
2781    pub fn is_special(self) -> bool {
2782        self.name.is_special()
2783    }
2784
2785    /// Returns `true` if the token is a keyword used in the language.
2786    pub fn is_used_keyword(self) -> bool {
2787        // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
2788        self.name.is_used_keyword_always()
2789            || self.name.is_used_keyword_conditional(|| self.span.edition())
2790    }
2791
2792    /// Returns `true` if the token is a keyword reserved for possible future use.
2793    pub fn is_unused_keyword(self) -> bool {
2794        // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
2795        self.name.is_unused_keyword_always()
2796            || self.name.is_unused_keyword_conditional(|| self.span.edition())
2797    }
2798
2799    /// Returns `true` if the token is either a special identifier or a keyword.
2800    pub fn is_reserved(self) -> bool {
2801        // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
2802        self.name.is_reserved(|| self.span.edition())
2803    }
2804
2805    /// A keyword or reserved identifier that can be used as a path segment.
2806    pub fn is_path_segment_keyword(self) -> bool {
2807        self.name.is_path_segment_keyword()
2808    }
2809
2810    /// We see this identifier in a normal identifier position, like variable name or a type.
2811    /// How was it written originally? Did it use the raw form? Let's try to guess.
2812    pub fn is_raw_guess(self) -> bool {
2813        self.name.can_be_raw() && self.is_reserved()
2814    }
2815
2816    /// Whether this would be the identifier for a tuple field like `self.0`, as
2817    /// opposed to a named field like `self.thing`.
2818    pub fn is_numeric(self) -> bool {
2819        !self.name.is_empty() && self.as_str().bytes().all(|b| b.is_ascii_digit())
2820    }
2821}
2822
2823/// Collect all the keywords in a given edition into a vector.
2824///
2825/// *Note:* Please update this if a new keyword is added beyond the current
2826/// range.
2827pub fn used_keywords(edition: impl Copy + FnOnce() -> Edition) -> Vec<Symbol> {
2828    (kw::DollarCrate.as_u32()..kw::Yeet.as_u32())
2829        .filter_map(|kw| {
2830            let kw = Symbol::new(kw);
2831            if kw.is_used_keyword_always() || kw.is_used_keyword_conditional(edition) {
2832                Some(kw)
2833            } else {
2834                None
2835            }
2836        })
2837        .collect()
2838}