Struct rustc_parse::parser::Parser
source · pub struct Parser<'a> {Show 17 fields
pub psess: &'a ParseSess,
pub token: Token,
token_spacing: Spacing,
pub prev_token: Token,
pub capture_cfg: bool,
restrictions: Restrictions,
expected_tokens: Vec<TokenType>,
token_cursor: TokenCursor,
num_bump_calls: u32,
break_last_token: bool,
unmatched_angle_bracket_count: u16,
angle_bracket_nesting: u16,
last_unexpected_token_span: Option<Span>,
subparser_name: Option<&'static str>,
capture_state: CaptureState,
current_closure: Option<ClosureSpans>,
recovery: Recovery,
}
Fields§
§psess: &'a ParseSess
§token: Token
The current token.
token_spacing: Spacing
The spacing for the current token.
prev_token: Token
The previous token.
capture_cfg: bool
§restrictions: Restrictions
§expected_tokens: Vec<TokenType>
§token_cursor: TokenCursor
§num_bump_calls: u32
§break_last_token: bool
§unmatched_angle_bracket_count: u16
This field is used to keep track of how many left angle brackets we have seen. This is
required in order to detect extra leading left angle brackets (<
characters) and error
appropriately.
See the comments in the parse_path_segment
function for more details.
angle_bracket_nesting: u16
§last_unexpected_token_span: Option<Span>
§subparser_name: Option<&'static str>
If present, this Parser
is not parsing Rust code but rather a macro call.
capture_state: CaptureState
§current_closure: Option<ClosureSpans>
This allows us to recover when the user forget to add braces around multiple statements in the closure body.
recovery: Recovery
Whether the parser is allowed to do recovery. This is disabled when parsing macro arguments, see #103534
Implementations§
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper>
pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper>
Parses attributes that appear before an item.
sourcepub fn parse_attribute(
&mut self,
inner_parse_policy: InnerAttrPolicy,
) -> PResult<'a, Attribute>
pub fn parse_attribute( &mut self, inner_parse_policy: InnerAttrPolicy, ) -> PResult<'a, Attribute>
Matches attribute = # ! [ meta_item ]
.
inner_parse_policy
prescribes how to handle inner attributes.
fn annotate_following_item_if_applicable( &self, err: &mut Diag<'_>, span: Span, attr_type: OuterAttributeType, ) -> Option<Span>
pub(super) fn error_on_forbidden_inner_attr( &self, attr_sp: Span, policy: InnerAttrPolicy, )
sourcepub fn parse_attr_item(
&mut self,
force_collect: ForceCollect,
) -> PResult<'a, AttrItem>
pub fn parse_attr_item( &mut self, force_collect: ForceCollect, ) -> PResult<'a, AttrItem>
Parses an inner part of an attribute (the path and following tokens).
The tokens must be either a delimited token stream, or empty token stream,
or the “legacy” key-value form.
PATH (
TOKEN_STREAM )
PATH [
TOKEN_STREAM ]
PATH {
TOKEN_STREAM }
PATH
PATH =
UNSUFFIXED_LIT
The delimiters or =
are still put into the resulting token stream.
sourcepub fn parse_inner_attributes(&mut self) -> PResult<'a, AttrVec>
pub fn parse_inner_attributes(&mut self) -> PResult<'a, AttrVec>
Parses attributes that appear after the opening of an item. These should be preceded by an exclamation mark, but we accept and warn about one terminated by a semicolon.
Matches inner_attrs*
.
pub(crate) fn parse_unsuffixed_meta_item_lit( &mut self, ) -> PResult<'a, MetaItemLit>
sourcepub fn parse_cfg_attr(
&mut self,
) -> PResult<'a, (MetaItem, Vec<(AttrItem, Span)>)>
pub fn parse_cfg_attr( &mut self, ) -> PResult<'a, (MetaItem, Vec<(AttrItem, Span)>)>
Parses cfg_attr(pred, attr_item_list)
where attr_item_list
is comma-delimited.
sourcepub(crate) fn parse_meta_seq_top(
&mut self,
) -> PResult<'a, ThinVec<NestedMetaItem>>
pub(crate) fn parse_meta_seq_top( &mut self, ) -> PResult<'a, ThinVec<NestedMetaItem>>
Matches COMMASEP(meta_item_inner)
.
sourcepub fn parse_meta_item(&mut self) -> PResult<'a, MetaItem>
pub fn parse_meta_item(&mut self) -> PResult<'a, MetaItem>
Parse a meta item per RFC 1559.
MetaItem = SimplePath ( '=' UNSUFFIXED_LIT | '(' MetaSeq? ')' )? ;
MetaSeq = MetaItemInner (',' MetaItemInner)* ','? ;
pub(crate) fn parse_meta_item_kind(&mut self) -> PResult<'a, MetaItemKind>
sourcefn parse_meta_item_inner(&mut self) -> PResult<'a, NestedMetaItem>
fn parse_meta_item_inner(&mut self) -> PResult<'a, NestedMetaItem>
Parse an inner meta item per RFC 1559.
MetaItemInner = UNSUFFIXED_LIT | MetaItem ;
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn collect_tokens_trailing_token<R: HasAttrs + HasTokens>(
&mut self,
attrs: AttrWrapper,
force_collect: ForceCollect,
f: impl FnOnce(&mut Self, AttrVec) -> PResult<'a, (R, bool)>,
) -> PResult<'a, R>
pub fn collect_tokens_trailing_token<R: HasAttrs + HasTokens>( &mut self, attrs: AttrWrapper, force_collect: ForceCollect, f: impl FnOnce(&mut Self, AttrVec) -> PResult<'a, (R, bool)>, ) -> PResult<'a, R>
Parses code with f
. If appropriate, it records the tokens (in
LazyAttrTokenStream
form) that were parsed in the result, accessible
via the HasTokens
trait. The second (bool) part of the callback’s
result indicates if an extra token should be captured, e.g. a comma or
semicolon.
The attrs
passed in are in AttrWrapper
form, which is opaque. The
AttrVec
within is passed to f
. See the comment on AttrWrapper
for
details.
Note: If your callback consumes an opening delimiter (including the
case where self.token
is an opening delimiter on entry to this
function), you must also consume the corresponding closing delimiter.
E.g. you can consume something ([{ }])
or ([{}])
, but not ([{}]
.
This restriction isn’t a problem in practice, because parsed AST items
always have matching delimiters.
The following example code will be used to explain things in comments below. It has an outer attribute and an inner attribute. Parsing it involves two calls to this method, one of which is indirectly recursive.
#[cfg_eval] // token pos
mod m { // 0.. 3
#[cfg_attr(cond1, attr1)] // 3..12
fn g() { // 12..17
#![cfg_attr(cond2, attr2)] // 17..27
let _x = 3; // 27..32
} // 32..33
} // 33..34
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub fn dcx(&self) -> DiagCtxtHandle<'a>
sourcepub(super) fn restore_snapshot(&mut self, snapshot: SnapshotParser<'a>)
pub(super) fn restore_snapshot(&mut self, snapshot: SnapshotParser<'a>)
Replace self
with snapshot.parser
.
sourcepub fn create_snapshot_for_diagnostic(&self) -> SnapshotParser<'a>
pub fn create_snapshot_for_diagnostic(&self) -> SnapshotParser<'a>
Create a snapshot of the Parser
.
pub(super) fn span_to_snippet( &self, span: Span, ) -> Result<String, SpanSnippetError>
sourcepub(super) fn expected_ident_found(
&mut self,
recover: bool,
) -> PResult<'a, (Ident, IdentIsRaw)>
pub(super) fn expected_ident_found( &mut self, recover: bool, ) -> PResult<'a, (Ident, IdentIsRaw)>
Emits an error with suggestions if an identifier was expected but not found.
Returns a possibly recovered identifier.
pub(super) fn expected_ident_found_err(&mut self) -> Diag<'a>
sourcepub(super) fn is_lit_bad_ident(&mut self) -> Option<(usize, Symbol)>
pub(super) fn is_lit_bad_ident(&mut self) -> Option<(usize, Symbol)>
Checks if the current token is a integer or float literal and looks like it could be a invalid identifier with digits at the start.
Returns the number of characters (bytes) composing the invalid portion of the identifier and the valid portion of the identifier.
pub(super) fn expected_one_of_not_found( &mut self, edible: &[TokenKind], inedible: &[TokenKind], ) -> PResult<'a, ErrorGuaranteed>
sourcepub(super) fn attr_on_non_tail_expr(&self, expr: &Expr) -> ErrorGuaranteed
pub(super) fn attr_on_non_tail_expr(&self, expr: &Expr) -> ErrorGuaranteed
The user has written #[attr] expr
which is unsupported. (#106020)
fn check_too_many_raw_str_terminators(&mut self, err: &mut Diag<'_>) -> bool
pub(super) fn maybe_suggest_struct_literal( &mut self, lo: Span, s: BlockCheckMode, maybe_struct_name: Token, can_be_struct_literal: bool, ) -> Option<PResult<'a, P<Block>>>
pub(super) fn recover_closure_body( &mut self, err: Diag<'a>, before: Token, prev: Token, token: Token, lo: Span, decl_hi: Span, ) -> PResult<'a, P<Expr>>
sourcepub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind])
pub(super) fn eat_to_tokens(&mut self, kets: &[&TokenKind])
Eats and discards tokens until one of kets
is encountered. Respects token trees,
passes through any errors encountered. Used for error recovery.
sourcepub(super) fn check_trailing_angle_brackets(
&mut self,
segment: &PathSegment,
end: &[&TokenKind],
) -> Option<ErrorGuaranteed>
pub(super) fn check_trailing_angle_brackets( &mut self, segment: &PathSegment, end: &[&TokenKind], ) -> Option<ErrorGuaranteed>
This function checks if there are trailing angle brackets and produces a diagnostic to suggest removing them.
let _ = [1, 2, 3].into_iter().collect::<Vec<usize>>>>();
^^ help: remove extra angle brackets
If true
is returned, then trailing brackets were recovered, tokens were consumed
up until one of the tokens in ‘end’ was encountered, and an error was emitted.
sourcepub(super) fn check_turbofish_missing_angle_brackets(
&mut self,
segment: &mut PathSegment,
)
pub(super) fn check_turbofish_missing_angle_brackets( &mut self, segment: &mut PathSegment, )
Check if a method call with an intended turbofish has been written without surrounding angle brackets.
sourcepub(super) fn check_mistyped_turbofish_with_multiple_type_params(
&mut self,
e: Diag<'a>,
expr: &mut P<Expr>,
) -> PResult<'a, ErrorGuaranteed>
pub(super) fn check_mistyped_turbofish_with_multiple_type_params( &mut self, e: Diag<'a>, expr: &mut P<Expr>, ) -> PResult<'a, ErrorGuaranteed>
When writing a turbofish with multiple type parameters missing the leading ::
, we will
encounter a parse error when encountering the first ,
.
sourcepub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut Diag<'a>)
pub(super) fn suggest_add_missing_let_for_stmt(&mut self, err: &mut Diag<'a>)
Suggest add the missing let
before the identifier in stmt
a: Ty = 1
-> let a: Ty = 1
sourcefn attempt_chained_comparison_suggestion(
&mut self,
err: &mut ComparisonOperatorsCannotBeChained,
inner_op: &Expr,
outer_op: &Spanned<AssocOp>,
) -> bool
fn attempt_chained_comparison_suggestion( &mut self, err: &mut ComparisonOperatorsCannotBeChained, inner_op: &Expr, outer_op: &Spanned<AssocOp>, ) -> bool
Check to see if a pair of chained operators looks like an attempt at chained comparison,
e.g. 1 < x <= 3
. If so, suggest either splitting the comparison into two, or
parenthesising the leftmost comparison. The return value indicates if recovery happened.
sourcepub(super) fn check_no_chained_comparison(
&mut self,
inner_op: &Expr,
outer_op: &Spanned<AssocOp>,
) -> PResult<'a, Option<P<Expr>>>
pub(super) fn check_no_chained_comparison( &mut self, inner_op: &Expr, outer_op: &Spanned<AssocOp>, ) -> PResult<'a, Option<P<Expr>>>
Produces an error if comparison operators are chained (RFC #558).
We only need to check the LHS, not the RHS, because all comparison ops have same
precedence (see fn precedence
) and are left-associative (see fn fixity
).
This can also be hit if someone incorrectly writes foo<bar>()
when they should have used
the turbofish (foo::<bar>()
) syntax. We attempt some heuristic recovery if that is the
case.
Keep in mind that given that outer_op.is_comparison()
holds and comparison ops are left
associative we can infer that we have:
outer_op
/ \
inner_op r2
/ \
l1 r1
fn consume_fn_args(&mut self) -> Result<(), ()>
pub(super) fn maybe_report_ambiguous_plus( &mut self, impl_dyn_multi: bool, ty: &Ty, )
sourcepub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty>
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty>
Swift lets users write Ty?
to mean Option<Ty>
. Parse the construct and recover from it.
sourcepub(super) fn maybe_recover_from_ternary_operator(&mut self) -> PResult<'a, ()>
pub(super) fn maybe_recover_from_ternary_operator(&mut self) -> PResult<'a, ()>
Rust has no ternary operator (cond ? then : else
). Parse it and try
to recover from it if then
and else
are valid expressions. Returns
an err if this appears to be a ternary expression.
pub(super) fn maybe_recover_from_bad_type_plus( &mut self, ty: &Ty, ) -> PResult<'a, ()>
pub(super) fn recover_from_prefix_increment( &mut self, operand_expr: P<Expr>, op_span: Span, start_stmt: bool, ) -> PResult<'a, P<Expr>>
pub(super) fn recover_from_postfix_increment( &mut self, operand_expr: P<Expr>, op_span: Span, start_stmt: bool, ) -> PResult<'a, P<Expr>>
pub(super) fn recover_from_postfix_decrement( &mut self, operand_expr: P<Expr>, op_span: Span, start_stmt: bool, ) -> PResult<'a, P<Expr>>
fn recover_from_inc_dec( &mut self, base: P<Expr>, kind: IncDecRecovery, op_span: Span, ) -> PResult<'a, P<Expr>>
fn prefix_inc_dec_suggest( &mut self, base_src: String, kind: IncDecRecovery, (pre_span, post_span): (Span, Span), ) -> MultiSugg
fn postfix_inc_dec_suggest( &mut self, base_src: String, kind: IncDecRecovery, (pre_span, post_span): (Span, Span), ) -> MultiSugg
fn inc_dec_standalone_suggest( &mut self, kind: IncDecRecovery, (pre_span, post_span): (Span, Span), ) -> MultiSugg
sourcepub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>(
&mut self,
base: P<T>,
) -> PResult<'a, P<T>>
pub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>( &mut self, base: P<T>, ) -> PResult<'a, P<T>>
Tries to recover from associated item paths like [T]::AssocItem
/ (T, U)::AssocItem
.
Attempts to convert the base expression/pattern/type into a type, parses the ::AssocItem
tail, and combines them into a <Ty>::AssocItem
expression/pattern/type.
sourcepub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
&mut self,
ty_span: Span,
ty: P<Ty>,
) -> PResult<'a, P<T>>
pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>( &mut self, ty_span: Span, ty: P<Ty>, ) -> PResult<'a, P<T>>
Given an already parsed Ty
, parses the ::AssocItem
tail and
combines them into a <Ty>::AssocItem
expression/pattern/type.
sourcepub fn maybe_consume_incorrect_semicolon(
&mut self,
previous_item: Option<&Item>,
) -> bool
pub fn maybe_consume_incorrect_semicolon( &mut self, previous_item: Option<&Item>, ) -> bool
This function gets called in places where a semicolon is NOT expected and if there’s a semicolon it emits the appropriate error and returns true.
sourcepub(super) fn unexpected_try_recover(
&mut self,
t: &TokenKind,
) -> PResult<'a, Recovered>
pub(super) fn unexpected_try_recover( &mut self, t: &TokenKind, ) -> PResult<'a, Recovered>
Creates a Diag
for an unexpected token t
and tries to recover if it is a
closing delimiter.
pub(super) fn expect_semi(&mut self) -> PResult<'a, ()>
pub(super) fn recover_colon_as_semi(&mut self) -> bool
sourcepub(super) fn recover_incorrect_await_syntax(
&mut self,
lo: Span,
await_sp: Span,
) -> PResult<'a, P<Expr>>
pub(super) fn recover_incorrect_await_syntax( &mut self, lo: Span, await_sp: Span, ) -> PResult<'a, P<Expr>>
Consumes alternative await syntaxes like await!(<expr>)
, await <expr>
,
await? <expr>
, await(<expr>)
, and await { <expr> }
.
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)>
fn recover_await_prefix( &mut self, await_sp: Span, ) -> PResult<'a, (Span, P<Expr>, bool)>
fn error_on_incorrect_await( &self, lo: Span, hi: Span, expr: &Expr, is_question: bool, ) -> (Span, ErrorGuaranteed)
sourcepub(super) fn recover_from_await_method_call(&mut self)
pub(super) fn recover_from_await_method_call(&mut self)
If encountering future.await()
, consumes and emits an error.
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>>
sourcepub(super) fn expect_gt_or_maybe_suggest_closing_generics(
&mut self,
params: &[GenericParam],
) -> PResult<'a, ()>
pub(super) fn expect_gt_or_maybe_suggest_closing_generics( &mut self, params: &[GenericParam], ) -> PResult<'a, ()>
When trying to close a generics list and encountering code like
impl<S: Into<std::borrow::Cow<'static, str>> From<S> for Canonical {}
// ^ missing > here
we provide a structured suggestion on the error from expect_gt
.
pub(super) fn recover_seq_parse_error( &mut self, delim: Delimiter, lo: Span, err: PErr<'a>, ) -> P<Expr>
sourcepub(super) fn recover_stmt(&mut self)
pub(super) fn recover_stmt(&mut self)
Eats tokens until we can be relatively sure we reached the end of the statement. This is something of a best-effort heuristic.
We terminate when we find an unmatched }
(without consuming it).
sourcepub(super) fn recover_stmt_(
&mut self,
break_on_semi: SemiColonMode,
break_on_block: BlockMode,
)
pub(super) fn recover_stmt_( &mut self, break_on_semi: SemiColonMode, break_on_block: BlockMode, )
If break_on_semi
is Break
, then we will stop consuming tokens after
finding (and consuming) a ;
outside of {}
or []
(note that this is
approximate – it can mean we break too early due to macros, but that
should only lead to sub-optimal recovery, not inaccurate parsing).
If break_on_block
is Break
, then we will stop consuming tokens
after finding (and consuming) a brace-delimited block.
pub(super) fn check_for_for_in_in_typo(&mut self, in_span: Span)
pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self)
pub(super) fn parameter_without_type( &mut self, err: &mut Diag<'_>, pat: P<Pat>, require_name: bool, first_param: bool, ) -> Option<Ident>
pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (P<Pat>, P<Ty>)>
pub(super) fn recover_bad_self_param( &mut self, param: Param, ) -> PResult<'a, Param>
pub(super) fn consume_block( &mut self, delim: Delimiter, consume_close: ConsumeClosingDelim, )
pub(super) fn expected_expression_found(&self) -> Diag<'a>
fn consume_tts(&mut self, acc: i64, modifier: &[(TokenKind, i64)])
sourcepub(super) fn deduplicate_recovered_params_names(
&self,
fn_inputs: &mut ThinVec<Param>,
)
pub(super) fn deduplicate_recovered_params_names( &self, fn_inputs: &mut ThinVec<Param>, )
Replace duplicated recovered parameters with _
pattern to avoid unnecessary errors.
This is necessary because at this point we don’t know whether we parsed a function with
anonymous parameters or a function with names but no types. In order to minimize
unnecessary errors, we assume the parameters are in the shape of fn foo(a, b, c)
where
the parameters are names (so we don’t emit errors about not being able to find b
in
the local scope), but if we find the same name multiple times, like in fn foo(i8, i8)
,
we deduplicate them to not complain about duplicated parameter names.
sourcepub(super) fn handle_ambiguous_unbraced_const_arg(
&mut self,
args: &mut ThinVec<AngleBracketedArg>,
) -> PResult<'a, bool>
pub(super) fn handle_ambiguous_unbraced_const_arg( &mut self, args: &mut ThinVec<AngleBracketedArg>, ) -> PResult<'a, bool>
Handle encountering a symbol in a generic argument list that is not a ,
or >
. In this
case, we emit an error and try to suggest enclosing a const argument in braces if it looks
like the user has forgotten them.
sourcepub(super) fn handle_unambiguous_unbraced_const_arg(
&mut self,
) -> PResult<'a, P<Expr>>
pub(super) fn handle_unambiguous_unbraced_const_arg( &mut self, ) -> PResult<'a, P<Expr>>
Attempt to parse a generic const argument that has not been enclosed in braces. There are a limited number of expressions that are permitted without being encoded in braces:
- Literals.
- Single-segment paths (i.e. standalone generic const parameters). All other expressions that can be parsed will emit an error suggesting the expression be wrapped in braces.
fn recover_const_param_decl( &mut self, ty_generics: Option<&Generics>, ) -> Option<GenericArg>
pub(super) fn recover_const_param_declaration( &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, Option<GenericArg>>
sourcepub(super) fn recover_const_arg(
&mut self,
start: Span,
err: Diag<'a>,
) -> PResult<'a, GenericArg>
pub(super) fn recover_const_arg( &mut self, start: Span, err: Diag<'a>, ) -> PResult<'a, GenericArg>
Try to recover from possible generic const argument without {
and }
.
When encountering code like foo::< bar + 3 >
or foo::< bar - baz >
we suggest
foo::<{ bar + 3 }>
and foo::<{ bar - baz }>
, respectively. We only provide a suggestion
if we think that the resulting expression would be well formed.
sourcepub(crate) fn recover_unbraced_const_arg_that_can_begin_ty(
&mut self,
snapshot: SnapshotParser<'a>,
) -> Option<P<Expr>>
pub(crate) fn recover_unbraced_const_arg_that_can_begin_ty( &mut self, snapshot: SnapshotParser<'a>, ) -> Option<P<Expr>>
Try to recover from an unbraced const argument whose first token could begin a type.
sourcepub(super) fn dummy_const_arg_needs_braces(
&self,
err: Diag<'a>,
span: Span,
) -> GenericArg
pub(super) fn dummy_const_arg_needs_braces( &self, err: Diag<'a>, span: Span, ) -> GenericArg
Creates a dummy const argument, and reports that the expression must be enclosed in braces
sourcepub(crate) fn maybe_recover_colon_colon_in_pat_typo(
&mut self,
first_pat: P<Pat>,
expected: Option<Expected>,
) -> P<Pat>
pub(crate) fn maybe_recover_colon_colon_in_pat_typo( &mut self, first_pat: P<Pat>, expected: Option<Expected>, ) -> P<Pat>
Some special error handling for the “top-level” patterns in a match arm,
for
loop, let
, &c. (in contrast to subpatterns within such).
pub(crate) fn maybe_recover_unexpected_block_label(&mut self) -> bool
sourcepub(crate) fn maybe_recover_unexpected_comma(
&mut self,
lo: Span,
rt: CommaRecoveryMode,
) -> PResult<'a, ()>
pub(crate) fn maybe_recover_unexpected_comma( &mut self, lo: Span, rt: CommaRecoveryMode, ) -> PResult<'a, ()>
Some special error handling for the “top-level” patterns in a match arm,
for
loop, let
, &c. (in contrast to subpatterns within such).
pub(crate) fn maybe_recover_bounds_doubled_colon( &mut self, ty: &Ty, ) -> PResult<'a, ()>
sourcepub(crate) fn maybe_err_dotdotlt_syntax(
&self,
maybe_lt: Token,
err: PErr<'a>,
) -> PErr<'a>
pub(crate) fn maybe_err_dotdotlt_syntax( &self, maybe_lt: Token, err: PErr<'a>, ) -> PErr<'a>
Check for exclusive ranges written as ..<
sourcepub(super) fn is_vcs_conflict_marker(
&mut self,
long_kind: &TokenKind,
short_kind: &TokenKind,
) -> bool
pub(super) fn is_vcs_conflict_marker( &mut self, long_kind: &TokenKind, short_kind: &TokenKind, ) -> bool
This checks if this is a conflict marker, depending of the parameter passed.
<<<<<<<
|||||||
=======
>>>>>>>
fn conflict_marker( &mut self, long_kind: &TokenKind, short_kind: &TokenKind, ) -> Option<Span>
pub(super) fn recover_vcs_conflict_marker(&mut self)
pub(crate) fn err_vcs_conflict_marker(&mut self) -> PResult<'a, ()>
sourcefn skip_pat_list(&mut self) -> PResult<'a, ()>
fn skip_pat_list(&mut self) -> PResult<'a, ()>
Parse and throw away a parenthesized comma separated
sequence of patterns until )
is reached.
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>
pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>
Parses an expression.
sourcepub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>>
pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>>
Parses an expression, forcing tokens to be collected.
pub fn parse_expr_anon_const(&mut self) -> PResult<'a, AnonConst>
fn parse_expr_catch_underscore( &mut self, restrictions: Restrictions, ) -> PResult<'a, P<Expr>>
sourcefn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<P<Expr>>>
fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<P<Expr>>>
Parses a sequence of expressions delimited by parentheses.
sourcepub(super) fn parse_expr_res(
&mut self,
r: Restrictions,
attrs: AttrWrapper,
) -> PResult<'a, P<Expr>>
pub(super) fn parse_expr_res( &mut self, r: Restrictions, attrs: AttrWrapper, ) -> PResult<'a, P<Expr>>
Parses an expression, subject to the given restrictions.
sourcepub(super) fn parse_expr_assoc_with(
&mut self,
min_prec: usize,
lhs: LhsExpr,
) -> PResult<'a, P<Expr>>
pub(super) fn parse_expr_assoc_with( &mut self, min_prec: usize, lhs: LhsExpr, ) -> PResult<'a, P<Expr>>
Parses an associative expression with operators of at least min_prec
precedence.
fn should_continue_as_assoc_expr(&mut self, lhs: &Expr) -> bool
sourcefn error_found_expr_would_be_stmt(&self, lhs: &Expr)
fn error_found_expr_would_be_stmt(&self, lhs: &Expr)
We’ve found an expression that would be parsed as a statement,
but the next token implies this should be parsed as an expression.
For example: if let Some(x) = x { x } else { 0 } / 2
.
sourcepub(super) fn check_assoc_op(&self) -> Option<Spanned<AssocOp>>
pub(super) fn check_assoc_op(&self) -> Option<Spanned<AssocOp>>
Possibly translate the current token to an associative operator. The method does not advance the current token.
Also performs recovery for and
/ or
which are mistaken for &&
and ||
respectively.
sourcefn expr_is_complete(&self, e: &Expr) -> bool
fn expr_is_complete(&self, e: &Expr) -> bool
Checks if this expression is a successfully parsed statement.
sourcefn parse_expr_range(
&mut self,
prec: usize,
lhs: P<Expr>,
op: AssocOp,
cur_op_span: Span,
) -> PResult<'a, P<Expr>>
fn parse_expr_range( &mut self, prec: usize, lhs: P<Expr>, op: AssocOp, cur_op_span: Span, ) -> PResult<'a, P<Expr>>
Parses x..y
, x..=y
, and x..
/x..=
.
The other two variants are handled in parse_prefix_range_expr
below.
fn is_at_start_of_range_notation_rhs(&self) -> bool
sourcefn parse_expr_prefix_range(
&mut self,
attrs: AttrWrapper,
) -> PResult<'a, P<Expr>>
fn parse_expr_prefix_range( &mut self, attrs: AttrWrapper, ) -> PResult<'a, P<Expr>>
Parses prefix-forms of range notation: ..expr
, ..
, ..=expr
.
sourcefn parse_expr_prefix(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>>
fn parse_expr_prefix(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>>
Parses a prefix-unary-operator expr.
fn parse_expr_prefix_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)>
fn parse_expr_unary( &mut self, lo: Span, op: UnOp, ) -> PResult<'a, (Span, ExprKind)>
sourcefn recover_tilde_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
fn recover_tilde_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
Recover on ~expr
in favor of !expr
.
sourcefn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)>
fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)>
Parse box expr
- this syntax has been removed, but we still parse this
for now to provide a more useful error
fn is_mistaken_not_ident_negation(&self) -> bool
sourcefn recover_not_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
fn recover_not_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
Recover on not expr
in favor of !expr
.
sourcefn interpolated_or_expr_span(&self, expr: &Expr) -> Span
fn interpolated_or_expr_span(&self, expr: &Expr) -> Span
Returns the span of expr if it was not interpolated, or the span of the interpolated token.
fn parse_assoc_op_cast( &mut self, lhs: P<Expr>, lhs_span: Span, expr_kind: fn(_: P<Expr>, _: P<Ty>) -> ExprKind, ) -> PResult<'a, P<Expr>>
sourcefn parse_expr_borrow(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
fn parse_expr_borrow(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)>
Parse & mut? <expr>
or & raw [ const | mut ] <expr>
.
fn error_remove_borrow_lifetime(&self, span: Span, lt_span: Span)
sourcefn parse_borrow_modifiers(&mut self, lo: Span) -> (BorrowKind, Mutability)
fn parse_borrow_modifiers(&mut self, lo: Span) -> (BorrowKind, Mutability)
Parse mut?
or raw [ const | mut ]
.
sourcefn parse_expr_dot_or_call(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>>
fn parse_expr_dot_or_call(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>>
Parses a.b
or a(13)
or a[4]
or just a
.
pub(super) fn parse_expr_dot_or_call_with( &mut self, attrs: AttrVec, e: P<Expr>, lo: Span, ) -> PResult<'a, P<Expr>>
pub(super) fn parse_dot_suffix_expr( &mut self, lo: Span, base: P<Expr>, ) -> PResult<'a, P<Expr>>
fn error_unexpected_after_dot(&self)
fn break_up_float(&self, float: Symbol, span: Span) -> DestructuredFloat
sourcefn parse_floating_field_access(&mut self) -> PResult<'a, P<[Ident]>>
fn parse_floating_field_access(&mut self) -> PResult<'a, P<[Ident]>>
Parse the field access used in offset_of, matched by $(e:expr)+
.
Currently returns a list of idents. However, it should be possible in
future to also do array indices, which might be arbitrary expressions.
fn mk_expr_tuple_field_access( &mut self, lo: Span, ident_span: Span, base: P<Expr>, field: Symbol, suffix: Option<Symbol>, ) -> P<Expr>
sourcefn parse_expr_fn_call(&mut self, lo: Span, fun: P<Expr>) -> P<Expr>
fn parse_expr_fn_call(&mut self, lo: Span, fun: P<Expr>) -> P<Expr>
Parse a function call expression, expr(...)
.
sourcefn maybe_recover_struct_lit_bad_delims(
&mut self,
lo: Span,
open_paren: Span,
seq: PResult<'a, P<Expr>>,
snapshot: Option<(SnapshotParser<'a>, ExprKind)>,
) -> PResult<'a, P<Expr>>
fn maybe_recover_struct_lit_bad_delims( &mut self, lo: Span, open_paren: Span, seq: PResult<'a, P<Expr>>, snapshot: Option<(SnapshotParser<'a>, ExprKind)>, ) -> PResult<'a, P<Expr>>
If we encounter a parser state that looks like the user has written a struct
literal with
parentheses instead of braces, recover the parser state and provide suggestions.
sourcefn parse_expr_index(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>>
fn parse_expr_index(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>>
Parse an indexing expression expr[...]
.
sourcefn parse_dot_suffix(
&mut self,
self_arg: P<Expr>,
lo: Span,
) -> PResult<'a, P<Expr>>
fn parse_dot_suffix( &mut self, self_arg: P<Expr>, lo: Span, ) -> PResult<'a, P<Expr>>
Assuming we have just parsed .
, continue parsing into an expression.
sourcefn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>>
At the bottom (top?) of the precedence hierarchy,
Parses things like parenthesized exprs, macros, return
, etc.
N.B., this does not parse outer attributes, and is private because it only works
correctly if called from parse_expr_dot_or_call
.
fn parse_expr_lit(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_tuple_parens( &mut self, restrictions: Restrictions, ) -> PResult<'a, P<Expr>>
fn parse_expr_array_or_repeat( &mut self, close_delim: Delimiter, ) -> PResult<'a, P<Expr>>
fn parse_expr_path_start(&mut self) -> PResult<'a, P<Expr>>
sourcepub(super) fn parse_expr_labeled(
&mut self,
label_: Label,
consume_colon: bool,
) -> PResult<'a, P<Expr>>
pub(super) fn parse_expr_labeled( &mut self, label_: Label, consume_colon: bool, ) -> PResult<'a, P<Expr>>
Parse 'label: $expr
. The label is already parsed.
sourcepub(super) fn recover_unclosed_char<L>(
&self,
ident: Ident,
mk_lit_char: impl FnOnce(Symbol, Span) -> L,
err: impl FnOnce(&Self) -> Diag<'a>,
) -> L
pub(super) fn recover_unclosed_char<L>( &self, ident: Ident, mk_lit_char: impl FnOnce(Symbol, Span) -> L, err: impl FnOnce(&Self) -> Diag<'a>, ) -> L
Emit an error when a char is parsed as a lifetime or label because of a missing quote.
sourcefn recover_do_catch(&mut self) -> PResult<'a, P<Expr>>
fn recover_do_catch(&mut self) -> PResult<'a, P<Expr>>
Recover on the syntax do catch { ... }
suggesting try { ... }
instead.
sourcefn parse_expr_opt(&mut self) -> PResult<'a, Option<P<Expr>>>
fn parse_expr_opt(&mut self) -> PResult<'a, Option<P<Expr>>>
Parse an expression if the token can begin one.
sourcefn parse_expr_return(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_return(&mut self) -> PResult<'a, P<Expr>>
Parse "return" expr?
.
sourcefn parse_expr_yeet(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_yeet(&mut self) -> PResult<'a, P<Expr>>
Parse "do" "yeet" expr?
.
sourcefn parse_expr_become(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_become(&mut self) -> PResult<'a, P<Expr>>
Parse "become" expr
, with "become"
token already eaten.
sourcefn parse_expr_break(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_break(&mut self) -> PResult<'a, P<Expr>>
Parse "break" (('label (:? expr)?) | expr?)
with "break"
token already eaten.
If the label is followed immediately by a :
token, the label and :
are
parsed as part of the expression (i.e. a labeled loop). The language team has
decided in #87026 to require parentheses as a visual aid to avoid confusion if
the break expression of an unlabeled break is a labeled loop (as in
break 'lbl: loop {}
); a labeled break with an unlabeled loop as its value
expression only gets a warning for compatibility reasons; and a labeled break
with a labeled loop does not even get a warning because there is no ambiguity.
sourcefn parse_expr_yield(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_yield(&mut self) -> PResult<'a, P<Expr>>
Parse "yield" expr?
.
sourcefn parse_expr_builtin(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_builtin(&mut self) -> PResult<'a, P<Expr>>
Parse builtin # ident(args,*)
.
pub(crate) fn parse_builtin<T>( &mut self, parse: impl FnOnce(&mut Parser<'a>, Span, Ident) -> PResult<'a, Option<T>>, ) -> PResult<'a, T>
sourcepub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, P<Expr>>
pub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, P<Expr>>
Built-in macro for offset_of!
expressions.
sourcepub(crate) fn parse_expr_type_ascribe(
&mut self,
lo: Span,
) -> PResult<'a, P<Expr>>
pub(crate) fn parse_expr_type_ascribe( &mut self, lo: Span, ) -> PResult<'a, P<Expr>>
Built-in macro for type ascription expressions.
sourcepub fn parse_str_lit(&mut self) -> Result<StrLit, Option<MetaItemLit>>
pub fn parse_str_lit(&mut self) -> Result<StrLit, Option<MetaItemLit>>
Returns a string literal if the next token is a string literal.
In case of error returns Some(lit)
if the next token is a literal with a wrong kind,
and returns None
if the next token is not literal at all.
pub(crate) fn mk_token_lit_char(name: Symbol, span: Span) -> (Lit, Span)
fn mk_meta_item_lit_char(name: Symbol, span: Span) -> MetaItemLit
fn handle_missing_lit<L>( &mut self, mk_lit_char: impl FnOnce(Symbol, Span) -> L, ) -> PResult<'a, L>
pub(super) fn parse_token_lit(&mut self) -> PResult<'a, (Lit, Span)>
pub(super) fn parse_meta_item_lit(&mut self) -> PResult<'a, MetaItemLit>
fn recover_after_dot(&mut self) -> Option<Token>
sourcepub(super) fn parse_opt_token_lit(&mut self) -> Option<(Lit, Span)>
pub(super) fn parse_opt_token_lit(&mut self) -> Option<(Lit, Span)>
Matches lit = true | false | token_lit
.
Returns None
if the next token is not a literal.
sourcepub(super) fn parse_opt_meta_item_lit(&mut self) -> Option<MetaItemLit>
pub(super) fn parse_opt_meta_item_lit(&mut self) -> Option<MetaItemLit>
Matches lit = true | false | token_lit
.
Returns None
if the next token is not a literal.
pub(super) fn expect_no_tuple_index_suffix(&self, span: Span, suffix: Symbol)
sourcepub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>>
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>>
Matches '-' lit | lit
(cf. ast_validation::AstValidator::check_expr_within_pat
).
Keep this in sync with Token::can_begin_literal_maybe_minus
.
fn is_array_like_block(&mut self) -> bool
sourcefn maybe_suggest_brackets_instead_of_braces(
&mut self,
lo: Span,
) -> Option<P<Expr>>
fn maybe_suggest_brackets_instead_of_braces( &mut self, lo: Span, ) -> Option<P<Expr>>
Emits a suggestion if it looks like the user meant an array but accidentally used braces, causing the code to be interpreted as a block expression.
fn suggest_missing_semicolon_before_array( &self, prev_span: Span, open_delim_span: Span, ) -> PResult<'a, ()>
sourcepub(super) fn parse_expr_block(
&mut self,
opt_label: Option<Label>,
lo: Span,
blk_mode: BlockCheckMode,
) -> PResult<'a, P<Expr>>
pub(super) fn parse_expr_block( &mut self, opt_label: Option<Label>, lo: Span, blk_mode: BlockCheckMode, ) -> PResult<'a, P<Expr>>
Parses a block or unsafe block.
sourcefn parse_simple_block(&mut self) -> PResult<'a, P<Expr>>
fn parse_simple_block(&mut self) -> PResult<'a, P<Expr>>
Parse a block which takes no attributes and has no label
sourcefn parse_expr_closure(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_closure(&mut self) -> PResult<'a, P<Expr>>
Parses a closure expression (e.g., move |args| expr
).
sourcefn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy>
fn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy>
Parses an optional move
prefix to a closure-like construct.
sourcefn parse_fn_block_decl(&mut self) -> PResult<'a, (P<FnDecl>, Span)>
fn parse_fn_block_decl(&mut self) -> PResult<'a, (P<FnDecl>, Span)>
Parses the |arg, arg|
header of a closure.
sourcefn parse_fn_block_param(&mut self) -> PResult<'a, Param>
fn parse_fn_block_param(&mut self) -> PResult<'a, Param>
Parses a parameter in a closure header (e.g., |arg, arg|
).
sourcefn parse_expr_if(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_if(&mut self) -> PResult<'a, P<Expr>>
Parses an if
expression (if
token already eaten).
fn parse_if_after_cond( &mut self, lo: Span, cond: P<Expr>, ) -> PResult<'a, P<Expr>>
sourcefn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>>
Parses the condition of a if
or while
expression.
sourcefn parse_expr_let(&mut self, restrictions: Restrictions) -> PResult<'a, P<Expr>>
fn parse_expr_let(&mut self, restrictions: Restrictions) -> PResult<'a, P<Expr>>
Parses a let $pat = $expr
pseudo-expression.
sourcefn parse_expr_else(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_else(&mut self) -> PResult<'a, P<Expr>>
Parses an else { ... }
expression (else
token already eaten).
fn error_on_if_block_attrs( &self, ctx_span: Span, is_ctx_else: bool, branch_span: Span, attrs: AttrWrapper, )
fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()>
fn parse_for_head(&mut self) -> PResult<'a, (P<Pat>, P<Expr>)>
sourcefn parse_expr_for(
&mut self,
opt_label: Option<Label>,
lo: Span,
) -> PResult<'a, P<Expr>>
fn parse_expr_for( &mut self, opt_label: Option<Label>, lo: Span, ) -> PResult<'a, P<Expr>>
Parses for await? <src_pat> in <src_expr> <src_loop_block>
(for
token already eaten).
sourcefn recover_loop_else(
&mut self,
loop_kind: &'static str,
loop_kw: Span,
) -> PResult<'a, ()>
fn recover_loop_else( &mut self, loop_kind: &'static str, loop_kw: Span, ) -> PResult<'a, ()>
Recovers from an else
clause after a loop (for...else
, while...else
)
fn error_missing_in_for_loop(&mut self)
sourcefn parse_expr_while(
&mut self,
opt_label: Option<Label>,
lo: Span,
) -> PResult<'a, P<Expr>>
fn parse_expr_while( &mut self, opt_label: Option<Label>, lo: Span, ) -> PResult<'a, P<Expr>>
Parses a while
or while let
expression (while
token already eaten).
sourcefn parse_expr_loop(
&mut self,
opt_label: Option<Label>,
lo: Span,
) -> PResult<'a, P<Expr>>
fn parse_expr_loop( &mut self, opt_label: Option<Label>, lo: Span, ) -> PResult<'a, P<Expr>>
Parses loop { ... }
(loop
token already eaten).
pub(crate) fn eat_label(&mut self) -> Option<Label>
sourcefn parse_expr_match(&mut self) -> PResult<'a, P<Expr>>
fn parse_expr_match(&mut self) -> PResult<'a, P<Expr>>
Parses a match ... { ... }
expression (match
token already eaten).
sourcefn parse_match_block(
&mut self,
lo: Span,
match_span: Span,
scrutinee: P<Expr>,
match_kind: MatchKind,
) -> PResult<'a, P<Expr>>
fn parse_match_block( &mut self, lo: Span, match_span: Span, scrutinee: P<Expr>, match_kind: MatchKind, ) -> PResult<'a, P<Expr>>
Parses the block of a match expr { ... }
or a expr.match { ... }
expression. This is after the match token and scrutinee are eaten
sourcefn parse_arm_body_missing_braces(
&mut self,
first_expr: &P<Expr>,
arrow_span: Span,
) -> Option<(Span, ErrorGuaranteed)>
fn parse_arm_body_missing_braces( &mut self, first_expr: &P<Expr>, arrow_span: Span, ) -> Option<(Span, ErrorGuaranteed)>
Attempt to recover from match arm body with statements and no surrounding braces.
pub(super) fn parse_arm(&mut self) -> PResult<'a, Arm>
fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<P<Expr>>>
fn parse_match_arm_pat_and_guard( &mut self, ) -> PResult<'a, (P<Pat>, Option<P<Expr>>)>
fn parse_match_guard_condition(&mut self) -> PResult<'a, P<Expr>>
pub(crate) fn is_builtin(&self) -> bool
sourcefn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, P<Expr>>
fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, P<Expr>>
Parses a try {...}
expression (try
token already eaten).
fn is_do_catch_block(&self) -> bool
fn is_do_yeet(&self) -> bool
fn is_try_block(&self) -> bool
sourcefn parse_gen_block(&mut self) -> PResult<'a, P<Expr>>
fn parse_gen_block(&mut self) -> PResult<'a, P<Expr>>
Parses an async move? {...}
or gen move? {...}
expression.
fn is_gen_block(&self, kw: Symbol, lookahead: usize) -> bool
pub(super) fn is_async_gen_block(&self) -> bool
fn is_certainly_not_a_block(&self) -> bool
fn maybe_parse_struct_expr( &mut self, qself: &Option<P<QSelf>>, path: &Path, ) -> Option<PResult<'a, P<Expr>>>
pub(super) fn parse_struct_fields( &mut self, pth: Path, recover: bool, close_delim: Delimiter, ) -> PResult<'a, (ThinVec<ExprField>, StructRest, Option<ErrorGuaranteed>)>
sourcepub(super) fn parse_expr_struct(
&mut self,
qself: Option<P<QSelf>>,
pth: Path,
recover: bool,
) -> PResult<'a, P<Expr>>
pub(super) fn parse_expr_struct( &mut self, qself: Option<P<QSelf>>, pth: Path, recover: bool, ) -> PResult<'a, P<Expr>>
Precondition: already parsed the ‘{’.
fn recover_struct_comma_after_dotdot(&mut self, span: Span)
fn recover_struct_field_dots(&mut self, close_delim: Delimiter) -> bool
sourcefn recover_ident_into_label(&mut self, ident: Ident) -> Label
fn recover_ident_into_label(&mut self, ident: Ident) -> Label
Converts an ident into ’label and emits an “expected a label, found an identifier” error.
sourcefn parse_expr_field(&mut self) -> PResult<'a, ExprField>
fn parse_expr_field(&mut self) -> PResult<'a, ExprField>
Parses ident (COLON expr)?
.
sourcefn error_on_eq_field_init(&self, field_name: Ident)
fn error_on_eq_field_init(&self, field_name: Ident)
Check for =
. This means the source incorrectly attempts to
initialize a field with an eq rather than a colon.
fn err_dotdotdot_syntax(&self, span: Span)
fn err_larrow_operator(&self, span: Span)
fn mk_assign_op(&self, binop: BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ExprKind
fn mk_range( &mut self, start: Option<P<Expr>>, end: Option<P<Expr>>, limits: RangeLimits, ) -> ExprKind
fn mk_unary(&self, unop: UnOp, expr: P<Expr>) -> ExprKind
fn mk_binary(&self, binop: BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ExprKind
fn mk_index(&self, expr: P<Expr>, idx: P<Expr>, brackets_span: Span) -> ExprKind
fn mk_call(&self, f: P<Expr>, args: ThinVec<P<Expr>>) -> ExprKind
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr>
pub(crate) fn mk_expr_with_attrs( &self, span: Span, kind: ExprKind, attrs: AttrVec, ) -> P<Expr>
pub(crate) fn mk_expr(&self, span: Span, kind: ExprKind) -> P<Expr>
pub(super) fn mk_expr_err(&self, span: Span, guar: ErrorGuaranteed) -> P<Expr>
sourcefn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span
fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, rhs_span: Span) -> Span
Create expression span ensuring the span of the parent node is larger than the span of lhs and rhs, including the attributes.
fn collect_tokens_for_expr( &mut self, attrs: AttrWrapper, f: impl FnOnce(&mut Self, AttrVec) -> PResult<'a, P<Expr>>, ) -> PResult<'a, P<Expr>>
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcefn parse_lt_param_bounds(&mut self) -> GenericBounds
fn parse_lt_param_bounds(&mut self) -> GenericBounds
Parses bounds of a lifetime parameter BOUND + BOUND + BOUND
, possibly with trailing +
.
BOUND = LT_BOUND (e.g., `'a`)
sourcefn parse_ty_param(
&mut self,
preceding_attrs: AttrVec,
) -> PResult<'a, GenericParam>
fn parse_ty_param( &mut self, preceding_attrs: AttrVec, ) -> PResult<'a, GenericParam>
Matches typaram = IDENT (
? unbound)? optbounds ( EQ ty )?
.
pub(crate) fn parse_const_param( &mut self, preceding_attrs: AttrVec, ) -> PResult<'a, GenericParam>
pub(crate) fn recover_const_param_with_mistyped_const( &mut self, preceding_attrs: AttrVec, mistyped_const_ident: Ident, ) -> PResult<'a, GenericParam>
sourcepub(super) fn parse_generic_params(
&mut self,
) -> PResult<'a, ThinVec<GenericParam>>
pub(super) fn parse_generic_params( &mut self, ) -> PResult<'a, ThinVec<GenericParam>>
Parses a (possibly empty) list of lifetime and type parameters, possibly including a trailing comma and erroneous trailing attributes.
sourcepub(super) fn parse_generics(&mut self) -> PResult<'a, Generics>
pub(super) fn parse_generics(&mut self) -> PResult<'a, Generics>
Parses a set of optional generic type parameter declarations. Where
clauses are not parsed here, and must be added later via
parse_where_clause()
.
matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > ) | ( < lifetimes , typaramseq ( , )? > ) where typaramseq = ( typaram ) | ( typaram , typaramseq )
sourcepub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause>
pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause>
Parses an optional where-clause.
where T : Trait<U, V> + 'b, 'a : 'b
pub(super) fn parse_struct_where_clause( &mut self, struct_name: Ident, body_insertion_point: Span, ) -> PResult<'a, (WhereClause, Option<ThinVec<FieldDef>>)>
fn parse_where_clause_common( &mut self, struct_: Option<(Ident, Span)>, ) -> PResult<'a, (WhereClause, Option<ThinVec<FieldDef>>)>
fn parse_ty_where_predicate_or_recover_tuple_struct_body( &mut self, struct_: Option<(Ident, Span)>, pred_lo: Span, where_sp: Span, ) -> PResult<'a, PredicateOrStructBody>
fn parse_ty_where_predicate(&mut self) -> PResult<'a, WherePredicate>
pub(super) fn choose_generics_over_qpath(&self, start: usize) -> bool
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn parse_crate_mod(&mut self) -> PResult<'a, Crate>
pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate>
Parses a source module as a crate. This is the main entry point for the parser.
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub fn parse_item( &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<P<Item>>>
fn parse_item_( &mut self, fn_parse_mode: FnParseMode, force_collect: ForceCollect, ) -> PResult<'a, Option<Item>>
pub(super) fn parse_item_common( &mut self, attrs: AttrWrapper, mac_allowed: bool, attrs_allowed: bool, fn_parse_mode: FnParseMode, force_collect: ForceCollect, ) -> PResult<'a, Option<Item>>
sourcefn error_on_unconsumed_default(&self, def: Defaultness, kind: &ItemKind)
fn error_on_unconsumed_default(&self, def: Defaultness, kind: &ItemKind)
Error in-case default
was parsed in an in-appropriate context.
sourcefn parse_item_kind(
&mut self,
attrs: &mut AttrVec,
macros_allowed: bool,
lo: Span,
vis: &Visibility,
def: &mut Defaultness,
fn_parse_mode: FnParseMode,
case: Case,
) -> PResult<'a, Option<(Ident, ItemKind)>>
fn parse_item_kind( &mut self, attrs: &mut AttrVec, macros_allowed: bool, lo: Span, vis: &Visibility, def: &mut Defaultness, fn_parse_mode: FnParseMode, case: Case, ) -> PResult<'a, Option<(Ident, ItemKind)>>
Parses one of the items allowed by the flags.
fn recover_import_as_use(&mut self) -> PResult<'a, Option<(Ident, ItemKind)>>
fn parse_use_item(&mut self) -> PResult<'a, (Ident, ItemKind)>
sourcepub(super) fn is_path_start_item(&mut self) -> bool
pub(super) fn is_path_start_item(&mut self) -> bool
When parsing a statement, would the start of a path be an item?
fn is_reuse_path_item(&mut self) -> bool
sourcefn isnt_macro_invocation(&mut self) -> bool
fn isnt_macro_invocation(&mut self) -> bool
Are we sure this could not possibly be a macro invocation?
sourcefn recover_missing_kw_before_item(&mut self) -> PResult<'a, ()>
fn recover_missing_kw_before_item(&mut self) -> PResult<'a, ()>
Recover on encountering a struct, enum, or method definition where the user
forgot to add the struct
, enum
, or fn
keyword
fn parse_item_builtin(&mut self) -> PResult<'a, Option<(Ident, ItemKind)>>
sourcefn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall>
fn parse_item_macro(&mut self, vis: &Visibility) -> PResult<'a, MacCall>
Parses an item macro, e.g., item!();
.
sourcefn recover_attrs_no_item(&mut self, attrs: &[Attribute]) -> PResult<'a, ()>
fn recover_attrs_no_item(&mut self, attrs: &[Attribute]) -> PResult<'a, ()>
Recover if we parsed attributes and expected an item but there was none.
fn is_async_fn(&self) -> bool
fn parse_polarity(&mut self) -> ImplPolarity
sourcefn parse_item_impl(
&mut self,
attrs: &mut AttrVec,
defaultness: Defaultness,
) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_impl( &mut self, attrs: &mut AttrVec, defaultness: Defaultness, ) -> PResult<'a, (Ident, ItemKind)>
Parses an implementation item.
impl<'a, T> TYPE { /* impl items */ }
impl<'a, T> TRAIT for TYPE { /* impl items */ }
impl<'a, T> !TRAIT for TYPE { /* impl items */ }
impl<'a, T> const TRAIT for TYPE { /* impl items */ }
We actually parse slightly more relaxed grammar for better error reporting and recovery.
"impl" GENERICS "const"? "!"? TYPE "for"? (TYPE | "..") ("where" PREDICATES)? "{" BODY "}"
"impl" GENERICS "const"? "!"? TYPE ("where" PREDICATES)? "{" BODY "}"
fn parse_item_delegation(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_list<T>( &mut self, attrs: &mut AttrVec, parse_item: impl FnMut(&mut Parser<'a>) -> PResult<'a, Option<Option<T>>>, ) -> PResult<'a, ThinVec<T>>
sourcefn recover_doc_comment_before_brace(&mut self) -> bool
fn recover_doc_comment_before_brace(&mut self) -> bool
Recover on a doc comment before }
.
sourcefn parse_defaultness(&mut self) -> Defaultness
fn parse_defaultness(&mut self) -> Defaultness
Parses defaultness (i.e., default
or nothing).
sourcefn check_auto_or_unsafe_trait_item(&mut self) -> bool
fn check_auto_or_unsafe_trait_item(&mut self) -> bool
Is this an (unsafe auto? | auto) trait
item?
sourcefn parse_item_trait(
&mut self,
attrs: &mut AttrVec,
lo: Span,
) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_trait( &mut self, attrs: &mut AttrVec, lo: Span, ) -> PResult<'a, (Ident, ItemKind)>
Parses unsafe? auto? trait Foo { ... }
or trait Foo = Bar;
.
pub fn parse_impl_item( &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<Option<P<AssocItem>>>>
pub fn parse_trait_item( &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<Option<P<AssocItem>>>>
sourcefn parse_assoc_item(
&mut self,
fn_parse_mode: FnParseMode,
force_collect: ForceCollect,
) -> PResult<'a, Option<Option<P<AssocItem>>>>
fn parse_assoc_item( &mut self, fn_parse_mode: FnParseMode, force_collect: ForceCollect, ) -> PResult<'a, Option<Option<P<AssocItem>>>>
Parses associated items.
sourcefn parse_type_alias(
&mut self,
defaultness: Defaultness,
) -> PResult<'a, (Ident, ItemKind)>
fn parse_type_alias( &mut self, defaultness: Defaultness, ) -> PResult<'a, (Ident, ItemKind)>
Parses a type
alias with the following grammar:
TypeAlias = "type" Ident Generics (":" GenericBounds)? WhereClause ("=" Ty)? WhereClause ";" ;
The "type"
has already been eaten.
sourcefn parse_use_tree(&mut self) -> PResult<'a, UseTree>
fn parse_use_tree(&mut self) -> PResult<'a, UseTree>
Parses a UseTree
.
USE_TREE = [`::`] `*` |
[`::`] `{` USE_TREE_LIST `}` |
PATH `::` `*` |
PATH `::` `{` USE_TREE_LIST `}` |
PATH [`as` IDENT]
sourcefn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind>
fn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind>
Parses *
or {...}
.
sourcefn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, NodeId)>>
fn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, NodeId)>>
Parses a UseTreeKind::Nested(list)
.
USE_TREE_LIST = ∅ | (USE_TREE `,`)* USE_TREE [`,`]
fn parse_rename(&mut self) -> PResult<'a, Option<Ident>>
fn parse_ident_or_underscore(&mut self) -> PResult<'a, Ident>
sourcefn parse_item_extern_crate(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_extern_crate(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_crate_name_with_dashes(&mut self) -> PResult<'a, Ident>
sourcefn parse_item_foreign_mod(
&mut self,
attrs: &mut AttrVec,
safety: Safety,
) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_foreign_mod( &mut self, attrs: &mut AttrVec, safety: Safety, ) -> PResult<'a, (Ident, ItemKind)>
sourcepub fn parse_foreign_item(
&mut self,
force_collect: ForceCollect,
) -> PResult<'a, Option<Option<P<ForeignItem>>>>
pub fn parse_foreign_item( &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<Option<P<ForeignItem>>>>
Parses a foreign item (one in an extern { ... }
block).
fn error_bad_item_kind<T>( &self, span: Span, kind: &ItemKind, ctx: &'static str, ) -> Option<T>
fn is_unsafe_foreign_mod(&self) -> bool
fn is_static_global(&mut self) -> bool
sourcefn recover_const_mut(&mut self, const_span: Span)
fn recover_const_mut(&mut self, const_span: Span)
Recover on const mut
with const
already eaten.
sourcefn recover_const_impl(
&mut self,
const_span: Span,
attrs: &mut AttrVec,
defaultness: Defaultness,
) -> PResult<'a, (Ident, ItemKind)>
fn recover_const_impl( &mut self, const_span: Span, attrs: &mut AttrVec, defaultness: Defaultness, ) -> PResult<'a, (Ident, ItemKind)>
Recover on const impl
with const
already eaten.
sourcefn parse_static_item(
&mut self,
safety: Safety,
mutability: Mutability,
) -> PResult<'a, (Ident, StaticItem)>
fn parse_static_item( &mut self, safety: Safety, mutability: Mutability, ) -> PResult<'a, (Ident, StaticItem)>
Parse a static item with the prefix "static" "mut"?
already parsed and stored in mutability
.
Static = "static" "mut"? $ident ":" $ty (= $expr)? ";" ;
sourcefn parse_const_item(
&mut self,
) -> PResult<'a, (Ident, Generics, P<Ty>, Option<P<Expr>>)>
fn parse_const_item( &mut self, ) -> PResult<'a, (Ident, Generics, P<Ty>, Option<P<Expr>>)>
Parse a constant item with the prefix "const"
already parsed.
Const = "const" ($ident | "_") Generics ":" $ty (= $expr)? WhereClause ";" ;
sourcefn recover_missing_global_item_type(
&mut self,
colon_present: bool,
m: Option<Mutability>,
) -> P<Ty>
fn recover_missing_global_item_type( &mut self, colon_present: bool, m: Option<Mutability>, ) -> P<Ty>
We were supposed to parse ":" $ty
but the :
or the type was missing.
This means that the type is missing.
sourcefn parse_item_enum(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_enum(&mut self) -> PResult<'a, (Ident, ItemKind)>
Parses an enum declaration.
fn parse_enum_variant(&mut self, span: Span) -> PResult<'a, Option<Variant>>
sourcefn parse_item_struct(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_struct(&mut self) -> PResult<'a, (Ident, ItemKind)>
Parses struct Foo { ... }
.
sourcefn parse_item_union(&mut self) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_union(&mut self) -> PResult<'a, (Ident, ItemKind)>
Parses union Foo { ... }
.
sourcepub(crate) fn parse_record_struct_body(
&mut self,
adt_ty: &str,
ident_span: Span,
parsed_where: bool,
) -> PResult<'a, (ThinVec<FieldDef>, Recovered)>
pub(crate) fn parse_record_struct_body( &mut self, adt_ty: &str, ident_span: Span, parsed_where: bool, ) -> PResult<'a, (ThinVec<FieldDef>, Recovered)>
This function parses the fields of record structs:
struct S { ... }
enum E { Variant { ... } }
pub(super) fn parse_tuple_struct_body( &mut self, ) -> PResult<'a, ThinVec<FieldDef>>
sourcefn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef>
fn parse_field_def(&mut self, adt_ty: &str) -> PResult<'a, FieldDef>
Parses an element of a struct declaration.
sourcefn parse_single_struct_field(
&mut self,
adt_ty: &str,
lo: Span,
vis: Visibility,
attrs: AttrVec,
) -> PResult<'a, FieldDef>
fn parse_single_struct_field( &mut self, adt_ty: &str, lo: Span, vis: Visibility, attrs: AttrVec, ) -> PResult<'a, FieldDef>
Parses a structure field declaration.
fn expect_field_ty_separator(&mut self) -> PResult<'a, ()>
sourcefn parse_name_and_ty(
&mut self,
adt_ty: &str,
lo: Span,
vis: Visibility,
attrs: AttrVec,
) -> PResult<'a, FieldDef>
fn parse_name_and_ty( &mut self, adt_ty: &str, lo: Span, vis: Visibility, attrs: AttrVec, ) -> PResult<'a, FieldDef>
Parses a structure field.
sourcefn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident>
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident>
Parses a field identifier. Specialized version of parse_ident_common
for better diagnostics and suggestions.
sourcefn parse_item_decl_macro(&mut self, lo: Span) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_decl_macro(&mut self, lo: Span) -> PResult<'a, (Ident, ItemKind)>
Parses a declarative macro 2.0 definition.
The macro
keyword has already been parsed.
MacBody = "{" TOKEN_STREAM "}" ;
MacParams = "(" TOKEN_STREAM ")" ;
DeclMac = "macro" Ident MacParams? MacBody ;
sourcefn is_macro_rules_item(&mut self) -> IsMacroRulesItem
fn is_macro_rules_item(&mut self) -> IsMacroRulesItem
Is this a possibly malformed start of a macro_rules! foo
item definition?
sourcefn parse_item_macro_rules(
&mut self,
vis: &Visibility,
has_bang: bool,
) -> PResult<'a, (Ident, ItemKind)>
fn parse_item_macro_rules( &mut self, vis: &Visibility, has_bang: bool, ) -> PResult<'a, (Ident, ItemKind)>
Parses a macro_rules! foo { ... }
declarative macro.
sourcefn complain_if_pub_macro(&self, vis: &Visibility, macro_rules: bool)
fn complain_if_pub_macro(&self, vis: &Visibility, macro_rules: bool)
Item macro invocations or macro_rules!
definitions need inherited visibility.
If that’s not the case, emit an error.
fn eat_semi_for_macro_if_needed(&mut self, args: &DelimArgs)
fn report_invalid_macro_expansion_item(&self, args: &DelimArgs)
sourcefn recover_nested_adt_item(&mut self, keyword: Symbol) -> PResult<'a, bool>
fn recover_nested_adt_item(&mut self, keyword: Symbol) -> PResult<'a, bool>
Checks if current token is one of tokens which cannot be nested like kw::Enum
. In case
it is, we try to parse the item and report error about nested types.
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Parsing of functions and methods.
sourcefn parse_fn(
&mut self,
attrs: &mut AttrVec,
fn_parse_mode: FnParseMode,
sig_lo: Span,
vis: &Visibility,
case: Case,
) -> PResult<'a, (Ident, FnSig, Generics, Option<P<Block>>)>
fn parse_fn( &mut self, attrs: &mut AttrVec, fn_parse_mode: FnParseMode, sig_lo: Span, vis: &Visibility, case: Case, ) -> PResult<'a, (Ident, FnSig, Generics, Option<P<Block>>)>
Parse a function starting from the front matter (const ...
) to the body { ... }
or ;
.
sourcefn error_fn_body_not_found(
&mut self,
ident_span: Span,
req_body: bool,
fn_params_end: Option<Span>,
) -> PResult<'a, ErrorGuaranteed>
fn error_fn_body_not_found( &mut self, ident_span: Span, req_body: bool, fn_params_end: Option<Span>, ) -> PResult<'a, ErrorGuaranteed>
Provide diagnostics when function body is not found
sourcefn parse_fn_body(
&mut self,
attrs: &mut AttrVec,
ident: &Ident,
sig_hi: &mut Span,
req_body: bool,
fn_params_end: Option<Span>,
) -> PResult<'a, Option<P<Block>>>
fn parse_fn_body( &mut self, attrs: &mut AttrVec, ident: &Ident, sig_hi: &mut Span, req_body: bool, fn_params_end: Option<Span>, ) -> PResult<'a, Option<P<Block>>>
Parse the “body” of a function.
This can either be ;
when there’s no body,
or e.g. a block when the function is a provided one.
sourcepub(super) fn check_fn_front_matter(
&mut self,
check_pub: bool,
case: Case,
) -> bool
pub(super) fn check_fn_front_matter( &mut self, check_pub: bool, case: Case, ) -> bool
Is the current token the start of an FnHeader
/ not a valid parse?
check_pub
adds additional pub
to the checks in case users place it
wrongly, can be used to ensure pub
never comes after default
.
sourcepub(super) fn parse_fn_front_matter(
&mut self,
orig_vis: &Visibility,
case: Case,
) -> PResult<'a, FnHeader>
pub(super) fn parse_fn_front_matter( &mut self, orig_vis: &Visibility, case: Case, ) -> PResult<'a, FnHeader>
Parses all the “front matter” (or “qualifiers”) for a fn
declaration,
up to and including the fn
keyword. The formal grammar is:
Extern = "extern" StringLit? ;
FnQual = "const"? "async"? "unsafe"? Extern? ;
FnFrontMatter = FnQual "fn" ;
vis
represents the visibility that was already parsed, if any. Use
Visibility::Inherited
when no visibility is known.
sourcepub(super) fn parse_fn_decl(
&mut self,
req_name: fn(_: Edition) -> bool,
ret_allow_plus: AllowPlus,
recover_return_sign: RecoverReturnSign,
) -> PResult<'a, P<FnDecl>>
pub(super) fn parse_fn_decl( &mut self, req_name: fn(_: Edition) -> bool, ret_allow_plus: AllowPlus, recover_return_sign: RecoverReturnSign, ) -> PResult<'a, P<FnDecl>>
Parses the parameter list and result type of a function declaration.
sourcepub(super) fn parse_fn_params(
&mut self,
req_name: fn(_: Edition) -> bool,
) -> PResult<'a, ThinVec<Param>>
pub(super) fn parse_fn_params( &mut self, req_name: fn(_: Edition) -> bool, ) -> PResult<'a, ThinVec<Param>>
Parses the parameter list of a function, including the (
and )
delimiters.
sourcefn parse_param_general(
&mut self,
req_name: fn(_: Edition) -> bool,
first_param: bool,
) -> PResult<'a, Param>
fn parse_param_general( &mut self, req_name: fn(_: Edition) -> bool, first_param: bool, ) -> PResult<'a, Param>
Parses a single function parameter.
self
is syntactically allowed whenfirst_param
holds.
sourcefn parse_self_param(&mut self) -> PResult<'a, Option<Param>>
fn parse_self_param(&mut self) -> PResult<'a, Option<Param>>
Returns the parsed optional self parameter and whether a self shortcut was used.
fn is_named_param(&self) -> bool
fn recover_self_param(&mut self) -> bool
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool
pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool
Checks whether a non-terminal may begin with a particular token.
Returning false
is a stability guarantee that such a matcher will never begin with
that token. Be conservative (return true) if not sure. Inlined because it has a single call
site.
sourcepub fn parse_nonterminal(
&mut self,
kind: NonterminalKind,
) -> PResult<'a, ParseNtResult>
pub fn parse_nonterminal( &mut self, kind: NonterminalKind, ) -> PResult<'a, ParseNtResult>
Parse a non-terminal (e.g. MBE :pat
or :ident
). Inlined because there is only one call
site.
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub fn parse_pat_no_top_alt(
&mut self,
expected: Option<Expected>,
syntax_loc: Option<PatternLocation>,
) -> PResult<'a, P<Pat>>
pub fn parse_pat_no_top_alt( &mut self, expected: Option<Expected>, syntax_loc: Option<PatternLocation>, ) -> PResult<'a, P<Pat>>
Parses a pattern.
Corresponds to pat<no_top_alt>
in RFC 2535 and does not admit or-patterns
at the top level. Used when parsing the parameters of lambda expressions,
functions, function pointers, and pat
macro fragments.
sourcepub fn parse_pat_allow_top_alt(
&mut self,
expected: Option<Expected>,
rc: RecoverComma,
ra: RecoverColon,
rt: CommaRecoveryMode,
) -> PResult<'a, P<Pat>>
pub fn parse_pat_allow_top_alt( &mut self, expected: Option<Expected>, rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, ) -> PResult<'a, P<Pat>>
Parses a pattern.
Corresponds to top_pat
in RFC 2535 and allows or-pattern at the top level.
Used for parsing patterns in all cases when pat<no_top_alt>
is not used.
Note that after the FCP in https://github.com/rust-lang/rust/issues/81415, a leading vert is allowed in nested or-patterns, too. This allows us to simplify the grammar somewhat.
sourcefn parse_pat_allow_top_alt_inner(
&mut self,
expected: Option<Expected>,
rc: RecoverComma,
ra: RecoverColon,
rt: CommaRecoveryMode,
syntax_loc: Option<PatternLocation>,
) -> PResult<'a, (P<Pat>, bool)>
fn parse_pat_allow_top_alt_inner( &mut self, expected: Option<Expected>, rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, syntax_loc: Option<PatternLocation>, ) -> PResult<'a, (P<Pat>, bool)>
Returns the pattern and a bool indicating whether we recovered from a trailing vert (true = recovered).
sourcepub(super) fn parse_pat_before_ty(
&mut self,
expected: Option<Expected>,
rc: RecoverComma,
syntax_loc: PatternLocation,
) -> PResult<'a, (P<Pat>, bool)>
pub(super) fn parse_pat_before_ty( &mut self, expected: Option<Expected>, rc: RecoverComma, syntax_loc: PatternLocation, ) -> PResult<'a, (P<Pat>, bool)>
Parse a pattern and (maybe) a Colon
in positions where a pattern may be followed by a
type annotation (e.g. for let
bindings or fn
params).
Generally, this corresponds to pat_no_top_alt
followed by an optional Colon
. It will
eat the Colon
token if one is present.
The return value represents the parsed pattern and true
if a Colon
was parsed (false
otherwise).
sourcepub(super) fn parse_fn_param_pat_colon(&mut self) -> PResult<'a, (P<Pat>, bool)>
pub(super) fn parse_fn_param_pat_colon(&mut self) -> PResult<'a, (P<Pat>, bool)>
Parse the pattern for a function or function pointer parameter, followed by a colon.
The return value represents the parsed pattern and true
if a Colon
was parsed (false
otherwise).
sourcefn eat_or_separator(&mut self, lo: Option<Span>) -> EatOrResult
fn eat_or_separator(&mut self, lo: Option<Span>) -> EatOrResult
Eat the or-pattern |
separator.
If instead a ||
token is encountered, recover and pretend we parsed |
.
sourcefn recover_trailing_vert(&mut self, lo: Option<Span>) -> bool
fn recover_trailing_vert(&mut self, lo: Option<Span>) -> bool
Recover if |
or ||
is the current token and we have one of the
tokens =>
, if
, =
, :
, ;
, ,
, ]
, )
, or }
ahead of us.
These tokens all indicate that we reached the end of the or-pattern
list and can now reliably say that the |
was an illegal trailing vert.
Note that there are more tokens such as @
for which we know that the |
is an illegal parse. However, the user’s intent is less clear in that case.
sourcefn maybe_recover_trailing_expr(
&mut self,
pat_span: Span,
is_end_bound: bool,
) -> Option<ErrorGuaranteed>
fn maybe_recover_trailing_expr( &mut self, pat_span: Span, is_end_bound: bool, ) -> Option<ErrorGuaranteed>
Ensures that the last parsed pattern (or pattern range bound) is not followed by a method call or an operator.
is_end_bound
indicates whether the last parsed thing was the end bound of a range pattern (see parse_pat_range_end
)
in order to say “expected a pattern range bound” instead of “expected a pattern”;
0..=1 + 2
^^^^^
Only the end bound is spanned, and this function have no idea if there were a ..=
before pat_span
, hence the parameter.
sourcefn parse_pat_with_range_pat(
&mut self,
allow_range_pat: bool,
expected: Option<Expected>,
syntax_loc: Option<PatternLocation>,
) -> PResult<'a, P<Pat>>
fn parse_pat_with_range_pat( &mut self, allow_range_pat: bool, expected: Option<Expected>, syntax_loc: Option<PatternLocation>, ) -> PResult<'a, P<Pat>>
Parses a pattern, with a setting whether modern range patterns (e.g., a..=b
, a..b
are
allowed).
sourcefn recover_dotdotdot_rest_pat(&mut self, lo: Span) -> PatKind
fn recover_dotdotdot_rest_pat(&mut self, lo: Span) -> PatKind
Recover from a typoed ...
pattern that was encountered
Ref: Issue #70388
sourcefn recover_intersection_pat(&mut self, lhs: P<Pat>) -> PResult<'a, P<Pat>>
fn recover_intersection_pat(&mut self, lhs: P<Pat>) -> PResult<'a, P<Pat>>
Try to recover the more general form intersect ::= $pat_lhs @ $pat_rhs
.
Allowed binding patterns generated by binding ::= ref? mut? $ident @ $pat_rhs
should already have been parsed by now at this point,
if the next token is @
then we can try to parse the more general form.
Consult parse_pat_ident
for the binding
grammar.
The notion of intersection patterns are found in e.g. F# where they are called AND-patterns.
sourcefn ban_pat_range_if_ambiguous(&self, pat: &Pat)
fn ban_pat_range_if_ambiguous(&self, pat: &Pat)
Ban a range pattern if it has an ambiguous interpretation.
sourcefn parse_pat_deref(
&mut self,
expected: Option<Expected>,
) -> PResult<'a, PatKind>
fn parse_pat_deref( &mut self, expected: Option<Expected>, ) -> PResult<'a, PatKind>
Parse &pat
/ &mut pat
.
sourcefn parse_pat_tuple_or_parens(&mut self) -> PResult<'a, PatKind>
fn parse_pat_tuple_or_parens(&mut self) -> PResult<'a, PatKind>
Parse a tuple or parenthesis pattern.
sourcefn parse_pat_ident_mut(&mut self) -> PResult<'a, PatKind>
fn parse_pat_ident_mut(&mut self) -> PResult<'a, PatKind>
Parse a mutable binding with the mut
token already eaten.
sourcefn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool
Turn all by-value immutable bindings in a pattern into mutable bindings.
Returns true
if any change was made.
sourcefn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool)
fn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool)
Error on mut $pat
where $pat
is not an ident.
sourcefn recover_additional_muts(&mut self)
fn recover_additional_muts(&mut self)
Eat any extraneous mut
s and error + recover if we ate any.
sourcefn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind>
fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind>
Parse macro invocation
fn fatal_unexpected_non_pat( &mut self, err: Diag<'a>, expected: Option<Expected>, ) -> PResult<'a, P<Pat>>
sourcefn parse_range_end(&mut self) -> Option<Spanned<RangeEnd>>
fn parse_range_end(&mut self) -> Option<Spanned<RangeEnd>>
Parses the range pattern end form ".." | "..." | "..=" ;
.
sourcefn parse_pat_range_begin_with(
&mut self,
begin: P<Expr>,
re: Spanned<RangeEnd>,
) -> PResult<'a, PatKind>
fn parse_pat_range_begin_with( &mut self, begin: P<Expr>, re: Spanned<RangeEnd>, ) -> PResult<'a, PatKind>
Parse a range pattern $begin $form $end?
where $form = ".." | "..." | "..=" ;
.
$begin $form
has already been parsed.
pub(super) fn inclusive_range_with_incorrect_end(&mut self) -> ErrorGuaranteed
sourcefn parse_pat_range_to(&mut self, re: Spanned<RangeEnd>) -> PResult<'a, PatKind>
fn parse_pat_range_to(&mut self, re: Spanned<RangeEnd>) -> PResult<'a, PatKind>
Parse a range-to pattern, ..X
or ..=X
where X
remains to be parsed.
The form ...X
is prohibited to reduce confusion with the potential
expression syntax ...expr
for splatting in expressions.
sourcefn is_pat_range_end_start(&self, dist: usize) -> bool
fn is_pat_range_end_start(&self, dist: usize) -> bool
Is the token dist
away from the current suitable as the start of a range patterns end?
sourcefn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>>
fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>>
Parse a range pattern end bound
sourcefn is_start_of_pat_with_path(&mut self) -> bool
fn is_start_of_pat_with_path(&mut self) -> bool
Is this the start of a pattern beginning with a path?
sourcefn can_be_ident_pat(&mut self) -> bool
fn can_be_ident_pat(&mut self) -> bool
Would parse_pat_ident
be appropriate here?
sourcefn parse_pat_ident(
&mut self,
binding_annotation: BindingMode,
syntax_loc: Option<PatternLocation>,
) -> PResult<'a, PatKind>
fn parse_pat_ident( &mut self, binding_annotation: BindingMode, syntax_loc: Option<PatternLocation>, ) -> PResult<'a, PatKind>
Parses ident
or ident @ pat
.
Used by the copy foo and ref foo patterns to give a good
error message when parsing mistakes like ref foo(a, b)
.
sourcefn parse_pat_struct(
&mut self,
qself: Option<P<QSelf>>,
path: Path,
) -> PResult<'a, PatKind>
fn parse_pat_struct( &mut self, qself: Option<P<QSelf>>, path: Path, ) -> PResult<'a, PatKind>
Parse a struct (“record”) pattern (e.g. Foo { ... }
or Foo::Bar { ... }
).
sourcefn parse_pat_tuple_struct(
&mut self,
qself: Option<P<QSelf>>,
path: Path,
) -> PResult<'a, PatKind>
fn parse_pat_tuple_struct( &mut self, qself: Option<P<QSelf>>, path: Path, ) -> PResult<'a, PatKind>
Parse tuple struct or tuple variant pattern (e.g. Foo(...)
or Foo::Bar(...)
).
sourcefn isnt_pattern_start(&self) -> bool
fn isnt_pattern_start(&self) -> bool
Are we sure this could not possibly be the start of a pattern?
Currently, this only accounts for tokens that can follow identifiers in patterns, but this can be extended as necessary.
fn parse_pat_builtin(&mut self) -> PResult<'a, PatKind>
sourcefn parse_pat_box(&mut self) -> PResult<'a, PatKind>
fn parse_pat_box(&mut self) -> PResult<'a, PatKind>
Parses box pat
sourcefn parse_pat_fields(
&mut self,
) -> PResult<'a, (ThinVec<PatField>, PatFieldsRest)>
fn parse_pat_fields( &mut self, ) -> PResult<'a, (ThinVec<PatField>, PatFieldsRest)>
Parses the fields of a struct-like pattern.
sourcefn recover_misplaced_pattern_modifiers(
&self,
fields: &ThinVec<PatField>,
err: &mut Diag<'a>,
)
fn recover_misplaced_pattern_modifiers( &self, fields: &ThinVec<PatField>, err: &mut Diag<'a>, )
If the user writes S { ref field: name }
instead of S { field: ref name }
, we suggest
the correct code.
sourcefn recover_bad_dot_dot(&self)
fn recover_bad_dot_dot(&self)
Recover on ...
or _
as if it were ..
to avoid further errors.
See issue #46718.
fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField>
pub(super) fn mk_pat_ident( &self, span: Span, ann: BindingMode, ident: Ident, ) -> P<Pat>
pub(super) fn mk_pat(&self, span: Span, kind: PatKind) -> P<Pat>
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub(super) fn parse_qpath(
&mut self,
style: PathStyle,
) -> PResult<'a, (P<QSelf>, Path)>
pub(super) fn parse_qpath( &mut self, style: PathStyle, ) -> PResult<'a, (P<QSelf>, Path)>
Parses a qualified path.
Assumes that the leading <
has been parsed already.
qualified_path = <type [as trait_ref]>::path
§Examples
<T>::default
<T as U>::a
<T as U>::F::a<S>
(without disambiguator)
<T as U>::F::a::<S>
(with disambiguator)
sourcefn recover_colon_before_qpath_proj(&mut self) -> bool
fn recover_colon_before_qpath_proj(&mut self) -> bool
Recover from an invalid single colon, when the user likely meant a qualified path. We avoid emitting this if not followed by an identifier, as our assumption that the user intended this to be a qualified path may not be correct.
<Bar as Baz<T>>:Qux
^ help: use double colon
pub(super) fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path>
sourcepub(super) fn parse_path_inner(
&mut self,
style: PathStyle,
ty_generics: Option<&Generics>,
) -> PResult<'a, Path>
pub(super) fn parse_path_inner( &mut self, style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, Path>
Parses simple paths.
path = [::] segment+
segment = ident | ident[::]<args> | ident[::](args) [-> type]
§Examples
a::b::C<D>
(without disambiguator)
a::b::C::<D>
(with disambiguator)
Fn(Args)
(without disambiguator)
Fn::(Args)
(with disambiguator)
pub(super) fn parse_path_segments( &mut self, segments: &mut ThinVec<PathSegment>, style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, ()>
pub(super) fn parse_path_segment( &mut self, style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, PathSegment>
pub(super) fn parse_path_segment_ident(&mut self) -> PResult<'a, Ident>
sourcefn recover_fn_call_leading_path_sep(
&mut self,
style: PathStyle,
prev_token_before_parsing: Token,
error: &mut Diag<'_>,
)
fn recover_fn_call_leading_path_sep( &mut self, style: PathStyle, prev_token_before_parsing: Token, error: &mut Diag<'_>, )
Recover $path::(...)
as $path(...)
.
foo::(420, "bar")
^^ remove extra separator to make the function call
// or
match x {
Foo::(420, "bar") => { ... },
^^ remove extra separator to turn this into tuple struct pattern
_ => { ... },
}
sourcefn parse_angle_args_with_leading_angle_bracket_recovery(
&mut self,
style: PathStyle,
lo: Span,
ty_generics: Option<&Generics>,
) -> PResult<'a, ThinVec<AngleBracketedArg>>
fn parse_angle_args_with_leading_angle_bracket_recovery( &mut self, style: PathStyle, lo: Span, ty_generics: Option<&Generics>, ) -> PResult<'a, ThinVec<AngleBracketedArg>>
Parses generic args (within a path segment) with recovery for extra leading angle brackets.
For the purposes of understanding the parsing logic of generic arguments, this function
can be thought of being the same as just calling self.parse_angle_args()
if the source
had the correct amount of leading angle brackets.
bar::<<<<T as Foo>::Output>();
^^ help: remove extra angle brackets
sourcepub(super) fn parse_angle_args(
&mut self,
ty_generics: Option<&Generics>,
) -> PResult<'a, ThinVec<AngleBracketedArg>>
pub(super) fn parse_angle_args( &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, ThinVec<AngleBracketedArg>>
Parses (possibly empty) list of generic arguments / associated item constraints, possibly including trailing comma.
sourcefn parse_angle_arg(
&mut self,
ty_generics: Option<&Generics>,
) -> PResult<'a, Option<AngleBracketedArg>>
fn parse_angle_arg( &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, Option<AngleBracketedArg>>
Parses a single argument in the angle arguments <...>
of a path segment.
sourcefn parse_assoc_equality_term(
&mut self,
ident: Ident,
gen_args: Option<&GenericArgs>,
eq: Span,
) -> PResult<'a, AssocItemConstraintKind>
fn parse_assoc_equality_term( &mut self, ident: Ident, gen_args: Option<&GenericArgs>, eq: Span, ) -> PResult<'a, AssocItemConstraintKind>
Parse the term to the right of an associated item equality constraint.
That is, parse $term
in Item = $term
where $term
is a type or
a const expression (wrapped in curly braces if complex).
sourcepub(super) fn expr_is_valid_const_arg(&self, expr: &P<Expr>) -> bool
pub(super) fn expr_is_valid_const_arg(&self, expr: &P<Expr>) -> bool
We do not permit arbitrary expressions as const arguments. They must be one of:
- An expression surrounded in
{}
. - A literal.
- A numeric literal prefixed by
-
. - A single-segment path.
sourcepub(super) fn parse_const_arg(&mut self) -> PResult<'a, AnonConst>
pub(super) fn parse_const_arg(&mut self) -> PResult<'a, AnonConst>
Parse a const argument, e.g. <3>
. It is assumed the angle brackets will be parsed by
the caller.
sourcepub(super) fn parse_generic_arg(
&mut self,
ty_generics: Option<&Generics>,
) -> PResult<'a, Option<GenericArg>>
pub(super) fn parse_generic_arg( &mut self, ty_generics: Option<&Generics>, ) -> PResult<'a, Option<GenericArg>>
Parse a generic argument in a path segment.
This does not include constraints, e.g., Item = u8
, which is handled in parse_angle_arg
.
sourcefn get_ident_from_generic_arg(
&self,
gen_arg: &GenericArg,
) -> Result<(bool, Ident, Option<GenericArgs>), ()>
fn get_ident_from_generic_arg( &self, gen_arg: &GenericArg, ) -> Result<(bool, Ident, Option<GenericArgs>), ()>
Given a arg inside of generics, we try to destructure it as if it were the LHS in
LHS = ...
, i.e. an associated item binding.
This returns a bool indicating if there are any for<'a, 'b>
binder args, the
identifier, and any GAT arguments.
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
sourcepub(super) fn parse_stmt(
&mut self,
force_collect: ForceCollect,
) -> PResult<'a, Option<Stmt>>
pub(super) fn parse_stmt( &mut self, force_collect: ForceCollect, ) -> PResult<'a, Option<Stmt>>
Parses a statement. This stops just before trailing semicolons on everything but items.
e.g., a StmtKind::Semi
parses to a StmtKind::Expr
, leaving the trailing ;
unconsumed.
sourcepub fn parse_stmt_without_recovery(
&mut self,
capture_semi: bool,
force_collect: ForceCollect,
) -> PResult<'a, Option<Stmt>>
pub fn parse_stmt_without_recovery( &mut self, capture_semi: bool, force_collect: ForceCollect, ) -> PResult<'a, Option<Stmt>>
If force_collect
is ForceCollect::Yes
, forces collection of tokens regardless of
whether or not we have attributes.
fn parse_stmt_path_start( &mut self, lo: Span, attrs: AttrWrapper, ) -> PResult<'a, Stmt>
sourcefn parse_stmt_mac(
&mut self,
lo: Span,
attrs: AttrVec,
path: Path,
) -> PResult<'a, Stmt>
fn parse_stmt_mac( &mut self, lo: Span, attrs: AttrVec, path: Path, ) -> PResult<'a, Stmt>
Parses a statement macro mac!(args)
provided a path
representing mac
.
At this point, the !
token after the path has already been eaten.
sourcefn error_outer_attrs(&self, attrs: AttrWrapper)
fn error_outer_attrs(&self, attrs: AttrWrapper)
Error on outer attributes in this context. Also error if the previous token was a doc comment.
fn recover_stmt_local_after_let( &mut self, lo: Span, attrs: AttrWrapper, subdiagnostic: fn(_: Span) -> InvalidVariableDeclarationSub, force_collect: ForceCollect, ) -> PResult<'a, Stmt>
fn parse_local_mk( &mut self, lo: Span, attrs: AttrWrapper, capture_semi: bool, force_collect: ForceCollect, ) -> PResult<'a, Stmt>
sourcefn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>>
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>>
Parses a local variable declaration.
fn check_let_else_init_bool_expr(&self, init: &Expr)
fn check_let_else_init_trailing_brace(&self, init: &Expr)
sourcefn parse_initializer(
&mut self,
eq_optional: bool,
) -> PResult<'a, Option<P<Expr>>>
fn parse_initializer( &mut self, eq_optional: bool, ) -> PResult<'a, Option<P<Expr>>>
Parses the RHS of a local variable declaration (e.g., = 14;
).
sourcepub fn parse_block(&mut self) -> PResult<'a, P<Block>>
pub fn parse_block(&mut self) -> PResult<'a, P<Block>>
Parses a block. No inner attributes are allowed.
fn error_block_no_opening_brace_msg( &mut self, msg: Cow<'static, str>, ) -> Diag<'a>
fn error_block_no_opening_brace<T>(&mut self) -> PResult<'a, T>
sourcepub(super) fn parse_inner_attrs_and_block(
&mut self,
) -> PResult<'a, (AttrVec, P<Block>)>
pub(super) fn parse_inner_attrs_and_block( &mut self, ) -> PResult<'a, (AttrVec, P<Block>)>
Parses a block. Inner attributes are allowed.
sourcepub(super) fn parse_block_common(
&mut self,
lo: Span,
blk_mode: BlockCheckMode,
can_be_struct_literal: bool,
) -> PResult<'a, (AttrVec, P<Block>)>
pub(super) fn parse_block_common( &mut self, lo: Span, blk_mode: BlockCheckMode, can_be_struct_literal: bool, ) -> PResult<'a, (AttrVec, P<Block>)>
Parses a block. Inner attributes are allowed.
sourcepub(crate) fn parse_block_tail(
&mut self,
lo: Span,
s: BlockCheckMode,
recover: AttemptLocalParseRecovery,
) -> PResult<'a, P<Block>>
pub(crate) fn parse_block_tail( &mut self, lo: Span, s: BlockCheckMode, recover: AttemptLocalParseRecovery, ) -> PResult<'a, P<Block>>
Parses the rest of a block expression or function body. Precondition: already parsed the ‘{’.
sourcepub fn parse_full_stmt(
&mut self,
recover: AttemptLocalParseRecovery,
) -> PResult<'a, Option<Stmt>>
pub fn parse_full_stmt( &mut self, recover: AttemptLocalParseRecovery, ) -> PResult<'a, Option<Stmt>>
Parses a statement, including the trailing semicolon.
pub(super) fn mk_block( &self, stmts: ThinVec<Stmt>, rules: BlockCheckMode, span: Span, ) -> P<Block>
pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt
pub(super) fn mk_stmt_err(&self, span: Span, guar: ErrorGuaranteed) -> Stmt
pub(super) fn mk_block_err(&self, span: Span, guar: ErrorGuaranteed) -> P<Block>
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub(super) fn parse_ty_with_generics_recovery( &mut self, ty_params: &Generics, ) -> PResult<'a, P<Ty>>
sourcepub(super) fn parse_ty_for_field_def(&mut self) -> PResult<'a, P<Ty>>
pub(super) fn parse_ty_for_field_def(&mut self) -> PResult<'a, P<Ty>>
Parse a type suitable for a field definition.
The difference from parse_ty
is that this version
allows anonymous structs and unions.
sourcepub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, P<Ty>>
pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, P<Ty>>
Parse a type suitable for a function or function pointer parameter.
The difference from parse_ty
is that this version allows ...
(CVarArgs
) at the top level of the type.
sourcepub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, P<Ty>>
pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, P<Ty>>
Parses a type in restricted contexts where +
is not permitted.
Example 1: &'a TYPE
+
is prohibited to maintain operator priority (P(+) < P(&)).
Example 2: value1 as TYPE + value2
+
is prohibited to avoid interactions with expression grammar.
sourcepub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, P<Ty>>
pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, P<Ty>>
Parses a type following an as
cast. Similar to parse_ty_no_plus
, but signaling origin
for better diagnostics involving ?
.
pub(super) fn parse_ty_no_question_mark_recover(&mut self) -> PResult<'a, P<Ty>>
sourcepub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>>
pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>>
Parse a type without recovering :
as ->
to avoid breaking code such as where fn() : for<'a>
sourcepub(super) fn parse_ret_ty(
&mut self,
allow_plus: AllowPlus,
recover_qpath: RecoverQPath,
recover_return_sign: RecoverReturnSign,
) -> PResult<'a, FnRetTy>
pub(super) fn parse_ret_ty( &mut self, allow_plus: AllowPlus, recover_qpath: RecoverQPath, recover_return_sign: RecoverReturnSign, ) -> PResult<'a, FnRetTy>
Parses an optional return type [ -> TY ]
in a function declaration.
fn parse_ty_common( &mut self, allow_plus: AllowPlus, allow_c_variadic: AllowCVariadic, recover_qpath: RecoverQPath, recover_return_sign: RecoverReturnSign, ty_generics: Option<&Generics>, recover_question_mark: RecoverQuestionMark, ) -> PResult<'a, P<Ty>>
sourcefn parse_anon_struct_or_union(&mut self) -> PResult<'a, P<Ty>>
fn parse_anon_struct_or_union(&mut self) -> PResult<'a, P<Ty>>
Parse an anonymous struct or union (only for field definitions):
#[repr(C)]
struct Foo {
_: struct { // anonymous struct
x: u32,
y: f64,
}
_: union { // anonymous union
z: u32,
w: f64,
}
}
sourcefn parse_ty_tuple_or_parens(
&mut self,
lo: Span,
allow_plus: AllowPlus,
) -> PResult<'a, TyKind>
fn parse_ty_tuple_or_parens( &mut self, lo: Span, allow_plus: AllowPlus, ) -> PResult<'a, TyKind>
Parses either:
(TYPE)
, a parenthesized type.(TYPE,)
, a tuple with a single field of type TYPE.
fn parse_bare_trait_object( &mut self, lo: Span, allow_plus: AllowPlus, ) -> PResult<'a, TyKind>
fn parse_remaining_bounds_path( &mut self, generic_params: ThinVec<GenericParam>, path: Path, lo: Span, parse_plus: bool, ) -> PResult<'a, TyKind>
sourcefn parse_remaining_bounds(
&mut self,
bounds: GenericBounds,
plus: bool,
) -> PResult<'a, TyKind>
fn parse_remaining_bounds( &mut self, bounds: GenericBounds, plus: bool, ) -> PResult<'a, TyKind>
Parse the remainder of a bare trait object type given an already parsed list.
sourcefn parse_ty_ptr(&mut self) -> PResult<'a, TyKind>
fn parse_ty_ptr(&mut self) -> PResult<'a, TyKind>
Parses a raw pointer type: *[const | mut] $type
.
sourcefn parse_array_or_slice_ty(&mut self) -> PResult<'a, TyKind>
fn parse_array_or_slice_ty(&mut self) -> PResult<'a, TyKind>
Parses an array ([TYPE; EXPR]
) or slice ([TYPE]
) type.
The opening [
bracket is already eaten.
fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind>
fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind>
sourcefn parse_ty_bare_fn(
&mut self,
lo: Span,
params: ThinVec<GenericParam>,
param_insertion_point: Option<Span>,
recover_return_sign: RecoverReturnSign,
) -> PResult<'a, TyKind>
fn parse_ty_bare_fn( &mut self, lo: Span, params: ThinVec<GenericParam>, param_insertion_point: Option<Span>, recover_return_sign: RecoverReturnSign, ) -> PResult<'a, TyKind>
Parses a function pointer type (TyKind::BareFn
).
[unsafe] [extern "ABI"] fn (S) -> T
// ^~~~~^ ^~~~^ ^~^ ^
// | | | |
// | | | Return type
// Function Style ABI Parameter types
We actually parse FnHeader FnDecl
, but we error on const
and async
qualifiers.
sourcefn recover_fn_ptr_with_generics(
&mut self,
lo: Span,
params: &mut ThinVec<GenericParam>,
param_insertion_point: Option<Span>,
) -> PResult<'a, ()>
fn recover_fn_ptr_with_generics( &mut self, lo: Span, params: &mut ThinVec<GenericParam>, param_insertion_point: Option<Span>, ) -> PResult<'a, ()>
Recover from function pointer types with a generic parameter list (e.g. fn<'a>(&'a str)
).
sourcefn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind>
fn parse_impl_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind>
Parses an impl B0 + ... + Bn
type.
fn parse_precise_capturing_args( &mut self, ) -> PResult<'a, (ThinVec<PreciseCapturingArg>, Span)>
sourcefn is_explicit_dyn_type(&mut self) -> bool
fn is_explicit_dyn_type(&mut self) -> bool
Is a dyn B0 + ... + Bn
type allowed here?
sourcefn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind>
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind>
Parses a dyn B0 + ... + Bn
type.
Note that this does not parse bare trait objects.
sourcefn parse_path_start_ty(
&mut self,
lo: Span,
allow_plus: AllowPlus,
ty_generics: Option<&Generics>,
) -> PResult<'a, TyKind>
fn parse_path_start_ty( &mut self, lo: Span, allow_plus: AllowPlus, ty_generics: Option<&Generics>, ) -> PResult<'a, TyKind>
Parses a type starting with a path.
This can be:
- a type macro,
mac!(...)
, - a bare trait object,
B0 + ... + Bn
, - or a path,
path::to::MyType
.
pub(super) fn parse_generic_bounds(&mut self) -> PResult<'a, GenericBounds>
sourcefn parse_generic_bounds_common(
&mut self,
allow_plus: AllowPlus,
) -> PResult<'a, GenericBounds>
fn parse_generic_bounds_common( &mut self, allow_plus: AllowPlus, ) -> PResult<'a, GenericBounds>
Parses bounds of a type parameter BOUND + BOUND + ...
, possibly with trailing +
.
See parse_generic_bound
for the BOUND
grammar.
pub(super) fn can_begin_anon_struct_or_union(&mut self) -> bool
sourcefn can_begin_bound(&mut self) -> bool
fn can_begin_bound(&mut self) -> bool
Can the current token begin a bound?
sourcefn parse_generic_bound(&mut self) -> PResult<'a, GenericBound>
fn parse_generic_bound(&mut self) -> PResult<'a, GenericBound>
Parses a bound according to the grammar:
BOUND = TY_BOUND | LT_BOUND
sourcefn parse_generic_lt_bound(
&mut self,
lo: Span,
has_parens: bool,
) -> PResult<'a, GenericBound>
fn parse_generic_lt_bound( &mut self, lo: Span, has_parens: bool, ) -> PResult<'a, GenericBound>
Parses a lifetime (“outlives”) bound, e.g. 'a
, according to:
LT_BOUND = LIFETIME
sourcefn error_lt_bound_with_modifiers(
&self,
modifiers: TraitBoundModifiers,
binder_span: Option<Span>,
) -> ErrorGuaranteed
fn error_lt_bound_with_modifiers( &self, modifiers: TraitBoundModifiers, binder_span: Option<Span>, ) -> ErrorGuaranteed
Emits an error if any trait bound modifiers were present.
sourcefn recover_paren_lifetime(&mut self, lo: Span) -> PResult<'a, ()>
fn recover_paren_lifetime(&mut self, lo: Span) -> PResult<'a, ()>
Recover on ('lifetime)
with (
already eaten.
sourcefn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers>
fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers>
Parses the modifiers that may precede a trait in a bound, e.g. ?Trait
or ~const Trait
.
If no modifiers are present, this does not consume any tokens.
TRAIT_BOUND_MODIFIERS = [["~"] "const"] ["async"] ["?" | "!"]
sourcefn parse_generic_ty_bound(
&mut self,
lo: Span,
has_parens: bool,
leading_token: &Token,
) -> PResult<'a, GenericBound>
fn parse_generic_ty_bound( &mut self, lo: Span, has_parens: bool, leading_token: &Token, ) -> PResult<'a, GenericBound>
Parses a type bound according to:
TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
TY_BOUND_NOPAREN = [TRAIT_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
For example, this grammar accepts for<'a: 'b> ~const ?m::Trait<'a>
.
fn recover_path_from_fn(&mut self) -> Option<Path>
sourcepub(super) fn parse_late_bound_lifetime_defs(
&mut self,
) -> PResult<'a, (ThinVec<GenericParam>, Option<Span>)>
pub(super) fn parse_late_bound_lifetime_defs( &mut self, ) -> PResult<'a, (ThinVec<GenericParam>, Option<Span>)>
Optionally parses for<$generic_params>
.
sourcefn recover_fn_trait_with_lifetime_params(
&mut self,
fn_path: &mut Path,
lifetime_defs: &mut ThinVec<GenericParam>,
) -> PResult<'a, ()>
fn recover_fn_trait_with_lifetime_params( &mut self, fn_path: &mut Path, lifetime_defs: &mut ThinVec<GenericParam>, ) -> PResult<'a, ()>
Recover from Fn
-family traits (Fn, FnMut, FnOnce) with lifetime arguments
(e.g. FnOnce<'a>(&'a str) -> bool
). Up to generic arguments have already
been eaten.
pub(super) fn check_lifetime(&mut self) -> bool
sourcepub(super) fn expect_lifetime(&mut self) -> Lifetime
pub(super) fn expect_lifetime(&mut self) -> Lifetime
Parses a single lifetime 'a
or panics.
pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> P<Ty>
source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub fn new( psess: &'a ParseSess, stream: TokenStream, subparser_name: Option<&'static str>, ) -> Self
pub fn recovery(self, recovery: Recovery) -> Self
sourcefn may_recover(&self) -> bool
fn may_recover(&self) -> bool
Whether the parser is allowed to recover from broken code.
If this returns false, recovering broken code into valid code (especially if this recovery does lookahead) is not allowed. All recovery done by the parser must be gated behind this check.
Technically, this only needs to restrict eager recovery by doing lookahead at more tokens. But making the distinction is very subtle, and simply forbidding all recovery is a lot simpler to uphold.
sourcepub fn unexpected_any<T>(&mut self) -> PResult<'a, T>
pub fn unexpected_any<T>(&mut self) -> PResult<'a, T>
Version of unexpected
that “returns” any type in the Ok
(both those functions never return “Ok”, and so can lie like that in the type).
pub fn unexpected(&mut self) -> PResult<'a, ()>
sourcepub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered>
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered>
Expects and consumes the token t
. Signals an error if the next token is not t
.
sourcefn expect_one_of(
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind],
) -> PResult<'a, Recovered>
fn expect_one_of( &mut self, edible: &[TokenKind], inedible: &[TokenKind], ) -> PResult<'a, Recovered>
Expect next token to be edible or inedible token. If edible, then consume it; if inedible, then return without consuming anything. Signal a fatal error if next token is unexpected.
pub fn parse_ident(&mut self) -> PResult<'a, Ident>
fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident>
fn ident_or_err(&mut self, recover: bool) -> PResult<'a, (Ident, IdentIsRaw)>
sourcefn check(&mut self, tok: &TokenKind) -> bool
fn check(&mut self, tok: &TokenKind) -> bool
Checks if the next token is tok
, and returns true
if so.
This method will automatically add tok
to expected_tokens
if tok
is not
encountered.
fn check_noexpect(&self, tok: &TokenKind) -> bool
sourcefn eat_noexpect(&mut self, tok: &TokenKind) -> bool
fn eat_noexpect(&mut self, tok: &TokenKind) -> bool
Consumes a token ‘tok’ if it exists. Returns whether the given token was present.
the main purpose of this function is to reduce the cluttering of the suggestions list which using the normal eat method could introduce in some cases.
sourcepub fn eat(&mut self, tok: &TokenKind) -> bool
pub fn eat(&mut self, tok: &TokenKind) -> bool
Consumes a token ‘tok’ if it exists. Returns whether the given token was present.
sourcefn check_keyword(&mut self, kw: Symbol) -> bool
fn check_keyword(&mut self, kw: Symbol) -> bool
If the next token is the given keyword, returns true
without eating it.
An expectation is also added for diagnostics purposes.
fn check_keyword_case(&mut self, kw: Symbol, case: Case) -> bool
sourcepub fn eat_keyword(&mut self, kw: Symbol) -> bool
pub fn eat_keyword(&mut self, kw: Symbol) -> bool
If the next token is the given keyword, eats it and returns true
.
Otherwise, returns false
. An expectation is also added for diagnostics purposes.
sourcefn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool
fn eat_keyword_case(&mut self, kw: Symbol, case: Case) -> bool
Eats a keyword, optionally ignoring the case. If the case differs (and is ignored) an error is issued. This is useful for recovery.
fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool
sourcefn expect_keyword(&mut self, kw: Symbol) -> PResult<'a, ()>
fn expect_keyword(&mut self, kw: Symbol) -> PResult<'a, ()>
If the given word is not a keyword, signals an error. If the next token is not the given word, signals an error. Otherwise, eats it.
sourcefn is_kw_followed_by_ident(&self, kw: Symbol) -> bool
fn is_kw_followed_by_ident(&self, kw: Symbol) -> bool
Is the given keyword kw
followed by a non-reserved identifier?
fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool
fn check_ident(&mut self) -> bool
fn check_path(&mut self) -> bool
fn check_type(&mut self) -> bool
fn check_const_arg(&mut self) -> bool
fn check_const_closure(&self) -> bool
fn check_inline_const(&self, dist: usize) -> bool
sourcefn check_plus(&mut self) -> bool
fn check_plus(&mut self) -> bool
Checks to see if the next token is either +
or +=
.
Otherwise returns false
.
sourcefn break_and_eat(&mut self, expected: TokenKind) -> bool
fn break_and_eat(&mut self, expected: TokenKind) -> bool
Eats the expected token if it’s present possibly breaking
compound tokens like multi-character operators in process.
Returns true
if the token was eaten.
sourcefn expect_and(&mut self) -> PResult<'a, ()>
fn expect_and(&mut self) -> PResult<'a, ()>
Eats &
possibly breaking tokens like &&
in process.
Signals an error if &
is not eaten.
sourcefn expect_or(&mut self) -> PResult<'a, ()>
fn expect_or(&mut self) -> PResult<'a, ()>
Eats |
possibly breaking tokens like ||
in process.
Signals an error if |
was not eaten.
sourcefn expect_lt(&mut self) -> PResult<'a, ()>
fn expect_lt(&mut self) -> PResult<'a, ()>
Eats <
possibly breaking tokens like <<
in process.
Signals an error if <
was not eaten.
sourcefn expect_gt(&mut self) -> PResult<'a, ()>
fn expect_gt(&mut self) -> PResult<'a, ()>
Eats >
possibly breaking tokens like >>
in process.
Signals an error if >
was not eaten.
sourcefn expect_any_with_type(
&mut self,
kets_expected: &[&TokenKind],
kets_not_expected: &[&TokenKind],
) -> bool
fn expect_any_with_type( &mut self, kets_expected: &[&TokenKind], kets_not_expected: &[&TokenKind], ) -> bool
Checks if the next token is contained within kets
, and returns true
if so.
sourcefn parse_seq_to_before_tokens<T>(
&mut self,
kets_expected: &[&TokenKind],
kets_not_expected: &[&TokenKind],
sep: SeqSep,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)>
fn parse_seq_to_before_tokens<T>( &mut self, kets_expected: &[&TokenKind], kets_not_expected: &[&TokenKind], sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)>
Parses a sequence until the specified delimiters. The function
f
must consume tokens until reaching the next separator or
closing bracket.
fn recover_missing_braces_around_closure_body( &mut self, closure_spans: ClosureSpans, expect_err: Diag<'_>, ) -> PResult<'a, ()>
sourcefn parse_seq_to_before_end<T>(
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)>
fn parse_seq_to_before_end<T>( &mut self, ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing, Recovered)>
Parses a sequence, not including the delimiters. The function
f
must consume tokens until reaching the next separator or
closing bracket.
sourcefn parse_seq_to_end<T>(
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing)>
fn parse_seq_to_end<T>( &mut self, ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing)>
Parses a sequence, including only the closing delimiter. The function
f
must consume tokens until reaching the next separator or
closing bracket.
sourcefn parse_unspanned_seq<T>(
&mut self,
bra: &TokenKind,
ket: &TokenKind,
sep: SeqSep,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing)>
fn parse_unspanned_seq<T>( &mut self, bra: &TokenKind, ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing)>
Parses a sequence, including both delimiters. The function
f
must consume tokens until reaching the next separator or
closing bracket.
sourcefn parse_delim_comma_seq<T>(
&mut self,
delim: Delimiter,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing)>
fn parse_delim_comma_seq<T>( &mut self, delim: Delimiter, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing)>
Parses a comma-separated sequence, including both delimiters.
The function f
must consume tokens until reaching the next separator or
closing bracket.
sourcefn parse_paren_comma_seq<T>(
&mut self,
f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>,
) -> PResult<'a, (ThinVec<T>, Trailing)>
fn parse_paren_comma_seq<T>( &mut self, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, ) -> PResult<'a, (ThinVec<T>, Trailing)>
Parses a comma-separated sequence delimited by parentheses (e.g. (x, y)
).
The function f
must consume tokens until reaching the next separator or
closing bracket.
sourcefn bump_with(&mut self, next: (Token, Spacing))
fn bump_with(&mut self, next: (Token, Spacing))
Advance the parser by one token using provided token as the next one.
sourcefn inlined_bump_with(&mut self, (next_token, next_spacing): (Token, Spacing))
fn inlined_bump_with(&mut self, (next_token, next_spacing): (Token, Spacing))
This always-inlined version should only be used on hot code paths.
sourcepub fn look_ahead<R>(&self, dist: usize, looker: impl FnOnce(&Token) -> R) -> R
pub fn look_ahead<R>(&self, dist: usize, looker: impl FnOnce(&Token) -> R) -> R
Look-ahead dist
tokens of self.token
and get access to that token there.
When dist == 0
then the current token is looked at. Eof
will be
returned if the look-ahead is any distance past the end of the tokens.
sourcepub(crate) fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool
pub(crate) fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool
Returns whether any of the given keywords are dist
tokens ahead of the current one.
sourcefn parse_coroutine_kind(&mut self, case: Case) -> Option<CoroutineKind>
fn parse_coroutine_kind(&mut self, case: Case) -> Option<CoroutineKind>
Parses asyncness: async
or nothing.
sourcefn parse_safety(&mut self, case: Case) -> Safety
fn parse_safety(&mut self, case: Case) -> Safety
Parses fn unsafety: unsafe
, safe
or nothing.
sourcefn parse_constness(&mut self, case: Case) -> Const
fn parse_constness(&mut self, case: Case) -> Const
Parses constness: const
or nothing.
sourcefn parse_closure_constness(&mut self) -> Const
fn parse_closure_constness(&mut self) -> Const
Parses constness for closures (case sensitive, feature-gated)
fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const
sourcefn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>>
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>>
Parses inline const expressions.
sourcefn parse_mutability(&mut self) -> Mutability
fn parse_mutability(&mut self) -> Mutability
Parses mutability (mut
or nothing).
sourcefn parse_byref(&mut self) -> ByRef
fn parse_byref(&mut self) -> ByRef
Parses reference binding mode (ref
, ref mut
, or nothing).
sourcefn parse_const_or_mut(&mut self) -> Option<Mutability>
fn parse_const_or_mut(&mut self) -> Option<Mutability>
Possibly parses mutability (const
or mut
).
fn parse_field_name(&mut self) -> PResult<'a, Ident>
fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>>
fn parse_attr_args(&mut self) -> PResult<'a, AttrArgs>
fn parse_delim_args_inner(&mut self) -> Option<DelimArgs>
sourcepub fn parse_token_tree(&mut self) -> TokenTree
pub fn parse_token_tree(&mut self) -> TokenTree
Parses a single token tree from the input.
pub fn parse_tokens(&mut self) -> TokenStream
sourcefn with_res<T>(
&mut self,
res: Restrictions,
f: impl FnOnce(&mut Self) -> T,
) -> T
fn with_res<T>( &mut self, res: Restrictions, f: impl FnOnce(&mut Self) -> T, ) -> T
Evaluates the closure with restrictions in place.
Afters the closure is evaluated, restrictions are reset.
sourcepub fn parse_visibility(
&mut self,
fbt: FollowedByType,
) -> PResult<'a, Visibility>
pub fn parse_visibility( &mut self, fbt: FollowedByType, ) -> PResult<'a, Visibility>
Parses pub
and pub(in path)
plus shortcuts pub(crate)
for pub(in crate)
, pub(self)
for pub(in self)
and pub(super)
for pub(in super)
.
If the following element can’t be a tuple (i.e., it’s a function definition), then
it’s not a tuple struct field), and the contents within the parentheses aren’t valid,
so emit a proper diagnostic.
sourcefn recover_incorrect_vis_restriction(&mut self) -> PResult<'a, ()>
fn recover_incorrect_vis_restriction(&mut self) -> PResult<'a, ()>
Recovery for e.g. pub(something) fn ...
or struct X { pub(something) y: Z }
sourcefn parse_extern(&mut self, case: Case) -> Extern
fn parse_extern(&mut self, case: Case) -> Extern
Parses extern string_literal?
.
fn collect_tokens_no_attrs<R: HasAttrs + HasTokens>( &mut self, f: impl FnOnce(&mut Self) -> PResult<'a, R>, ) -> PResult<'a, R>
sourcefn is_import_coupler(&mut self) -> bool
fn is_import_coupler(&mut self) -> bool
::{
or ::*
pub(crate) fn debug_lookahead(&self, lookahead: usize) -> impl Debug + '_
pub fn clear_expected_tokens(&mut self)
pub fn approx_token_stream_pos(&self) -> u32
Trait Implementations§
Auto Trait Implementations§
impl<'a> DynSend for Parser<'a>
impl<'a> DynSync for Parser<'a>
impl<'a> Freeze for Parser<'a>
impl<'a> !RefUnwindSafe for Parser<'a>
impl<'a> !Send for Parser<'a>
impl<'a> !Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> !UnwindSafe for Parser<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<T> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
impl<T> ErasedDestructor for Twhere
T: 'static,
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: 256 bytes