Skip to main content

rustc_ast/
token.rs

1use std::borrow::Cow;
2use std::fmt;
3
4pub use LitKind::*;
5pub use NtExprKind::*;
6pub use NtPatKind::*;
7pub use TokenKind::*;
8use rustc_macros::{Decodable, Encodable, HashStable_Generic};
9use rustc_span::edition::Edition;
10use rustc_span::symbol::IdentPrintMode;
11use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym};
12#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
13#[allow(hidden_glob_reexports)]
14use rustc_span::{Ident, Symbol};
15
16use crate::ast;
17use crate::util::case::Case;
18
19/// Represents the kind of doc comment it is, ie `///` or `#[doc = ""]`.
20#[derive(#[automatically_derived]
impl ::core::clone::Clone for DocFragmentKind {
    #[inline]
    fn clone(&self) -> DocFragmentKind {
        let _: ::core::clone::AssertParamIsClone<CommentKind>;
        let _: ::core::clone::AssertParamIsClone<Span>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for DocFragmentKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for DocFragmentKind {
    #[inline]
    fn eq(&self, other: &DocFragmentKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (DocFragmentKind::Sugared(__self_0),
                    DocFragmentKind::Sugared(__arg1_0)) => __self_0 == __arg1_0,
                (DocFragmentKind::Raw(__self_0),
                    DocFragmentKind::Raw(__arg1_0)) => __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DocFragmentKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<CommentKind>;
        let _: ::core::cmp::AssertParamIsEq<Span>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DocFragmentKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        DocFragmentKind::Sugared(ref __binding_0) => { 0usize }
                        DocFragmentKind::Raw(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    DocFragmentKind::Sugared(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DocFragmentKind::Raw(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for DocFragmentKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        DocFragmentKind::Sugared(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        DocFragmentKind::Raw(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DocFragmentKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for DocFragmentKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DocFragmentKind::Sugared(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Sugared", &__self_0),
            DocFragmentKind::Raw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Raw",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for DocFragmentKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    DocFragmentKind::Sugared(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    DocFragmentKind::Raw(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
21pub enum DocFragmentKind {
22    /// A sugared doc comment: `///` or `//!` or `/**` or `/*!`.
23    Sugared(CommentKind),
24    /// A "raw" doc comment: `#[doc = ""]`. The `Span` represents the string literal.
25    Raw(Span),
26}
27
28impl DocFragmentKind {
29    pub fn is_sugared(self) -> bool {
30        #[allow(non_exhaustive_omitted_patterns)] match self {
    Self::Sugared(_) => true,
    _ => false,
}matches!(self, Self::Sugared(_))
31    }
32
33    /// If it is `Sugared`, it will return its associated `CommentKind`, otherwise it will return
34    /// `CommentKind::Line`.
35    pub fn comment_kind(self) -> CommentKind {
36        match self {
37            Self::Sugared(kind) => kind,
38            Self::Raw(_) => CommentKind::Line,
39        }
40    }
41}
42
43#[derive(#[automatically_derived]
impl ::core::clone::Clone for CommentKind {
    #[inline]
    fn clone(&self) -> CommentKind { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for CommentKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for CommentKind {
    #[inline]
    fn eq(&self, other: &CommentKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CommentKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for CommentKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for CommentKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        CommentKind::Line => { 0usize }
                        CommentKind::Block => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    CommentKind::Line => {}
                    CommentKind::Block => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for CommentKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { CommentKind::Line }
                    1usize => { CommentKind::Block }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `CommentKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for CommentKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                CommentKind::Line => "Line",
                CommentKind::Block => "Block",
            })
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for CommentKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    CommentKind::Line => {}
                    CommentKind::Block => {}
                }
            }
        }
    };HashStable_Generic)]
44pub enum CommentKind {
45    Line,
46    Block,
47}
48
49#[derive(#[automatically_derived]
impl ::core::marker::Copy for InvisibleOrigin { }Copy, #[automatically_derived]
impl ::core::clone::Clone for InvisibleOrigin {
    #[inline]
    fn clone(&self) -> InvisibleOrigin {
        let _: ::core::clone::AssertParamIsClone<MetaVarKind>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for InvisibleOrigin {
    #[inline]
    fn eq(&self, other: &InvisibleOrigin) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (InvisibleOrigin::MetaVar(__self_0),
                    InvisibleOrigin::MetaVar(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for InvisibleOrigin {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<MetaVarKind>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for InvisibleOrigin {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            InvisibleOrigin::MetaVar(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for InvisibleOrigin {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            InvisibleOrigin::MetaVar(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "MetaVar", &__self_0),
            InvisibleOrigin::ProcMacro =>
                ::core::fmt::Formatter::write_str(f, "ProcMacro"),
        }
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for InvisibleOrigin {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        InvisibleOrigin::MetaVar(ref __binding_0) => { 0usize }
                        InvisibleOrigin::ProcMacro => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    InvisibleOrigin::MetaVar(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    InvisibleOrigin::ProcMacro => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for InvisibleOrigin {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        InvisibleOrigin::MetaVar(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => { InvisibleOrigin::ProcMacro }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `InvisibleOrigin`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for InvisibleOrigin where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    InvisibleOrigin::MetaVar(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    InvisibleOrigin::ProcMacro => {}
                }
            }
        }
    };HashStable_Generic)]
50pub enum InvisibleOrigin {
51    // From the expansion of a metavariable in a declarative macro.
52    MetaVar(MetaVarKind),
53
54    // Converted from `proc_macro::Delimiter` in
55    // `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
56    ProcMacro,
57}
58
59impl InvisibleOrigin {
60    // Should the parser skip these invisible delimiters? Ideally this function
61    // will eventually disappear and no invisible delimiters will be skipped.
62    #[inline]
63    pub fn skip(&self) -> bool {
64        match self {
65            InvisibleOrigin::MetaVar(_) => false,
66            InvisibleOrigin::ProcMacro => true,
67        }
68    }
69}
70
71/// Annoyingly similar to `NonterminalKind`, but the slight differences are important.
72#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MetaVarKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            MetaVarKind::Item => ::core::fmt::Formatter::write_str(f, "Item"),
            MetaVarKind::Block =>
                ::core::fmt::Formatter::write_str(f, "Block"),
            MetaVarKind::Stmt => ::core::fmt::Formatter::write_str(f, "Stmt"),
            MetaVarKind::Pat(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Pat",
                    &__self_0),
            MetaVarKind::Expr {
                kind: __self_0,
                can_begin_literal_maybe_minus: __self_1,
                can_begin_string_literal: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f, "Expr",
                    "kind", __self_0, "can_begin_literal_maybe_minus", __self_1,
                    "can_begin_string_literal", &__self_2),
            MetaVarKind::Ty { is_path: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Ty",
                    "is_path", &__self_0),
            MetaVarKind::Ident =>
                ::core::fmt::Formatter::write_str(f, "Ident"),
            MetaVarKind::Lifetime =>
                ::core::fmt::Formatter::write_str(f, "Lifetime"),
            MetaVarKind::Literal =>
                ::core::fmt::Formatter::write_str(f, "Literal"),
            MetaVarKind::Meta { has_meta_form: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Meta",
                    "has_meta_form", &__self_0),
            MetaVarKind::Path => ::core::fmt::Formatter::write_str(f, "Path"),
            MetaVarKind::Vis => ::core::fmt::Formatter::write_str(f, "Vis"),
            MetaVarKind::Guard =>
                ::core::fmt::Formatter::write_str(f, "Guard"),
            MetaVarKind::TT => ::core::fmt::Formatter::write_str(f, "TT"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for MetaVarKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for MetaVarKind {
    #[inline]
    fn clone(&self) -> MetaVarKind {
        let _: ::core::clone::AssertParamIsClone<NtPatKind>;
        let _: ::core::clone::AssertParamIsClone<NtExprKind>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for MetaVarKind {
    #[inline]
    fn eq(&self, other: &MetaVarKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (MetaVarKind::Pat(__self_0), MetaVarKind::Pat(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (MetaVarKind::Expr {
                    kind: __self_0,
                    can_begin_literal_maybe_minus: __self_1,
                    can_begin_string_literal: __self_2 }, MetaVarKind::Expr {
                    kind: __arg1_0,
                    can_begin_literal_maybe_minus: __arg1_1,
                    can_begin_string_literal: __arg1_2 }) =>
                    __self_1 == __arg1_1 && __self_2 == __arg1_2 &&
                        __self_0 == __arg1_0,
                (MetaVarKind::Ty { is_path: __self_0 }, MetaVarKind::Ty {
                    is_path: __arg1_0 }) => __self_0 == __arg1_0,
                (MetaVarKind::Meta { has_meta_form: __self_0 },
                    MetaVarKind::Meta { has_meta_form: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MetaVarKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<NtPatKind>;
        let _: ::core::cmp::AssertParamIsEq<NtExprKind>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for MetaVarKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        MetaVarKind::Item => { 0usize }
                        MetaVarKind::Block => { 1usize }
                        MetaVarKind::Stmt => { 2usize }
                        MetaVarKind::Pat(ref __binding_0) => { 3usize }
                        MetaVarKind::Expr {
                            kind: ref __binding_0,
                            can_begin_literal_maybe_minus: ref __binding_1,
                            can_begin_string_literal: ref __binding_2 } => {
                            4usize
                        }
                        MetaVarKind::Ty { is_path: ref __binding_0 } => { 5usize }
                        MetaVarKind::Ident => { 6usize }
                        MetaVarKind::Lifetime => { 7usize }
                        MetaVarKind::Literal => { 8usize }
                        MetaVarKind::Meta { has_meta_form: ref __binding_0 } => {
                            9usize
                        }
                        MetaVarKind::Path => { 10usize }
                        MetaVarKind::Vis => { 11usize }
                        MetaVarKind::Guard => { 12usize }
                        MetaVarKind::TT => { 13usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    MetaVarKind::Item => {}
                    MetaVarKind::Block => {}
                    MetaVarKind::Stmt => {}
                    MetaVarKind::Pat(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    MetaVarKind::Expr {
                        kind: ref __binding_0,
                        can_begin_literal_maybe_minus: ref __binding_1,
                        can_begin_string_literal: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    MetaVarKind::Ty { is_path: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    MetaVarKind::Ident => {}
                    MetaVarKind::Lifetime => {}
                    MetaVarKind::Literal => {}
                    MetaVarKind::Meta { has_meta_form: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    MetaVarKind::Path => {}
                    MetaVarKind::Vis => {}
                    MetaVarKind::Guard => {}
                    MetaVarKind::TT => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for MetaVarKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { MetaVarKind::Item }
                    1usize => { MetaVarKind::Block }
                    2usize => { MetaVarKind::Stmt }
                    3usize => {
                        MetaVarKind::Pat(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        MetaVarKind::Expr {
                            kind: ::rustc_serialize::Decodable::decode(__decoder),
                            can_begin_literal_maybe_minus: ::rustc_serialize::Decodable::decode(__decoder),
                            can_begin_string_literal: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    5usize => {
                        MetaVarKind::Ty {
                            is_path: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    6usize => { MetaVarKind::Ident }
                    7usize => { MetaVarKind::Lifetime }
                    8usize => { MetaVarKind::Literal }
                    9usize => {
                        MetaVarKind::Meta {
                            has_meta_form: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    10usize => { MetaVarKind::Path }
                    11usize => { MetaVarKind::Vis }
                    12usize => { MetaVarKind::Guard }
                    13usize => { MetaVarKind::TT }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `MetaVarKind`, expected 0..14, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for MetaVarKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            MetaVarKind::Pat(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            MetaVarKind::Expr {
                kind: __self_0,
                can_begin_literal_maybe_minus: __self_1,
                can_begin_string_literal: __self_2 } => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            MetaVarKind::Ty { is_path: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            MetaVarKind::Meta { has_meta_form: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for MetaVarKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    MetaVarKind::Item => {}
                    MetaVarKind::Block => {}
                    MetaVarKind::Stmt => {}
                    MetaVarKind::Pat(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    MetaVarKind::Expr {
                        kind: ref __binding_0,
                        can_begin_literal_maybe_minus: ref __binding_1,
                        can_begin_string_literal: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                    MetaVarKind::Ty { is_path: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    MetaVarKind::Ident => {}
                    MetaVarKind::Lifetime => {}
                    MetaVarKind::Literal => {}
                    MetaVarKind::Meta { has_meta_form: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    MetaVarKind::Path => {}
                    MetaVarKind::Vis => {}
                    MetaVarKind::Guard => {}
                    MetaVarKind::TT => {}
                }
            }
        }
    };HashStable_Generic)]
73pub enum MetaVarKind {
74    Item,
75    Block,
76    Stmt,
77    Pat(NtPatKind),
78    Expr {
79        kind: NtExprKind,
80        // This field is needed for `Token::can_begin_literal_maybe_minus`.
81        can_begin_literal_maybe_minus: bool,
82        // This field is needed for `Token::can_begin_string_literal`.
83        can_begin_string_literal: bool,
84    },
85    Ty {
86        is_path: bool,
87    },
88    Ident,
89    Lifetime,
90    Literal,
91    Meta {
92        /// Will `AttrItem::meta` succeed on this, if reparsed?
93        has_meta_form: bool,
94    },
95    Path,
96    Vis,
97    Guard,
98    TT,
99}
100
101impl fmt::Display for MetaVarKind {
102    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103        let sym = match self {
104            MetaVarKind::Item => sym::item,
105            MetaVarKind::Block => sym::block,
106            MetaVarKind::Stmt => sym::stmt,
107            MetaVarKind::Pat(PatParam { inferred: true } | PatWithOr) => sym::pat,
108            MetaVarKind::Pat(PatParam { inferred: false }) => sym::pat_param,
109            MetaVarKind::Expr { kind: Expr2021 { inferred: true } | Expr, .. } => sym::expr,
110            MetaVarKind::Expr { kind: Expr2021 { inferred: false }, .. } => sym::expr_2021,
111            MetaVarKind::Ty { .. } => sym::ty,
112            MetaVarKind::Ident => sym::ident,
113            MetaVarKind::Lifetime => sym::lifetime,
114            MetaVarKind::Literal => sym::literal,
115            MetaVarKind::Meta { .. } => sym::meta,
116            MetaVarKind::Path => sym::path,
117            MetaVarKind::Vis => sym::vis,
118            MetaVarKind::Guard => sym::guard,
119            MetaVarKind::TT => sym::tt,
120        };
121        f.write_fmt(format_args!("{0}", sym))write!(f, "{sym}")
122    }
123}
124
125/// Describes how a sequence of token trees is delimited.
126/// Cannot use `proc_macro::Delimiter` directly because this
127/// structure should implement some additional traits.
128#[derive(#[automatically_derived]
impl ::core::marker::Copy for Delimiter { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Delimiter {
    #[inline]
    fn clone(&self) -> Delimiter {
        let _: ::core::clone::AssertParamIsClone<InvisibleOrigin>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Delimiter {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Delimiter::Parenthesis =>
                ::core::fmt::Formatter::write_str(f, "Parenthesis"),
            Delimiter::Brace => ::core::fmt::Formatter::write_str(f, "Brace"),
            Delimiter::Bracket =>
                ::core::fmt::Formatter::write_str(f, "Bracket"),
            Delimiter::Invisible(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Invisible", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for Delimiter {
    #[inline]
    fn eq(&self, other: &Delimiter) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Delimiter::Invisible(__self_0),
                    Delimiter::Invisible(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Delimiter {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<InvisibleOrigin>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Delimiter {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            Delimiter::Invisible(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Delimiter {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Delimiter::Parenthesis => { 0usize }
                        Delimiter::Brace => { 1usize }
                        Delimiter::Bracket => { 2usize }
                        Delimiter::Invisible(ref __binding_0) => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Delimiter::Parenthesis => {}
                    Delimiter::Brace => {}
                    Delimiter::Bracket => {}
                    Delimiter::Invisible(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Delimiter {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Delimiter::Parenthesis }
                    1usize => { Delimiter::Brace }
                    2usize => { Delimiter::Bracket }
                    3usize => {
                        Delimiter::Invisible(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Delimiter`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for Delimiter where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    Delimiter::Parenthesis => {}
                    Delimiter::Brace => {}
                    Delimiter::Bracket => {}
                    Delimiter::Invisible(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
129pub enum Delimiter {
130    /// `( ... )`
131    Parenthesis,
132    /// `{ ... }`
133    Brace,
134    /// `[ ... ]`
135    Bracket,
136    /// `∅ ... ∅`
137    /// An invisible delimiter, that may, for example, appear around tokens coming from a
138    /// "macro variable" `$var`. It is important to preserve operator priorities in cases like
139    /// `$var * 3` where `$var` is `1 + 2`.
140    /// Invisible delimiters might not survive roundtrip of a token stream through a string.
141    Invisible(InvisibleOrigin),
142}
143
144impl Delimiter {
145    // Should the parser skip these delimiters? Only happens for certain kinds
146    // of invisible delimiters. Ideally this function will eventually disappear
147    // and no invisible delimiters will be skipped.
148    #[inline]
149    pub fn skip(&self) -> bool {
150        match self {
151            Delimiter::Parenthesis | Delimiter::Bracket | Delimiter::Brace => false,
152            Delimiter::Invisible(origin) => origin.skip(),
153        }
154    }
155
156    // This exists because `InvisibleOrigin`s should not be compared. It is only used for
157    // assertions.
158    pub fn eq_ignoring_invisible_origin(&self, other: &Delimiter) -> bool {
159        match (self, other) {
160            (Delimiter::Parenthesis, Delimiter::Parenthesis) => true,
161            (Delimiter::Brace, Delimiter::Brace) => true,
162            (Delimiter::Bracket, Delimiter::Bracket) => true,
163            (Delimiter::Invisible(_), Delimiter::Invisible(_)) => true,
164            _ => false,
165        }
166    }
167
168    pub fn as_open_token_kind(&self) -> TokenKind {
169        match *self {
170            Delimiter::Parenthesis => OpenParen,
171            Delimiter::Brace => OpenBrace,
172            Delimiter::Bracket => OpenBracket,
173            Delimiter::Invisible(origin) => OpenInvisible(origin),
174        }
175    }
176
177    pub fn as_close_token_kind(&self) -> TokenKind {
178        match *self {
179            Delimiter::Parenthesis => CloseParen,
180            Delimiter::Brace => CloseBrace,
181            Delimiter::Bracket => CloseBracket,
182            Delimiter::Invisible(origin) => CloseInvisible(origin),
183        }
184    }
185}
186
187// Note that the suffix is *not* considered when deciding the `LitKind` in this
188// type. This means that float literals like `1f32` are classified by this type
189// as `Int`. Only upon conversion to `ast::LitKind` will such a literal be
190// given the `Float` kind.
191#[derive(#[automatically_derived]
impl ::core::clone::Clone for LitKind {
    #[inline]
    fn clone(&self) -> LitKind {
        let _: ::core::clone::AssertParamIsClone<u8>;
        let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LitKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for LitKind {
    #[inline]
    fn eq(&self, other: &LitKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (LitKind::StrRaw(__self_0), LitKind::StrRaw(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (LitKind::ByteStrRaw(__self_0), LitKind::ByteStrRaw(__arg1_0))
                    => __self_0 == __arg1_0,
                (LitKind::CStrRaw(__self_0), LitKind::CStrRaw(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (LitKind::Err(__self_0), LitKind::Err(__arg1_0)) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LitKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<u8>;
        let _: ::core::cmp::AssertParamIsEq<ErrorGuaranteed>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for LitKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            LitKind::StrRaw(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            LitKind::ByteStrRaw(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            LitKind::CStrRaw(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            LitKind::Err(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for LitKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        LitKind::Bool => { 0usize }
                        LitKind::Byte => { 1usize }
                        LitKind::Char => { 2usize }
                        LitKind::Integer => { 3usize }
                        LitKind::Float => { 4usize }
                        LitKind::Str => { 5usize }
                        LitKind::StrRaw(ref __binding_0) => { 6usize }
                        LitKind::ByteStr => { 7usize }
                        LitKind::ByteStrRaw(ref __binding_0) => { 8usize }
                        LitKind::CStr => { 9usize }
                        LitKind::CStrRaw(ref __binding_0) => { 10usize }
                        LitKind::Err(ref __binding_0) => { 11usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    LitKind::Bool => {}
                    LitKind::Byte => {}
                    LitKind::Char => {}
                    LitKind::Integer => {}
                    LitKind::Float => {}
                    LitKind::Str => {}
                    LitKind::StrRaw(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    LitKind::ByteStr => {}
                    LitKind::ByteStrRaw(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    LitKind::CStr => {}
                    LitKind::CStrRaw(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    LitKind::Err(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for LitKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { LitKind::Bool }
                    1usize => { LitKind::Byte }
                    2usize => { LitKind::Char }
                    3usize => { LitKind::Integer }
                    4usize => { LitKind::Float }
                    5usize => { LitKind::Str }
                    6usize => {
                        LitKind::StrRaw(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    7usize => { LitKind::ByteStr }
                    8usize => {
                        LitKind::ByteStrRaw(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    9usize => { LitKind::CStr }
                    10usize => {
                        LitKind::CStrRaw(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    11usize => {
                        LitKind::Err(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `LitKind`, expected 0..12, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for LitKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LitKind::Bool => ::core::fmt::Formatter::write_str(f, "Bool"),
            LitKind::Byte => ::core::fmt::Formatter::write_str(f, "Byte"),
            LitKind::Char => ::core::fmt::Formatter::write_str(f, "Char"),
            LitKind::Integer =>
                ::core::fmt::Formatter::write_str(f, "Integer"),
            LitKind::Float => ::core::fmt::Formatter::write_str(f, "Float"),
            LitKind::Str => ::core::fmt::Formatter::write_str(f, "Str"),
            LitKind::StrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "StrRaw",
                    &__self_0),
            LitKind::ByteStr =>
                ::core::fmt::Formatter::write_str(f, "ByteStr"),
            LitKind::ByteStrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ByteStrRaw", &__self_0),
            LitKind::CStr => ::core::fmt::Formatter::write_str(f, "CStr"),
            LitKind::CStrRaw(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "CStrRaw", &__self_0),
            LitKind::Err(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Err",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for LitKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    LitKind::Bool => {}
                    LitKind::Byte => {}
                    LitKind::Char => {}
                    LitKind::Integer => {}
                    LitKind::Float => {}
                    LitKind::Str => {}
                    LitKind::StrRaw(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    LitKind::ByteStr => {}
                    LitKind::ByteStrRaw(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    LitKind::CStr => {}
                    LitKind::CStrRaw(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    LitKind::Err(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
192pub enum LitKind {
193    Bool, // AST only, must never appear in a `Token`
194    Byte,
195    Char,
196    Integer, // e.g. `1`, `1u8`, `1f32`
197    Float,   // e.g. `1.`, `1.0`, `1e3f32`
198    Str,
199    StrRaw(u8), // raw string delimited by `n` hash symbols
200    ByteStr,
201    ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
202    CStr,
203    CStrRaw(u8),
204    Err(ErrorGuaranteed),
205}
206
207/// A literal token.
208#[derive(#[automatically_derived]
impl ::core::clone::Clone for Lit {
    #[inline]
    fn clone(&self) -> Lit {
        let _: ::core::clone::AssertParamIsClone<LitKind>;
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        let _: ::core::clone::AssertParamIsClone<Option<Symbol>>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Lit { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Lit {
    #[inline]
    fn eq(&self, other: &Lit) -> bool {
        self.kind == other.kind && self.symbol == other.symbol &&
            self.suffix == other.suffix
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Lit {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<LitKind>;
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<Option<Symbol>>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Lit {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.kind, state);
        ::core::hash::Hash::hash(&self.symbol, state);
        ::core::hash::Hash::hash(&self.suffix, state)
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Lit {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    Lit {
                        kind: ref __binding_0,
                        symbol: ref __binding_1,
                        suffix: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Lit {
            fn decode(__decoder: &mut __D) -> Self {
                Lit {
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                    symbol: ::rustc_serialize::Decodable::decode(__decoder),
                    suffix: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for Lit {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "Lit", "kind",
            &self.kind, "symbol", &self.symbol, "suffix", &&self.suffix)
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for Lit where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    Lit {
                        kind: ref __binding_0,
                        symbol: ref __binding_1,
                        suffix: ref __binding_2 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
209pub struct Lit {
210    pub kind: LitKind,
211    pub symbol: Symbol,
212    pub suffix: Option<Symbol>,
213}
214
215impl Lit {
216    pub fn new(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Lit {
217        Lit { kind, symbol, suffix }
218    }
219
220    /// Returns `true` if this is semantically a float literal. This includes
221    /// ones like `1f32` that have an `Integer` kind but a float suffix.
222    pub fn is_semantic_float(&self) -> bool {
223        match self.kind {
224            LitKind::Float => true,
225            LitKind::Integer => match self.suffix {
226                Some(sym) => sym == sym::f32 || sym == sym::f64,
227                None => false,
228            },
229            _ => false,
230        }
231    }
232
233    /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
234    /// `Parser::eat_token_lit` (excluding unary negation).
235    pub fn from_token(token: &Token) -> Option<Lit> {
236        match token.uninterpolate().kind {
237            Ident(name, IdentIsRaw::No) if name.is_bool_lit() => Some(Lit::new(Bool, name, None)),
238            Literal(token_lit) => Some(token_lit),
239            OpenInvisible(InvisibleOrigin::MetaVar(
240                MetaVarKind::Literal | MetaVarKind::Expr { .. },
241            )) => {
242                // Unreachable with the current test suite.
243                { ::core::panicking::panic_fmt(format_args!("from_token metavar")); };panic!("from_token metavar");
244            }
245            _ => None,
246        }
247    }
248}
249
250impl fmt::Display for Lit {
251    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
252        let Lit { kind, symbol, suffix } = *self;
253        match kind {
254            Byte => f.write_fmt(format_args!("b\'{0}\'", symbol))write!(f, "b'{symbol}'")?,
255            Char => f.write_fmt(format_args!("\'{0}\'", symbol))write!(f, "'{symbol}'")?,
256            Str => f.write_fmt(format_args!("\"{0}\"", symbol))write!(f, "\"{symbol}\"")?,
257            StrRaw(n) => f.write_fmt(format_args!("r{0}\"{1}\"{0}", "#".repeat(n as usize), symbol))write!(
258                f,
259                "r{delim}\"{string}\"{delim}",
260                delim = "#".repeat(n as usize),
261                string = symbol
262            )?,
263            ByteStr => f.write_fmt(format_args!("b\"{0}\"", symbol))write!(f, "b\"{symbol}\"")?,
264            ByteStrRaw(n) => f.write_fmt(format_args!("br{0}\"{1}\"{0}", "#".repeat(n as usize), symbol))write!(
265                f,
266                "br{delim}\"{string}\"{delim}",
267                delim = "#".repeat(n as usize),
268                string = symbol
269            )?,
270            CStr => f.write_fmt(format_args!("c\"{0}\"", symbol))write!(f, "c\"{symbol}\"")?,
271            CStrRaw(n) => {
272                f.write_fmt(format_args!("cr{0}\"{1}\"{0}", "#".repeat(n as usize), symbol))write!(f, "cr{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))?
273            }
274            Integer | Float | Bool | Err(_) => f.write_fmt(format_args!("{0}", symbol))write!(f, "{symbol}")?,
275        }
276
277        if let Some(suffix) = suffix {
278            f.write_fmt(format_args!("{0}", suffix))write!(f, "{suffix}")?;
279        }
280
281        Ok(())
282    }
283}
284
285impl LitKind {
286    /// An English article for the literal token kind.
287    pub fn article(self) -> &'static str {
288        match self {
289            Integer | Err(_) => "an",
290            _ => "a",
291        }
292    }
293
294    pub fn descr(self) -> &'static str {
295        match self {
296            Bool => "boolean",
297            Byte => "byte",
298            Char => "char",
299            Integer => "integer",
300            Float => "float",
301            Str | StrRaw(..) => "string",
302            ByteStr | ByteStrRaw(..) => "byte string",
303            CStr | CStrRaw(..) => "C string",
304            Err(_) => "error",
305        }
306    }
307
308    pub(crate) fn may_have_suffix(self) -> bool {
309        #[allow(non_exhaustive_omitted_patterns)] match self {
    Integer | Float | Err(_) => true,
    _ => false,
}matches!(self, Integer | Float | Err(_))
310    }
311}
312
313pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
314    let ident_token = Token::new(Ident(name, is_raw), span);
315
316    !ident_token.is_reserved_ident()
317        || ident_token.is_path_segment_keyword()
318        || [
319            kw::Async,
320            kw::Do,
321            kw::Box,
322            kw::Break,
323            kw::Const,
324            kw::Continue,
325            kw::False,
326            kw::For,
327            kw::Gen,
328            kw::If,
329            kw::Let,
330            kw::Loop,
331            kw::Match,
332            kw::Move,
333            kw::Return,
334            kw::True,
335            kw::Try,
336            kw::Unsafe,
337            kw::While,
338            kw::Yield,
339            kw::Safe,
340            kw::Static,
341        ]
342        .contains(&name)
343}
344
345fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool {
346    let ident_token = Token::new(Ident(name, is_raw), span);
347
348    !ident_token.is_reserved_ident()
349        || ident_token.is_path_segment_keyword()
350        || [kw::Underscore, kw::For, kw::Impl, kw::Fn, kw::Unsafe, kw::Extern, kw::Typeof, kw::Dyn]
351            .contains(&name)
352}
353
354#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for IdentIsRaw {
    #[inline]
    fn eq(&self, other: &IdentIsRaw) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for IdentIsRaw {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {}
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for IdentIsRaw {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        IdentIsRaw::No => { 0usize }
                        IdentIsRaw::Yes => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self { IdentIsRaw::No => {} IdentIsRaw::Yes => {} }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for IdentIsRaw {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { IdentIsRaw::No }
                    1usize => { IdentIsRaw::Yes }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `IdentIsRaw`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for IdentIsRaw {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state)
    }
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for IdentIsRaw {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self { IdentIsRaw::No => "No", IdentIsRaw::Yes => "Yes", })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for IdentIsRaw { }Copy, #[automatically_derived]
impl ::core::clone::Clone for IdentIsRaw {
    #[inline]
    fn clone(&self) -> IdentIsRaw { *self }
}Clone, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for IdentIsRaw where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self { IdentIsRaw::No => {} IdentIsRaw::Yes => {} }
            }
        }
    };HashStable_Generic)]
355pub enum IdentIsRaw {
356    No,
357    Yes,
358}
359
360impl IdentIsRaw {
361    pub fn to_print_mode_ident(self) -> IdentPrintMode {
362        match self {
363            IdentIsRaw::No => IdentPrintMode::Normal,
364            IdentIsRaw::Yes => IdentPrintMode::RawIdent,
365        }
366    }
367    pub fn to_print_mode_lifetime(self) -> IdentPrintMode {
368        match self {
369            IdentIsRaw::No => IdentPrintMode::Normal,
370            IdentIsRaw::Yes => IdentPrintMode::RawLifetime,
371        }
372    }
373}
374
375impl From<bool> for IdentIsRaw {
376    fn from(b: bool) -> Self {
377        if b { Self::Yes } else { Self::No }
378    }
379}
380
381#[derive(#[automatically_derived]
impl ::core::clone::Clone for TokenKind {
    #[inline]
    fn clone(&self) -> TokenKind {
        let _: ::core::clone::AssertParamIsClone<InvisibleOrigin>;
        let _: ::core::clone::AssertParamIsClone<Lit>;
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        let _: ::core::clone::AssertParamIsClone<IdentIsRaw>;
        let _: ::core::clone::AssertParamIsClone<Ident>;
        let _: ::core::clone::AssertParamIsClone<CommentKind>;
        let _: ::core::clone::AssertParamIsClone<ast::AttrStyle>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for TokenKind { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for TokenKind {
    #[inline]
    fn eq(&self, other: &TokenKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (TokenKind::OpenInvisible(__self_0),
                    TokenKind::OpenInvisible(__arg1_0)) => __self_0 == __arg1_0,
                (TokenKind::CloseInvisible(__self_0),
                    TokenKind::CloseInvisible(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (TokenKind::Literal(__self_0), TokenKind::Literal(__arg1_0))
                    => __self_0 == __arg1_0,
                (TokenKind::Ident(__self_0, __self_1),
                    TokenKind::Ident(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (TokenKind::NtIdent(__self_0, __self_1),
                    TokenKind::NtIdent(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (TokenKind::Lifetime(__self_0, __self_1),
                    TokenKind::Lifetime(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (TokenKind::NtLifetime(__self_0, __self_1),
                    TokenKind::NtLifetime(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (TokenKind::DocComment(__self_0, __self_1, __self_2),
                    TokenKind::DocComment(__arg1_0, __arg1_1, __arg1_2)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for TokenKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<InvisibleOrigin>;
        let _: ::core::cmp::AssertParamIsEq<Lit>;
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<IdentIsRaw>;
        let _: ::core::cmp::AssertParamIsEq<Ident>;
        let _: ::core::cmp::AssertParamIsEq<CommentKind>;
        let _: ::core::cmp::AssertParamIsEq<ast::AttrStyle>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for TokenKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            TokenKind::OpenInvisible(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            TokenKind::CloseInvisible(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            TokenKind::Literal(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            TokenKind::Ident(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            TokenKind::NtIdent(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            TokenKind::Lifetime(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            TokenKind::NtLifetime(__self_0, __self_1) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state)
            }
            TokenKind::DocComment(__self_0, __self_1, __self_2) => {
                ::core::hash::Hash::hash(__self_0, state);
                ::core::hash::Hash::hash(__self_1, state);
                ::core::hash::Hash::hash(__self_2, state)
            }
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for TokenKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        TokenKind::Eq => { 0usize }
                        TokenKind::Lt => { 1usize }
                        TokenKind::Le => { 2usize }
                        TokenKind::EqEq => { 3usize }
                        TokenKind::Ne => { 4usize }
                        TokenKind::Ge => { 5usize }
                        TokenKind::Gt => { 6usize }
                        TokenKind::AndAnd => { 7usize }
                        TokenKind::OrOr => { 8usize }
                        TokenKind::Bang => { 9usize }
                        TokenKind::Tilde => { 10usize }
                        TokenKind::Plus => { 11usize }
                        TokenKind::Minus => { 12usize }
                        TokenKind::Star => { 13usize }
                        TokenKind::Slash => { 14usize }
                        TokenKind::Percent => { 15usize }
                        TokenKind::Caret => { 16usize }
                        TokenKind::And => { 17usize }
                        TokenKind::Or => { 18usize }
                        TokenKind::Shl => { 19usize }
                        TokenKind::Shr => { 20usize }
                        TokenKind::PlusEq => { 21usize }
                        TokenKind::MinusEq => { 22usize }
                        TokenKind::StarEq => { 23usize }
                        TokenKind::SlashEq => { 24usize }
                        TokenKind::PercentEq => { 25usize }
                        TokenKind::CaretEq => { 26usize }
                        TokenKind::AndEq => { 27usize }
                        TokenKind::OrEq => { 28usize }
                        TokenKind::ShlEq => { 29usize }
                        TokenKind::ShrEq => { 30usize }
                        TokenKind::At => { 31usize }
                        TokenKind::Dot => { 32usize }
                        TokenKind::DotDot => { 33usize }
                        TokenKind::DotDotDot => { 34usize }
                        TokenKind::DotDotEq => { 35usize }
                        TokenKind::Comma => { 36usize }
                        TokenKind::Semi => { 37usize }
                        TokenKind::Colon => { 38usize }
                        TokenKind::PathSep => { 39usize }
                        TokenKind::RArrow => { 40usize }
                        TokenKind::LArrow => { 41usize }
                        TokenKind::FatArrow => { 42usize }
                        TokenKind::Pound => { 43usize }
                        TokenKind::Dollar => { 44usize }
                        TokenKind::Question => { 45usize }
                        TokenKind::SingleQuote => { 46usize }
                        TokenKind::OpenParen => { 47usize }
                        TokenKind::CloseParen => { 48usize }
                        TokenKind::OpenBrace => { 49usize }
                        TokenKind::CloseBrace => { 50usize }
                        TokenKind::OpenBracket => { 51usize }
                        TokenKind::CloseBracket => { 52usize }
                        TokenKind::OpenInvisible(ref __binding_0) => { 53usize }
                        TokenKind::CloseInvisible(ref __binding_0) => { 54usize }
                        TokenKind::Literal(ref __binding_0) => { 55usize }
                        TokenKind::Ident(ref __binding_0, ref __binding_1) => {
                            56usize
                        }
                        TokenKind::NtIdent(ref __binding_0, ref __binding_1) => {
                            57usize
                        }
                        TokenKind::Lifetime(ref __binding_0, ref __binding_1) => {
                            58usize
                        }
                        TokenKind::NtLifetime(ref __binding_0, ref __binding_1) => {
                            59usize
                        }
                        TokenKind::DocComment(ref __binding_0, ref __binding_1,
                            ref __binding_2) => {
                            60usize
                        }
                        TokenKind::Eof => { 61usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    TokenKind::Eq => {}
                    TokenKind::Lt => {}
                    TokenKind::Le => {}
                    TokenKind::EqEq => {}
                    TokenKind::Ne => {}
                    TokenKind::Ge => {}
                    TokenKind::Gt => {}
                    TokenKind::AndAnd => {}
                    TokenKind::OrOr => {}
                    TokenKind::Bang => {}
                    TokenKind::Tilde => {}
                    TokenKind::Plus => {}
                    TokenKind::Minus => {}
                    TokenKind::Star => {}
                    TokenKind::Slash => {}
                    TokenKind::Percent => {}
                    TokenKind::Caret => {}
                    TokenKind::And => {}
                    TokenKind::Or => {}
                    TokenKind::Shl => {}
                    TokenKind::Shr => {}
                    TokenKind::PlusEq => {}
                    TokenKind::MinusEq => {}
                    TokenKind::StarEq => {}
                    TokenKind::SlashEq => {}
                    TokenKind::PercentEq => {}
                    TokenKind::CaretEq => {}
                    TokenKind::AndEq => {}
                    TokenKind::OrEq => {}
                    TokenKind::ShlEq => {}
                    TokenKind::ShrEq => {}
                    TokenKind::At => {}
                    TokenKind::Dot => {}
                    TokenKind::DotDot => {}
                    TokenKind::DotDotDot => {}
                    TokenKind::DotDotEq => {}
                    TokenKind::Comma => {}
                    TokenKind::Semi => {}
                    TokenKind::Colon => {}
                    TokenKind::PathSep => {}
                    TokenKind::RArrow => {}
                    TokenKind::LArrow => {}
                    TokenKind::FatArrow => {}
                    TokenKind::Pound => {}
                    TokenKind::Dollar => {}
                    TokenKind::Question => {}
                    TokenKind::SingleQuote => {}
                    TokenKind::OpenParen => {}
                    TokenKind::CloseParen => {}
                    TokenKind::OpenBrace => {}
                    TokenKind::CloseBrace => {}
                    TokenKind::OpenBracket => {}
                    TokenKind::CloseBracket => {}
                    TokenKind::OpenInvisible(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TokenKind::CloseInvisible(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TokenKind::Literal(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    TokenKind::Ident(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TokenKind::NtIdent(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TokenKind::Lifetime(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TokenKind::NtLifetime(ref __binding_0, ref __binding_1) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    TokenKind::DocComment(ref __binding_0, ref __binding_1,
                        ref __binding_2) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                    TokenKind::Eof => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for TokenKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { TokenKind::Eq }
                    1usize => { TokenKind::Lt }
                    2usize => { TokenKind::Le }
                    3usize => { TokenKind::EqEq }
                    4usize => { TokenKind::Ne }
                    5usize => { TokenKind::Ge }
                    6usize => { TokenKind::Gt }
                    7usize => { TokenKind::AndAnd }
                    8usize => { TokenKind::OrOr }
                    9usize => { TokenKind::Bang }
                    10usize => { TokenKind::Tilde }
                    11usize => { TokenKind::Plus }
                    12usize => { TokenKind::Minus }
                    13usize => { TokenKind::Star }
                    14usize => { TokenKind::Slash }
                    15usize => { TokenKind::Percent }
                    16usize => { TokenKind::Caret }
                    17usize => { TokenKind::And }
                    18usize => { TokenKind::Or }
                    19usize => { TokenKind::Shl }
                    20usize => { TokenKind::Shr }
                    21usize => { TokenKind::PlusEq }
                    22usize => { TokenKind::MinusEq }
                    23usize => { TokenKind::StarEq }
                    24usize => { TokenKind::SlashEq }
                    25usize => { TokenKind::PercentEq }
                    26usize => { TokenKind::CaretEq }
                    27usize => { TokenKind::AndEq }
                    28usize => { TokenKind::OrEq }
                    29usize => { TokenKind::ShlEq }
                    30usize => { TokenKind::ShrEq }
                    31usize => { TokenKind::At }
                    32usize => { TokenKind::Dot }
                    33usize => { TokenKind::DotDot }
                    34usize => { TokenKind::DotDotDot }
                    35usize => { TokenKind::DotDotEq }
                    36usize => { TokenKind::Comma }
                    37usize => { TokenKind::Semi }
                    38usize => { TokenKind::Colon }
                    39usize => { TokenKind::PathSep }
                    40usize => { TokenKind::RArrow }
                    41usize => { TokenKind::LArrow }
                    42usize => { TokenKind::FatArrow }
                    43usize => { TokenKind::Pound }
                    44usize => { TokenKind::Dollar }
                    45usize => { TokenKind::Question }
                    46usize => { TokenKind::SingleQuote }
                    47usize => { TokenKind::OpenParen }
                    48usize => { TokenKind::CloseParen }
                    49usize => { TokenKind::OpenBrace }
                    50usize => { TokenKind::CloseBrace }
                    51usize => { TokenKind::OpenBracket }
                    52usize => { TokenKind::CloseBracket }
                    53usize => {
                        TokenKind::OpenInvisible(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    54usize => {
                        TokenKind::CloseInvisible(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    55usize => {
                        TokenKind::Literal(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    56usize => {
                        TokenKind::Ident(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    57usize => {
                        TokenKind::NtIdent(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    58usize => {
                        TokenKind::Lifetime(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    59usize => {
                        TokenKind::NtLifetime(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    60usize => {
                        TokenKind::DocComment(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    61usize => { TokenKind::Eof }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `TokenKind`, expected 0..62, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for TokenKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            TokenKind::Eq => ::core::fmt::Formatter::write_str(f, "Eq"),
            TokenKind::Lt => ::core::fmt::Formatter::write_str(f, "Lt"),
            TokenKind::Le => ::core::fmt::Formatter::write_str(f, "Le"),
            TokenKind::EqEq => ::core::fmt::Formatter::write_str(f, "EqEq"),
            TokenKind::Ne => ::core::fmt::Formatter::write_str(f, "Ne"),
            TokenKind::Ge => ::core::fmt::Formatter::write_str(f, "Ge"),
            TokenKind::Gt => ::core::fmt::Formatter::write_str(f, "Gt"),
            TokenKind::AndAnd =>
                ::core::fmt::Formatter::write_str(f, "AndAnd"),
            TokenKind::OrOr => ::core::fmt::Formatter::write_str(f, "OrOr"),
            TokenKind::Bang => ::core::fmt::Formatter::write_str(f, "Bang"),
            TokenKind::Tilde => ::core::fmt::Formatter::write_str(f, "Tilde"),
            TokenKind::Plus => ::core::fmt::Formatter::write_str(f, "Plus"),
            TokenKind::Minus => ::core::fmt::Formatter::write_str(f, "Minus"),
            TokenKind::Star => ::core::fmt::Formatter::write_str(f, "Star"),
            TokenKind::Slash => ::core::fmt::Formatter::write_str(f, "Slash"),
            TokenKind::Percent =>
                ::core::fmt::Formatter::write_str(f, "Percent"),
            TokenKind::Caret => ::core::fmt::Formatter::write_str(f, "Caret"),
            TokenKind::And => ::core::fmt::Formatter::write_str(f, "And"),
            TokenKind::Or => ::core::fmt::Formatter::write_str(f, "Or"),
            TokenKind::Shl => ::core::fmt::Formatter::write_str(f, "Shl"),
            TokenKind::Shr => ::core::fmt::Formatter::write_str(f, "Shr"),
            TokenKind::PlusEq =>
                ::core::fmt::Formatter::write_str(f, "PlusEq"),
            TokenKind::MinusEq =>
                ::core::fmt::Formatter::write_str(f, "MinusEq"),
            TokenKind::StarEq =>
                ::core::fmt::Formatter::write_str(f, "StarEq"),
            TokenKind::SlashEq =>
                ::core::fmt::Formatter::write_str(f, "SlashEq"),
            TokenKind::PercentEq =>
                ::core::fmt::Formatter::write_str(f, "PercentEq"),
            TokenKind::CaretEq =>
                ::core::fmt::Formatter::write_str(f, "CaretEq"),
            TokenKind::AndEq => ::core::fmt::Formatter::write_str(f, "AndEq"),
            TokenKind::OrEq => ::core::fmt::Formatter::write_str(f, "OrEq"),
            TokenKind::ShlEq => ::core::fmt::Formatter::write_str(f, "ShlEq"),
            TokenKind::ShrEq => ::core::fmt::Formatter::write_str(f, "ShrEq"),
            TokenKind::At => ::core::fmt::Formatter::write_str(f, "At"),
            TokenKind::Dot => ::core::fmt::Formatter::write_str(f, "Dot"),
            TokenKind::DotDot =>
                ::core::fmt::Formatter::write_str(f, "DotDot"),
            TokenKind::DotDotDot =>
                ::core::fmt::Formatter::write_str(f, "DotDotDot"),
            TokenKind::DotDotEq =>
                ::core::fmt::Formatter::write_str(f, "DotDotEq"),
            TokenKind::Comma => ::core::fmt::Formatter::write_str(f, "Comma"),
            TokenKind::Semi => ::core::fmt::Formatter::write_str(f, "Semi"),
            TokenKind::Colon => ::core::fmt::Formatter::write_str(f, "Colon"),
            TokenKind::PathSep =>
                ::core::fmt::Formatter::write_str(f, "PathSep"),
            TokenKind::RArrow =>
                ::core::fmt::Formatter::write_str(f, "RArrow"),
            TokenKind::LArrow =>
                ::core::fmt::Formatter::write_str(f, "LArrow"),
            TokenKind::FatArrow =>
                ::core::fmt::Formatter::write_str(f, "FatArrow"),
            TokenKind::Pound => ::core::fmt::Formatter::write_str(f, "Pound"),
            TokenKind::Dollar =>
                ::core::fmt::Formatter::write_str(f, "Dollar"),
            TokenKind::Question =>
                ::core::fmt::Formatter::write_str(f, "Question"),
            TokenKind::SingleQuote =>
                ::core::fmt::Formatter::write_str(f, "SingleQuote"),
            TokenKind::OpenParen =>
                ::core::fmt::Formatter::write_str(f, "OpenParen"),
            TokenKind::CloseParen =>
                ::core::fmt::Formatter::write_str(f, "CloseParen"),
            TokenKind::OpenBrace =>
                ::core::fmt::Formatter::write_str(f, "OpenBrace"),
            TokenKind::CloseBrace =>
                ::core::fmt::Formatter::write_str(f, "CloseBrace"),
            TokenKind::OpenBracket =>
                ::core::fmt::Formatter::write_str(f, "OpenBracket"),
            TokenKind::CloseBracket =>
                ::core::fmt::Formatter::write_str(f, "CloseBracket"),
            TokenKind::OpenInvisible(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "OpenInvisible", &__self_0),
            TokenKind::CloseInvisible(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "CloseInvisible", &__self_0),
            TokenKind::Literal(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Literal", &__self_0),
            TokenKind::Ident(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Ident",
                    __self_0, &__self_1),
            TokenKind::NtIdent(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "NtIdent", __self_0, &__self_1),
            TokenKind::Lifetime(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "Lifetime", __self_0, &__self_1),
            TokenKind::NtLifetime(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "NtLifetime", __self_0, &__self_1),
            TokenKind::DocComment(__self_0, __self_1, __self_2) =>
                ::core::fmt::Formatter::debug_tuple_field3_finish(f,
                    "DocComment", __self_0, __self_1, &__self_2),
            TokenKind::Eof => ::core::fmt::Formatter::write_str(f, "Eof"),
        }
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for TokenKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    TokenKind::Eq => {}
                    TokenKind::Lt => {}
                    TokenKind::Le => {}
                    TokenKind::EqEq => {}
                    TokenKind::Ne => {}
                    TokenKind::Ge => {}
                    TokenKind::Gt => {}
                    TokenKind::AndAnd => {}
                    TokenKind::OrOr => {}
                    TokenKind::Bang => {}
                    TokenKind::Tilde => {}
                    TokenKind::Plus => {}
                    TokenKind::Minus => {}
                    TokenKind::Star => {}
                    TokenKind::Slash => {}
                    TokenKind::Percent => {}
                    TokenKind::Caret => {}
                    TokenKind::And => {}
                    TokenKind::Or => {}
                    TokenKind::Shl => {}
                    TokenKind::Shr => {}
                    TokenKind::PlusEq => {}
                    TokenKind::MinusEq => {}
                    TokenKind::StarEq => {}
                    TokenKind::SlashEq => {}
                    TokenKind::PercentEq => {}
                    TokenKind::CaretEq => {}
                    TokenKind::AndEq => {}
                    TokenKind::OrEq => {}
                    TokenKind::ShlEq => {}
                    TokenKind::ShrEq => {}
                    TokenKind::At => {}
                    TokenKind::Dot => {}
                    TokenKind::DotDot => {}
                    TokenKind::DotDotDot => {}
                    TokenKind::DotDotEq => {}
                    TokenKind::Comma => {}
                    TokenKind::Semi => {}
                    TokenKind::Colon => {}
                    TokenKind::PathSep => {}
                    TokenKind::RArrow => {}
                    TokenKind::LArrow => {}
                    TokenKind::FatArrow => {}
                    TokenKind::Pound => {}
                    TokenKind::Dollar => {}
                    TokenKind::Question => {}
                    TokenKind::SingleQuote => {}
                    TokenKind::OpenParen => {}
                    TokenKind::CloseParen => {}
                    TokenKind::OpenBrace => {}
                    TokenKind::CloseBrace => {}
                    TokenKind::OpenBracket => {}
                    TokenKind::CloseBracket => {}
                    TokenKind::OpenInvisible(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::CloseInvisible(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::Literal(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::Ident(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::NtIdent(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::Lifetime(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::NtLifetime(ref __binding_0, ref __binding_1) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::DocComment(ref __binding_0, ref __binding_1,
                        ref __binding_2) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                        { __binding_2.hash_stable(__hcx, __hasher); }
                    }
                    TokenKind::Eof => {}
                }
            }
        }
    };HashStable_Generic)]
382pub enum TokenKind {
383    /* Expression-operator symbols. */
384    /// `=`
385    Eq,
386    /// `<`
387    Lt,
388    /// `<=`
389    Le,
390    /// `==`
391    EqEq,
392    /// `!=`
393    Ne,
394    /// `>=`
395    Ge,
396    /// `>`
397    Gt,
398    /// `&&`
399    AndAnd,
400    /// `||`
401    OrOr,
402    /// `!`
403    Bang,
404    /// `~`
405    Tilde,
406    // `+`
407    Plus,
408    // `-`
409    Minus,
410    // `*`
411    Star,
412    // `/`
413    Slash,
414    // `%`
415    Percent,
416    // `^`
417    Caret,
418    // `&`
419    And,
420    // `|`
421    Or,
422    // `<<`
423    Shl,
424    // `>>`
425    Shr,
426    // `+=`
427    PlusEq,
428    // `-=`
429    MinusEq,
430    // `*=`
431    StarEq,
432    // `/=`
433    SlashEq,
434    // `%=`
435    PercentEq,
436    // `^=`
437    CaretEq,
438    // `&=`
439    AndEq,
440    // `|=`
441    OrEq,
442    // `<<=`
443    ShlEq,
444    // `>>=`
445    ShrEq,
446
447    /* Structural symbols */
448    /// `@`
449    At,
450    /// `.`
451    Dot,
452    /// `..`
453    DotDot,
454    /// `...`
455    DotDotDot,
456    /// `..=`
457    DotDotEq,
458    /// `,`
459    Comma,
460    /// `;`
461    Semi,
462    /// `:`
463    Colon,
464    /// `::`
465    PathSep,
466    /// `->`
467    RArrow,
468    /// `<-`
469    LArrow,
470    /// `=>`
471    FatArrow,
472    /// `#`
473    Pound,
474    /// `$`
475    Dollar,
476    /// `?`
477    Question,
478    /// Used by proc macros for representing lifetimes, not generated by lexer right now.
479    SingleQuote,
480    /// `(`
481    OpenParen,
482    /// `)`
483    CloseParen,
484    /// `{`
485    OpenBrace,
486    /// `}`
487    CloseBrace,
488    /// `[`
489    OpenBracket,
490    /// `]`
491    CloseBracket,
492    /// Invisible opening delimiter, produced by a macro.
493    OpenInvisible(InvisibleOrigin),
494    /// Invisible closing delimiter, produced by a macro.
495    CloseInvisible(InvisibleOrigin),
496
497    /* Literals */
498    Literal(Lit),
499
500    /// Identifier token.
501    /// Do not forget about `NtIdent` when you want to match on identifiers.
502    /// It's recommended to use `Token::{ident,uninterpolate}` and
503    /// `Parser::token_uninterpolated_span` to treat regular and interpolated
504    /// identifiers in the same way.
505    Ident(Symbol, IdentIsRaw),
506    /// This identifier (and its span) is the identifier passed to the
507    /// declarative macro. The span in the surrounding `Token` is the span of
508    /// the `ident` metavariable in the macro's RHS.
509    NtIdent(Ident, IdentIsRaw),
510
511    /// Lifetime identifier token.
512    /// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
513    /// It's recommended to use `Token::{ident,uninterpolate}` and
514    /// `Parser::token_uninterpolated_span` to treat regular and interpolated
515    /// identifiers in the same way.
516    Lifetime(Symbol, IdentIsRaw),
517    /// This identifier (and its span) is the lifetime passed to the
518    /// declarative macro. The span in the surrounding `Token` is the span of
519    /// the `lifetime` metavariable in the macro's RHS.
520    NtLifetime(Ident, IdentIsRaw),
521
522    /// A doc comment token.
523    /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
524    /// similarly to symbols in string literal tokens.
525    DocComment(CommentKind, ast::AttrStyle, Symbol),
526
527    /// End Of File
528    Eof,
529}
530
531#[derive(#[automatically_derived]
impl ::core::clone::Clone for Token {
    #[inline]
    fn clone(&self) -> Token {
        let _: ::core::clone::AssertParamIsClone<TokenKind>;
        let _: ::core::clone::AssertParamIsClone<Span>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Token { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for Token {
    #[inline]
    fn eq(&self, other: &Token) -> bool {
        self.kind == other.kind && self.span == other.span
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Token {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<TokenKind>;
        let _: ::core::cmp::AssertParamIsEq<Span>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for Token {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.kind, state);
        ::core::hash::Hash::hash(&self.span, state)
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Token {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    Token { kind: ref __binding_0, span: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Token {
            fn decode(__decoder: &mut __D) -> Self {
                Token {
                    kind: ::rustc_serialize::Decodable::decode(__decoder),
                    span: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::fmt::Debug for Token {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "Token", "kind",
            &self.kind, "span", &&self.span)
    }
}Debug, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for Token where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                match *self {
                    Token { kind: ref __binding_0, span: ref __binding_1 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                        { __binding_1.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
532pub struct Token {
533    pub kind: TokenKind,
534    pub span: Span,
535}
536
537impl TokenKind {
538    pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> TokenKind {
539        Literal(Lit::new(kind, symbol, suffix))
540    }
541
542    /// An approximation to proc-macro-style single-character operators used by
543    /// rustc parser. If the operator token can be broken into two tokens, the
544    /// first of which has `n` (1 or 2) chars, then this function performs that
545    /// operation, otherwise it returns `None`.
546    pub fn break_two_token_op(&self, n: u32) -> Option<(TokenKind, TokenKind)> {
547        if !(n == 1 || n == 2) {
    ::core::panicking::panic("assertion failed: n == 1 || n == 2")
};assert!(n == 1 || n == 2);
548        Some(match (self, n) {
549            (Le, 1) => (Lt, Eq),
550            (EqEq, 1) => (Eq, Eq),
551            (Ne, 1) => (Bang, Eq),
552            (Ge, 1) => (Gt, Eq),
553            (AndAnd, 1) => (And, And),
554            (OrOr, 1) => (Or, Or),
555            (Shl, 1) => (Lt, Lt),
556            (Shr, 1) => (Gt, Gt),
557            (PlusEq, 1) => (Plus, Eq),
558            (MinusEq, 1) => (Minus, Eq),
559            (StarEq, 1) => (Star, Eq),
560            (SlashEq, 1) => (Slash, Eq),
561            (PercentEq, 1) => (Percent, Eq),
562            (CaretEq, 1) => (Caret, Eq),
563            (AndEq, 1) => (And, Eq),
564            (OrEq, 1) => (Or, Eq),
565            (ShlEq, 1) => (Lt, Le),  // `<` + `<=`
566            (ShlEq, 2) => (Shl, Eq), // `<<` + `=`
567            (ShrEq, 1) => (Gt, Ge),  // `>` + `>=`
568            (ShrEq, 2) => (Shr, Eq), // `>>` + `=`
569            (DotDot, 1) => (Dot, Dot),
570            (DotDotDot, 1) => (Dot, DotDot), // `.` + `..`
571            (DotDotDot, 2) => (DotDot, Dot), // `..` + `.`
572            (DotDotEq, 2) => (DotDot, Eq),
573            (PathSep, 1) => (Colon, Colon),
574            (RArrow, 1) => (Minus, Gt),
575            (LArrow, 1) => (Lt, Minus),
576            (FatArrow, 1) => (Eq, Gt),
577            _ => return None,
578        })
579    }
580
581    /// Returns tokens that are likely to be typed accidentally instead of the current token.
582    /// Enables better error recovery when the wrong token is found.
583    pub fn similar_tokens(&self) -> &[TokenKind] {
584        match self {
585            Comma => &[Dot, Lt, Semi],
586            Semi => &[Colon, Comma],
587            Colon => &[Semi],
588            FatArrow => &[Eq, RArrow, Ge, Gt],
589            _ => &[],
590        }
591    }
592
593    pub fn should_end_const_arg(&self) -> bool {
594        #[allow(non_exhaustive_omitted_patterns)] match self {
    Gt | Ge | Shr | ShrEq => true,
    _ => false,
}matches!(self, Gt | Ge | Shr | ShrEq)
595    }
596
597    pub fn is_delim(&self) -> bool {
598        self.open_delim().is_some() || self.close_delim().is_some()
599    }
600
601    pub fn open_delim(&self) -> Option<Delimiter> {
602        match *self {
603            OpenParen => Some(Delimiter::Parenthesis),
604            OpenBrace => Some(Delimiter::Brace),
605            OpenBracket => Some(Delimiter::Bracket),
606            OpenInvisible(origin) => Some(Delimiter::Invisible(origin)),
607            _ => None,
608        }
609    }
610
611    pub fn close_delim(&self) -> Option<Delimiter> {
612        match *self {
613            CloseParen => Some(Delimiter::Parenthesis),
614            CloseBrace => Some(Delimiter::Brace),
615            CloseBracket => Some(Delimiter::Bracket),
616            CloseInvisible(origin) => Some(Delimiter::Invisible(origin)),
617            _ => None,
618        }
619    }
620
621    pub fn is_close_delim_or_eof(&self) -> bool {
622        match self {
623            CloseParen | CloseBrace | CloseBracket | CloseInvisible(_) | Eof => true,
624            _ => false,
625        }
626    }
627}
628
629impl Token {
630    pub const fn new(kind: TokenKind, span: Span) -> Self {
631        Token { kind, span }
632    }
633
634    /// Some token that will be thrown away later.
635    pub const fn dummy() -> Self {
636        Token::new(TokenKind::Question, DUMMY_SP)
637    }
638
639    /// Recovers a `Token` from an `Ident`. This creates a raw identifier if necessary.
640    pub fn from_ast_ident(ident: Ident) -> Self {
641        Token::new(Ident(ident.name, ident.is_raw_guess().into()), ident.span)
642    }
643
644    pub fn is_range_separator(&self) -> bool {
645        [DotDot, DotDotDot, DotDotEq].contains(&self.kind)
646    }
647
648    pub fn is_punct(&self) -> bool {
649        match self.kind {
650            Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Bang | Tilde | Plus | Minus
651            | Star | Slash | Percent | Caret | And | Or | Shl | Shr | PlusEq | MinusEq | StarEq
652            | SlashEq | PercentEq | CaretEq | AndEq | OrEq | ShlEq | ShrEq | At | Dot | DotDot
653            | DotDotDot | DotDotEq | Comma | Semi | Colon | PathSep | RArrow | LArrow
654            | FatArrow | Pound | Dollar | Question | SingleQuote => true,
655
656            OpenParen | CloseParen | OpenBrace | CloseBrace | OpenBracket | CloseBracket
657            | OpenInvisible(_) | CloseInvisible(_) | Literal(..) | DocComment(..) | Ident(..)
658            | NtIdent(..) | Lifetime(..) | NtLifetime(..) | Eof => false,
659        }
660    }
661
662    pub fn is_like_plus(&self) -> bool {
663        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    Plus | PlusEq => true,
    _ => false,
}matches!(self.kind, Plus | PlusEq)
664    }
665
666    /// Returns `true` if the token can appear at the start of an expression.
667    ///
668    /// **NB**: Take care when modifying this function, since it will change
669    /// the stable set of tokens that are allowed to match an expr nonterminal.
670    pub fn can_begin_expr(&self) -> bool {
671        match self.uninterpolate().kind {
672            Ident(name, is_raw)              =>
673                ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
674            OpenParen                         | // tuple
675            OpenBrace                         | // block
676            OpenBracket                       | // array
677            Literal(..)                       | // literal
678            Bang                              | // operator not
679            Minus                             | // unary minus
680            Star                              | // dereference
681            Or | OrOr                         | // closure
682            And                               | // reference
683            AndAnd                            | // double reference
684            // DotDotDot is no longer supported, but we need some way to display the error
685            DotDot | DotDotDot | DotDotEq     | // range notation
686            Lt | Shl                          | // associated path
687            PathSep                           | // global path
688            Lifetime(..)                      | // labeled loop
689            Pound                             => true, // expression attributes
690            OpenInvisible(InvisibleOrigin::MetaVar(
691                MetaVarKind::Block |
692                MetaVarKind::Expr { .. } |
693                MetaVarKind::Literal |
694                MetaVarKind::Path
695            )) => true,
696            _ => false,
697        }
698    }
699
700    /// Returns `true` if the token can appear at the start of a pattern.
701    ///
702    /// Shamelessly borrowed from `can_begin_expr`, only used for diagnostics right now.
703    pub fn can_begin_pattern(&self, pat_kind: NtPatKind) -> bool {
704        match &self.uninterpolate().kind {
705            // box, ref, mut, and other identifiers (can stricten)
706            Ident(..) | NtIdent(..) |
707            OpenParen |                          // tuple pattern
708            OpenBracket |                        // slice pattern
709            And |                                // reference
710            Minus |                              // negative literal
711            AndAnd |                             // double reference
712            Literal(_) |                         // literal
713            DotDot |                             // range pattern (future compat)
714            DotDotDot |                          // range pattern (future compat)
715            PathSep |                            // path
716            Lt |                                 // path (UFCS constant)
717            Shl => true,                         // path (double UFCS)
718            Or => #[allow(non_exhaustive_omitted_patterns)] match pat_kind {
    PatWithOr => true,
    _ => false,
}matches!(pat_kind, PatWithOr), // leading vert `|` or-pattern
719            OpenInvisible(InvisibleOrigin::MetaVar(
720                MetaVarKind::Expr { .. } |
721                MetaVarKind::Literal |
722                MetaVarKind::Meta { .. } |
723                MetaVarKind::Pat(_) |
724                MetaVarKind::Path |
725                MetaVarKind::Ty { .. }
726            )) => true,
727            _ => false,
728        }
729    }
730
731    /// Returns `true` if the token can appear at the start of a type.
732    pub fn can_begin_type(&self) -> bool {
733        match self.uninterpolate().kind {
734            Ident(name, is_raw) =>
735                ident_can_begin_type(name, self.span, is_raw), // type name or keyword
736            OpenParen                         | // tuple
737            OpenBracket                       | // array
738            Bang                              | // never
739            Star                              | // raw pointer
740            And                               | // reference
741            AndAnd                            | // double reference
742            Question                          | // maybe bound in trait object
743            Lifetime(..)                      | // lifetime bound in trait object
744            Lt | Shl                          | // associated path
745            PathSep => true,                    // global path
746            OpenInvisible(InvisibleOrigin::MetaVar(
747                MetaVarKind::Ty { .. } |
748                MetaVarKind::Path
749            )) => true,
750            // For anonymous structs or unions, which only appear in specific positions
751            // (type of struct fields or union fields), we don't consider them as regular types
752            _ => false,
753        }
754    }
755
756    /// Returns `true` if the token can appear at the start of a const param.
757    pub fn can_begin_const_arg(&self) -> bool {
758        match self.kind {
759            OpenBrace | Literal(..) | Minus => true,
760            Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true,
761            OpenInvisible(InvisibleOrigin::MetaVar(
762                MetaVarKind::Expr { .. } | MetaVarKind::Block | MetaVarKind::Literal,
763            )) => true,
764            _ => false,
765        }
766    }
767
768    /// Returns `true` if the token can appear at the start of an item.
769    pub fn can_begin_item(&self) -> bool {
770        match self.kind {
771            Ident(name, _) => [
772                kw::Fn,
773                kw::Use,
774                kw::Struct,
775                kw::Enum,
776                kw::Pub,
777                kw::Trait,
778                kw::Extern,
779                kw::Impl,
780                kw::Unsafe,
781                kw::Const,
782                kw::Safe,
783                kw::Static,
784                kw::Union,
785                kw::Macro,
786                kw::Mod,
787                kw::Type,
788            ]
789            .contains(&name),
790            _ => false,
791        }
792    }
793
794    /// Returns `true` if the token is any literal.
795    pub fn is_lit(&self) -> bool {
796        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    Literal(..) => true,
    _ => false,
}matches!(self.kind, Literal(..))
797    }
798
799    /// Returns `true` if the token is any literal, a minus (which can prefix a literal,
800    /// for example a '-42', or one of the boolean idents).
801    ///
802    /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
803    ///
804    /// Keep this in sync with `Lit::from_token` and `Parser::eat_token_lit`
805    /// (excluding unary negation).
806    pub fn can_begin_literal_maybe_minus(&self) -> bool {
807        match self.uninterpolate().kind {
808            Literal(..) | Minus => true,
809            Ident(name, IdentIsRaw::No) if name.is_bool_lit() => true,
810            OpenInvisible(InvisibleOrigin::MetaVar(mv_kind)) => match mv_kind {
811                MetaVarKind::Literal => true,
812                MetaVarKind::Expr { can_begin_literal_maybe_minus, .. } => {
813                    can_begin_literal_maybe_minus
814                }
815                _ => false,
816            },
817            _ => false,
818        }
819    }
820
821    pub fn can_begin_string_literal(&self) -> bool {
822        match self.uninterpolate().kind {
823            Literal(..) => true,
824            OpenInvisible(InvisibleOrigin::MetaVar(mv_kind)) => match mv_kind {
825                MetaVarKind::Literal => true,
826                MetaVarKind::Expr { can_begin_string_literal, .. } => can_begin_string_literal,
827                _ => false,
828            },
829            _ => false,
830        }
831    }
832
833    /// A convenience function for matching on identifiers during parsing.
834    /// Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token
835    /// into the regular identifier or lifetime token it refers to,
836    /// otherwise returns the original token.
837    pub fn uninterpolate(&self) -> Cow<'_, Token> {
838        match self.kind {
839            NtIdent(ident, is_raw) => Cow::Owned(Token::new(Ident(ident.name, is_raw), ident.span)),
840            NtLifetime(ident, is_raw) => {
841                Cow::Owned(Token::new(Lifetime(ident.name, is_raw), ident.span))
842            }
843            _ => Cow::Borrowed(self),
844        }
845    }
846
847    /// Returns an identifier if this token is an identifier.
848    #[inline]
849    pub fn ident(&self) -> Option<(Ident, IdentIsRaw)> {
850        // We avoid using `Token::uninterpolate` here because it's slow.
851        match self.kind {
852            Ident(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
853            NtIdent(ident, is_raw) => Some((ident, is_raw)),
854            _ => None,
855        }
856    }
857
858    /// Returns a lifetime identifier if this token is a lifetime.
859    #[inline]
860    pub fn lifetime(&self) -> Option<(Ident, IdentIsRaw)> {
861        // We avoid using `Token::uninterpolate` here because it's slow.
862        match self.kind {
863            Lifetime(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
864            NtLifetime(ident, is_raw) => Some((ident, is_raw)),
865            _ => None,
866        }
867    }
868
869    /// Returns `true` if the token is an identifier.
870    pub fn is_ident(&self) -> bool {
871        self.ident().is_some()
872    }
873
874    /// Returns `true` if the token is a lifetime.
875    pub fn is_lifetime(&self) -> bool {
876        self.lifetime().is_some()
877    }
878
879    /// Returns `true` if the token is an identifier whose name is the given
880    /// string slice.
881    pub fn is_ident_named(&self, name: Symbol) -> bool {
882        self.ident().is_some_and(|(ident, _)| ident.name == name)
883    }
884
885    /// Is this a pre-parsed expression dropped into the token stream
886    /// (which happens while parsing the result of macro expansion)?
887    pub fn is_metavar_expr(&self) -> bool {
888        #[allow(non_exhaustive_omitted_patterns)] match self.is_metavar_seq() {
    Some(MetaVarKind::Expr { .. } | MetaVarKind::Literal | MetaVarKind::Path |
        MetaVarKind::Block) => true,
    _ => false,
}matches!(
889            self.is_metavar_seq(),
890            Some(
891                MetaVarKind::Expr { .. }
892                    | MetaVarKind::Literal
893                    | MetaVarKind::Path
894                    | MetaVarKind::Block
895            )
896        )
897    }
898
899    /// Are we at a block from a metavar (`$b:block`)?
900    pub fn is_metavar_block(&self) -> bool {
901        #[allow(non_exhaustive_omitted_patterns)] match self.is_metavar_seq() {
    Some(MetaVarKind::Block) => true,
    _ => false,
}matches!(self.is_metavar_seq(), Some(MetaVarKind::Block))
902    }
903
904    /// Returns `true` if the token is either the `mut` or `const` keyword.
905    pub fn is_mutability(&self) -> bool {
906        self.is_keyword(kw::Mut) || self.is_keyword(kw::Const)
907    }
908
909    pub fn is_qpath_start(&self) -> bool {
910        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    Lt | Shl => true,
    _ => false,
}matches!(self.kind, Lt | Shl)
911    }
912
913    pub fn is_path_start(&self) -> bool {
914        self.kind == PathSep
915            || self.is_qpath_start()
916            || #[allow(non_exhaustive_omitted_patterns)] match self.is_metavar_seq() {
    Some(MetaVarKind::Path) => true,
    _ => false,
}matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
917            || self.is_path_segment_keyword()
918            || self.is_non_reserved_ident()
919    }
920
921    /// Returns `true` if the token is a given keyword, `kw`.
922    pub fn is_keyword(&self, kw: Symbol) -> bool {
923        self.is_non_raw_ident_where(|id| id.name == kw)
924    }
925
926    /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
927    /// token is an identifier equal to `kw` ignoring the case.
928    pub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool {
929        self.is_keyword(kw)
930            || (case == Case::Insensitive
931                && self.is_non_raw_ident_where(|id| {
932                    // Do an ASCII case-insensitive match, because all keywords are ASCII.
933                    id.name.as_str().eq_ignore_ascii_case(kw.as_str())
934                }))
935    }
936
937    pub fn is_path_segment_keyword(&self) -> bool {
938        self.is_non_raw_ident_where(Ident::is_path_segment_keyword)
939    }
940
941    /// Returns true for reserved identifiers used internally for elided lifetimes,
942    /// unnamed method parameters, crate root module, error recovery etc.
943    pub fn is_special_ident(&self) -> bool {
944        self.is_non_raw_ident_where(Ident::is_special)
945    }
946
947    /// Returns `true` if the token is a keyword used in the language.
948    pub fn is_used_keyword(&self) -> bool {
949        self.is_non_raw_ident_where(Ident::is_used_keyword)
950    }
951
952    /// Returns `true` if the token is a keyword reserved for possible future use.
953    pub fn is_unused_keyword(&self) -> bool {
954        self.is_non_raw_ident_where(Ident::is_unused_keyword)
955    }
956
957    /// Returns `true` if the token is either a special identifier or a keyword.
958    pub fn is_reserved_ident(&self) -> bool {
959        self.is_non_raw_ident_where(Ident::is_reserved)
960    }
961
962    pub fn is_non_reserved_ident(&self) -> bool {
963        self.ident().is_some_and(|(id, raw)| raw == IdentIsRaw::Yes || !Ident::is_reserved(id))
964    }
965
966    /// Returns `true` if the token is the identifier `true` or `false`.
967    pub fn is_bool_lit(&self) -> bool {
968        self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
969    }
970
971    pub fn is_numeric_lit(&self) -> bool {
972        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    Literal(Lit { kind: LitKind::Integer, .. }) |
        Literal(Lit { kind: LitKind::Float, .. }) => true,
    _ => false,
}matches!(
973            self.kind,
974            Literal(Lit { kind: LitKind::Integer, .. }) | Literal(Lit { kind: LitKind::Float, .. })
975        )
976    }
977
978    /// Returns `true` if the token is the integer literal.
979    pub fn is_integer_lit(&self) -> bool {
980        #[allow(non_exhaustive_omitted_patterns)] match self.kind {
    Literal(Lit { kind: LitKind::Integer, .. }) => true,
    _ => false,
}matches!(self.kind, Literal(Lit { kind: LitKind::Integer, .. }))
981    }
982
983    /// Returns `true` if the token is a non-raw identifier for which `pred` holds.
984    pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
985        match self.ident() {
986            Some((id, IdentIsRaw::No)) => pred(id),
987            _ => false,
988        }
989    }
990
991    /// Is this an invisible open delimiter at the start of a token sequence
992    /// from an expanded metavar?
993    pub fn is_metavar_seq(&self) -> Option<MetaVarKind> {
994        match self.kind {
995            OpenInvisible(InvisibleOrigin::MetaVar(kind)) => Some(kind),
996            _ => None,
997        }
998    }
999
1000    pub fn glue(&self, joint: &Token) -> Option<Token> {
1001        let kind = match (&self.kind, &joint.kind) {
1002            (Eq, Eq) => EqEq,
1003            (Eq, Gt) => FatArrow,
1004            (Eq, _) => return None,
1005
1006            (Lt, Eq) => Le,
1007            (Lt, Lt) => Shl,
1008            (Lt, Le) => ShlEq,
1009            (Lt, Minus) => LArrow,
1010            (Lt, _) => return None,
1011
1012            (Gt, Eq) => Ge,
1013            (Gt, Gt) => Shr,
1014            (Gt, Ge) => ShrEq,
1015            (Gt, _) => return None,
1016
1017            (Bang, Eq) => Ne,
1018            (Bang, _) => return None,
1019
1020            (Plus, Eq) => PlusEq,
1021            (Plus, _) => return None,
1022
1023            (Minus, Eq) => MinusEq,
1024            (Minus, Gt) => RArrow,
1025            (Minus, _) => return None,
1026
1027            (Star, Eq) => StarEq,
1028            (Star, _) => return None,
1029
1030            (Slash, Eq) => SlashEq,
1031            (Slash, _) => return None,
1032
1033            (Percent, Eq) => PercentEq,
1034            (Percent, _) => return None,
1035
1036            (Caret, Eq) => CaretEq,
1037            (Caret, _) => return None,
1038
1039            (And, Eq) => AndEq,
1040            (And, And) => AndAnd,
1041            (And, _) => return None,
1042
1043            (Or, Eq) => OrEq,
1044            (Or, Or) => OrOr,
1045            (Or, _) => return None,
1046
1047            (Shl, Eq) => ShlEq,
1048            (Shl, _) => return None,
1049
1050            (Shr, Eq) => ShrEq,
1051            (Shr, _) => return None,
1052
1053            (Dot, Dot) => DotDot,
1054            (Dot, DotDot) => DotDotDot,
1055            (Dot, _) => return None,
1056
1057            (DotDot, Dot) => DotDotDot,
1058            (DotDot, Eq) => DotDotEq,
1059            (DotDot, _) => return None,
1060
1061            (Colon, Colon) => PathSep,
1062            (Colon, _) => return None,
1063
1064            (SingleQuote, Ident(name, is_raw)) => {
1065                Lifetime(Symbol::intern(&::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("\'{0}", name))
    })format!("'{name}")), *is_raw)
1066            }
1067            (SingleQuote, _) => return None,
1068
1069            (
1070                Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | PlusEq | MinusEq | StarEq | SlashEq
1071                | PercentEq | CaretEq | AndEq | OrEq | ShlEq | ShrEq | At | DotDotDot | DotDotEq
1072                | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar | Question
1073                | OpenParen | CloseParen | OpenBrace | CloseBrace | OpenBracket | CloseBracket
1074                | OpenInvisible(_) | CloseInvisible(_) | Literal(..) | Ident(..) | NtIdent(..)
1075                | Lifetime(..) | NtLifetime(..) | DocComment(..) | Eof,
1076                _,
1077            ) => {
1078                return None;
1079            }
1080        };
1081
1082        Some(Token::new(kind, self.span.to(joint.span)))
1083    }
1084}
1085
1086impl PartialEq<TokenKind> for Token {
1087    #[inline]
1088    fn eq(&self, rhs: &TokenKind) -> bool {
1089        self.kind == *rhs
1090    }
1091}
1092
1093#[derive(#[automatically_derived]
impl ::core::fmt::Debug for NtPatKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NtPatKind::PatWithOr =>
                ::core::fmt::Formatter::write_str(f, "PatWithOr"),
            NtPatKind::PatParam { inferred: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "PatParam", "inferred", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for NtPatKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for NtPatKind {
    #[inline]
    fn clone(&self) -> NtPatKind {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for NtPatKind {
    #[inline]
    fn eq(&self, other: &NtPatKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (NtPatKind::PatParam { inferred: __self_0 },
                    NtPatKind::PatParam { inferred: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NtPatKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for NtPatKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NtPatKind::PatWithOr => { 0usize }
                        NtPatKind::PatParam { inferred: ref __binding_0 } => {
                            1usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NtPatKind::PatWithOr => {}
                    NtPatKind::PatParam { inferred: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for NtPatKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { NtPatKind::PatWithOr }
                    1usize => {
                        NtPatKind::PatParam {
                            inferred: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NtPatKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for NtPatKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            NtPatKind::PatParam { inferred: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for NtPatKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    NtPatKind::PatWithOr => {}
                    NtPatKind::PatParam { inferred: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
1094pub enum NtPatKind {
1095    // Matches or-patterns. Was written using `pat` in edition 2021 or later.
1096    PatWithOr,
1097    // Doesn't match or-patterns.
1098    // - `inferred`: was written using `pat` in edition 2015 or 2018.
1099    // - `!inferred`: was written using `pat_param`.
1100    PatParam { inferred: bool },
1101}
1102
1103#[derive(#[automatically_derived]
impl ::core::fmt::Debug for NtExprKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NtExprKind::Expr => ::core::fmt::Formatter::write_str(f, "Expr"),
            NtExprKind::Expr2021 { inferred: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "Expr2021", "inferred", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for NtExprKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for NtExprKind {
    #[inline]
    fn clone(&self) -> NtExprKind {
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for NtExprKind {
    #[inline]
    fn eq(&self, other: &NtExprKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (NtExprKind::Expr2021 { inferred: __self_0 },
                    NtExprKind::Expr2021 { inferred: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NtExprKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for NtExprKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NtExprKind::Expr => { 0usize }
                        NtExprKind::Expr2021 { inferred: ref __binding_0 } => {
                            1usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NtExprKind::Expr => {}
                    NtExprKind::Expr2021 { inferred: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for NtExprKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { NtExprKind::Expr }
                    1usize => {
                        NtExprKind::Expr2021 {
                            inferred: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NtExprKind`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for NtExprKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            NtExprKind::Expr2021 { inferred: __self_0 } =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for NtExprKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    NtExprKind::Expr => {}
                    NtExprKind::Expr2021 { inferred: ref __binding_0 } => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                }
            }
        }
    };HashStable_Generic)]
1104pub enum NtExprKind {
1105    // Matches expressions using the post-edition 2024. Was written using
1106    // `expr` in edition 2024 or later.
1107    Expr,
1108    // Matches expressions using the pre-edition 2024 rules.
1109    // - `inferred`: was written using `expr` in edition 2021 or earlier.
1110    // - `!inferred`: was written using `expr_2021`.
1111    Expr2021 { inferred: bool },
1112}
1113
1114/// A macro nonterminal, known in documentation as a fragment specifier.
1115#[derive(#[automatically_derived]
impl ::core::fmt::Debug for NonterminalKind {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            NonterminalKind::Item =>
                ::core::fmt::Formatter::write_str(f, "Item"),
            NonterminalKind::Block =>
                ::core::fmt::Formatter::write_str(f, "Block"),
            NonterminalKind::Stmt =>
                ::core::fmt::Formatter::write_str(f, "Stmt"),
            NonterminalKind::Pat(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Pat",
                    &__self_0),
            NonterminalKind::Expr(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Expr",
                    &__self_0),
            NonterminalKind::Ty => ::core::fmt::Formatter::write_str(f, "Ty"),
            NonterminalKind::Ident =>
                ::core::fmt::Formatter::write_str(f, "Ident"),
            NonterminalKind::Lifetime =>
                ::core::fmt::Formatter::write_str(f, "Lifetime"),
            NonterminalKind::Literal =>
                ::core::fmt::Formatter::write_str(f, "Literal"),
            NonterminalKind::Meta =>
                ::core::fmt::Formatter::write_str(f, "Meta"),
            NonterminalKind::Path =>
                ::core::fmt::Formatter::write_str(f, "Path"),
            NonterminalKind::Vis =>
                ::core::fmt::Formatter::write_str(f, "Vis"),
            NonterminalKind::Guard =>
                ::core::fmt::Formatter::write_str(f, "Guard"),
            NonterminalKind::TT => ::core::fmt::Formatter::write_str(f, "TT"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for NonterminalKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for NonterminalKind {
    #[inline]
    fn clone(&self) -> NonterminalKind {
        let _: ::core::clone::AssertParamIsClone<NtPatKind>;
        let _: ::core::clone::AssertParamIsClone<NtExprKind>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for NonterminalKind {
    #[inline]
    fn eq(&self, other: &NonterminalKind) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (NonterminalKind::Pat(__self_0),
                    NonterminalKind::Pat(__arg1_0)) => __self_0 == __arg1_0,
                (NonterminalKind::Expr(__self_0),
                    NonterminalKind::Expr(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for NonterminalKind {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<NtPatKind>;
        let _: ::core::cmp::AssertParamIsEq<NtExprKind>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for NonterminalKind {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        NonterminalKind::Item => { 0usize }
                        NonterminalKind::Block => { 1usize }
                        NonterminalKind::Stmt => { 2usize }
                        NonterminalKind::Pat(ref __binding_0) => { 3usize }
                        NonterminalKind::Expr(ref __binding_0) => { 4usize }
                        NonterminalKind::Ty => { 5usize }
                        NonterminalKind::Ident => { 6usize }
                        NonterminalKind::Lifetime => { 7usize }
                        NonterminalKind::Literal => { 8usize }
                        NonterminalKind::Meta => { 9usize }
                        NonterminalKind::Path => { 10usize }
                        NonterminalKind::Vis => { 11usize }
                        NonterminalKind::Guard => { 12usize }
                        NonterminalKind::TT => { 13usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    NonterminalKind::Item => {}
                    NonterminalKind::Block => {}
                    NonterminalKind::Stmt => {}
                    NonterminalKind::Pat(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NonterminalKind::Expr(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    NonterminalKind::Ty => {}
                    NonterminalKind::Ident => {}
                    NonterminalKind::Lifetime => {}
                    NonterminalKind::Literal => {}
                    NonterminalKind::Meta => {}
                    NonterminalKind::Path => {}
                    NonterminalKind::Vis => {}
                    NonterminalKind::Guard => {}
                    NonterminalKind::TT => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for NonterminalKind {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { NonterminalKind::Item }
                    1usize => { NonterminalKind::Block }
                    2usize => { NonterminalKind::Stmt }
                    3usize => {
                        NonterminalKind::Pat(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        NonterminalKind::Expr(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    5usize => { NonterminalKind::Ty }
                    6usize => { NonterminalKind::Ident }
                    7usize => { NonterminalKind::Lifetime }
                    8usize => { NonterminalKind::Literal }
                    9usize => { NonterminalKind::Meta }
                    10usize => { NonterminalKind::Path }
                    11usize => { NonterminalKind::Vis }
                    12usize => { NonterminalKind::Guard }
                    13usize => { NonterminalKind::TT }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `NonterminalKind`, expected 0..14, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, #[automatically_derived]
impl ::core::hash::Hash for NonterminalKind {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            NonterminalKind::Pat(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            NonterminalKind::Expr(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
            for NonterminalKind where __CTX: crate::HashStableContext {
            #[inline]
            fn hash_stable(&self, __hcx: &mut __CTX,
                __hasher:
                    &mut ::rustc_data_structures::stable_hasher::StableHasher) {
                ::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
                match *self {
                    NonterminalKind::Item => {}
                    NonterminalKind::Block => {}
                    NonterminalKind::Stmt => {}
                    NonterminalKind::Pat(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    NonterminalKind::Expr(ref __binding_0) => {
                        { __binding_0.hash_stable(__hcx, __hasher); }
                    }
                    NonterminalKind::Ty => {}
                    NonterminalKind::Ident => {}
                    NonterminalKind::Lifetime => {}
                    NonterminalKind::Literal => {}
                    NonterminalKind::Meta => {}
                    NonterminalKind::Path => {}
                    NonterminalKind::Vis => {}
                    NonterminalKind::Guard => {}
                    NonterminalKind::TT => {}
                }
            }
        }
    };HashStable_Generic)]
1116pub enum NonterminalKind {
1117    Item,
1118    Block,
1119    Stmt,
1120    Pat(NtPatKind),
1121    Expr(NtExprKind),
1122    Ty,
1123    Ident,
1124    Lifetime,
1125    Literal,
1126    Meta,
1127    Path,
1128    Vis,
1129    Guard,
1130    TT,
1131}
1132
1133impl NonterminalKind {
1134    /// The `edition` closure is used to get the edition for the given symbol. Doing
1135    /// `span.edition()` is expensive, so we do it lazily.
1136    pub fn from_symbol(
1137        symbol: Symbol,
1138        edition: impl FnOnce() -> Edition,
1139    ) -> Option<NonterminalKind> {
1140        Some(match symbol {
1141            sym::item => NonterminalKind::Item,
1142            sym::block => NonterminalKind::Block,
1143            sym::stmt => NonterminalKind::Stmt,
1144            sym::pat => {
1145                if edition().at_least_rust_2021() {
1146                    NonterminalKind::Pat(PatWithOr)
1147                } else {
1148                    NonterminalKind::Pat(PatParam { inferred: true })
1149                }
1150            }
1151            sym::pat_param => NonterminalKind::Pat(PatParam { inferred: false }),
1152            sym::expr => {
1153                if edition().at_least_rust_2024() {
1154                    NonterminalKind::Expr(Expr)
1155                } else {
1156                    NonterminalKind::Expr(Expr2021 { inferred: true })
1157                }
1158            }
1159            sym::expr_2021 => NonterminalKind::Expr(Expr2021 { inferred: false }),
1160            sym::ty => NonterminalKind::Ty,
1161            sym::ident => NonterminalKind::Ident,
1162            sym::lifetime => NonterminalKind::Lifetime,
1163            sym::literal => NonterminalKind::Literal,
1164            sym::meta => NonterminalKind::Meta,
1165            sym::path => NonterminalKind::Path,
1166            sym::vis => NonterminalKind::Vis,
1167            sym::guard => NonterminalKind::Guard,
1168            sym::tt => NonterminalKind::TT,
1169            _ => return None,
1170        })
1171    }
1172
1173    fn symbol(self) -> Symbol {
1174        match self {
1175            NonterminalKind::Item => sym::item,
1176            NonterminalKind::Block => sym::block,
1177            NonterminalKind::Stmt => sym::stmt,
1178            NonterminalKind::Pat(PatParam { inferred: true } | PatWithOr) => sym::pat,
1179            NonterminalKind::Pat(PatParam { inferred: false }) => sym::pat_param,
1180            NonterminalKind::Expr(Expr2021 { inferred: true } | Expr) => sym::expr,
1181            NonterminalKind::Expr(Expr2021 { inferred: false }) => sym::expr_2021,
1182            NonterminalKind::Ty => sym::ty,
1183            NonterminalKind::Ident => sym::ident,
1184            NonterminalKind::Lifetime => sym::lifetime,
1185            NonterminalKind::Literal => sym::literal,
1186            NonterminalKind::Meta => sym::meta,
1187            NonterminalKind::Path => sym::path,
1188            NonterminalKind::Vis => sym::vis,
1189            NonterminalKind::Guard => sym::guard,
1190            NonterminalKind::TT => sym::tt,
1191        }
1192    }
1193}
1194
1195impl fmt::Display for NonterminalKind {
1196    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1197        f.write_fmt(format_args!("{0}", self.symbol()))write!(f, "{}", self.symbol())
1198    }
1199}
1200
1201// Some types are used a lot. Make sure they don't unintentionally get bigger.
1202#[cfg(target_pointer_width = "64")]
1203mod size_asserts {
1204    use rustc_data_structures::static_assert_size;
1205
1206    use super::*;
1207    // tidy-alphabetical-start
1208    const _: [(); 12] = [(); ::std::mem::size_of::<Lit>()];static_assert_size!(Lit, 12);
1209    const _: [(); 2] = [(); ::std::mem::size_of::<LitKind>()];static_assert_size!(LitKind, 2);
1210    const _: [(); 24] = [(); ::std::mem::size_of::<Token>()];static_assert_size!(Token, 24);
1211    const _: [(); 16] = [(); ::std::mem::size_of::<TokenKind>()];static_assert_size!(TokenKind, 16);
1212    // tidy-alphabetical-end
1213}