rustc_ast::token

Struct Token

Source
pub struct Token {
    pub kind: TokenKind,
    pub span: Span,
}

Fields§

§kind: TokenKind§span: Span

Implementations§

Source§

impl Token

Source

pub fn new(kind: TokenKind, span: Span) -> Self

Source

pub fn dummy() -> Self

Some token that will be thrown away later.

Source

pub fn from_ast_ident(ident: Ident) -> Self

Recovers a Token from an Ident. This creates a raw identifier if necessary.

Source

pub fn uninterpolated_span(&self) -> Span

For interpolated tokens, returns a span of the fragment to which the interpolated token refers. For all other tokens this is just a regular span. It is particularly important to use this for identifiers and lifetimes for which spans affect name resolution and edition checks. Note that keywords are also identifiers, so they should use this if they keep spans or perform edition checks.

Source

pub fn is_range_separator(&self) -> bool

Source

pub fn is_punct(&self) -> bool

Source

pub fn is_like_plus(&self) -> bool

Source

pub fn can_begin_expr(&self) -> bool

Returns true if the token can appear at the start of an expression.

NB: Take care when modifying this function, since it will change the stable set of tokens that are allowed to match an expr nonterminal.

Source

pub fn can_begin_pattern(&self, pat_kind: NtPatKind) -> bool

Returns true if the token can appear at the start of a pattern.

Shamelessly borrowed from can_begin_expr, only used for diagnostics right now.

Source

pub fn can_begin_type(&self) -> bool

Returns true if the token can appear at the start of a type.

Source

pub fn can_begin_const_arg(&self) -> bool

Returns true if the token can appear at the start of a const param.

Source

pub fn can_begin_item(&self) -> bool

Returns true if the token can appear at the start of an item.

Source

pub fn is_lit(&self) -> bool

Returns true if the token is any literal.

Source

pub fn can_begin_literal_maybe_minus(&self) -> bool

Returns true if the token is any literal, a minus (which can prefix a literal, for example a ‘-42’, or one of the boolean idents).

In other words, would this token be a valid start of parse_literal_maybe_minus?

Keep this in sync with and Lit::from_token, excluding unary negation.

Source

pub fn can_begin_string_literal(&self) -> bool

Source

pub fn uninterpolate(&self) -> Cow<'_, Token>

A convenience function for matching on identifiers during parsing. Turns interpolated identifier ($i: ident) or lifetime ($l: lifetime) token into the regular identifier or lifetime token it refers to, otherwise returns the original token.

Source

pub fn ident(&self) -> Option<(Ident, IdentIsRaw)>

Returns an identifier if this token is an identifier.

Source

pub fn lifetime(&self) -> Option<(Ident, IdentIsRaw)>

Returns a lifetime identifier if this token is a lifetime.

Source

pub fn is_ident(&self) -> bool

Returns true if the token is an identifier.

Source

pub fn is_lifetime(&self) -> bool

Returns true if the token is a lifetime.

Source

pub fn is_ident_named(&self, name: Symbol) -> bool

Returns true if the token is an identifier whose name is the given string slice.

Source

fn is_whole_path(&self) -> bool

Returns true if the token is an interpolated path.

Source

pub fn is_whole_expr(&self) -> bool

Is this a pre-parsed expression dropped into the token stream (which happens while parsing the result of macro expansion)?

Source

pub fn is_whole_block(&self) -> bool

Is the token an interpolated block ($b:block)?

Source

pub fn is_mutability(&self) -> bool

Returns true if the token is either the mut or const keyword.

Source

pub fn is_qpath_start(&self) -> bool

Source

pub fn is_path_start(&self) -> bool

Source

pub fn is_keyword(&self, kw: Symbol) -> bool

Returns true if the token is a given keyword, kw.

Source

pub fn is_keyword_case(&self, kw: Symbol, case: Case) -> bool

Returns true if the token is a given keyword, kw or if case is Insensitive and this token is an identifier equal to kw ignoring the case.

Source

pub fn is_path_segment_keyword(&self) -> bool

Source

pub fn is_special_ident(&self) -> bool

Returns true for reserved identifiers used internally for elided lifetimes, unnamed method parameters, crate root module, error recovery etc.

Source

pub fn is_used_keyword(&self) -> bool

Returns true if the token is a keyword used in the language.

Source

pub fn is_unused_keyword(&self) -> bool

Returns true if the token is a keyword reserved for possible future use.

Source

pub fn is_reserved_ident(&self) -> bool

Returns true if the token is either a special identifier or a keyword.

Source

pub fn is_bool_lit(&self) -> bool

Returns true if the token is the identifier true or false.

Source

pub fn is_numeric_lit(&self) -> bool

Source

pub fn is_integer_lit(&self) -> bool

Returns true if the token is the integer literal.

Source

pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool

Returns true if the token is a non-raw identifier for which pred holds.

Source

pub fn glue(&self, joint: &Token) -> Option<Token>

Trait Implementations§

Source§

impl Clone for Token

Source§

fn clone(&self) -> Token

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Token

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<__D: SpanDecoder> Decodable<__D> for Token

Source§

fn decode(__decoder: &mut __D) -> Self

Source§

impl<__E: SpanEncoder> Encodable<__E> for Token

Source§

fn encode(&self, __encoder: &mut __E)

Source§

impl<__CTX> HashStable<__CTX> for Token
where __CTX: HashStableContext,

Source§

fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)

Source§

impl PartialEq<TokenKind> for Token

Source§

fn eq(&self, rhs: &TokenKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Token

Source§

fn eq(&self, other: &Token) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Token

Auto Trait Implementations§

§

impl DynSend for Token

§

impl DynSync for Token

§

impl Freeze for Token

§

impl !RefUnwindSafe for Token

§

impl !Send for Token

§

impl !Sync for Token

§

impl Unpin for Token

§

impl !UnwindSafe for Token

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment = _

Alignment of Self.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes