diff options
| author | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
| commit | 56ac6bfc87cce22feffc079c0540c8774b00a5ca (patch) | |
| tree | e430c91fb4e29070945f79df7a47639e5cf4f9b1 /compiler/rustc_parse/src/parser | |
| parent | ffd12f67cfa28891bbd1fa81d5e80a128f346ace (diff) | |
| parent | cb45103358c0fef99d7659e0949b3c65b3eabdd6 (diff) | |
| download | rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.tar.gz rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.zip | |
Auto merge of #2803 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 257 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 28 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 30 |
10 files changed, 230 insertions, 214 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 686454a8f18..e3e7c63e344 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -1,11 +1,15 @@ use crate::errors::{InvalidMetaItem, SuffixedLiteralInAttribute}; +use crate::fluent_generated as fluent; use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle}; use rustc_ast as ast; use rustc_ast::attr; use rustc_ast::token::{self, Delimiter, Nonterminal}; -use rustc_errors::{error_code, fluent, Diagnostic, IntoDiagnostic, PResult}; +use rustc_errors::{error_code, Diagnostic, IntoDiagnostic, PResult}; use rustc_span::{sym, BytePos, Span}; +use std::convert::TryInto; +use thin_vec::ThinVec; +use tracing::debug; // Public for rustfmt usage #[derive(Debug)] @@ -65,10 +69,10 @@ impl<'a> Parser<'a> { token::CommentKind::Block => OuterAttributeType::DocBlockComment, }, ) { - err.note(fluent::note); + err.note(fluent::parse_note); err.span_suggestion_verbose( replacement_span, - fluent::suggestion, + fluent::parse_suggestion, "", rustc_errors::Applicability::MachineApplicable, ); @@ -172,10 +176,10 @@ impl<'a> Parser<'a> { Ok(Some(item)) => { // FIXME(#100717) err.set_arg("item", item.kind.descr()); - err.span_label(item.span, fluent::label_does_not_annotate_this); + err.span_label(item.span, fluent::parse_label_does_not_annotate_this); err.span_suggestion_verbose( replacement_span, - fluent::sugg_change_inner_to_outer, + fluent::parse_sugg_change_inner_to_outer, match attr_type { OuterAttributeType::Attribute => "", OuterAttributeType::DocBlockComment => "*", @@ -201,8 +205,8 @@ impl<'a> Parser<'a> { attr_sp, fluent::parse_inner_attr_not_permitted_after_outer_doc_comment, ); - diag.span_label(attr_sp, fluent::label_attr) - .span_label(prev_doc_comment_span, fluent::label_prev_doc_comment); + diag.span_label(attr_sp, fluent::parse_label_attr) + .span_label(prev_doc_comment_span, fluent::parse_label_prev_doc_comment); diag } Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => { @@ -210,8 +214,8 @@ impl<'a> Parser<'a> { attr_sp, fluent::parse_inner_attr_not_permitted_after_outer_attr, ); - diag.span_label(attr_sp, fluent::label_attr) - .span_label(prev_outer_attr_sp, fluent::label_prev_attr); + diag.span_label(attr_sp, fluent::parse_label_attr) + .span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr); diag } Some(InnerAttrForbiddenReason::InCodeBlock) | None => { @@ -346,9 +350,9 @@ impl<'a> Parser<'a> { } /// Matches `COMMASEP(meta_item_inner)`. - pub(crate) fn parse_meta_seq_top(&mut self) -> PResult<'a, Vec<ast::NestedMetaItem>> { + pub(crate) fn parse_meta_seq_top(&mut self) -> PResult<'a, ThinVec<ast::NestedMetaItem>> { // Presumably, the majority of the time there will only be one attr. - let mut nmis = Vec::with_capacity(1); + let mut nmis = ThinVec::with_capacity(1); while self.token.kind != token::Eof { nmis.push(self.parse_meta_item_inner()?); if !self.eat(&token::Comma) { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 49eff41329c..b4948dddcc9 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -18,6 +18,7 @@ use crate::errors::{ UseEqInstead, }; +use crate::fluent_generated as fluent; use crate::lexer::UnmatchedBrace; use crate::parser; use rustc_ast as ast; @@ -32,10 +33,9 @@ use rustc_ast::{ use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{ - fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, FatalError, Handler, MultiSpan, - PResult, + pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, + FatalError, Handler, IntoDiagnostic, MultiSpan, PResult, }; -use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic}; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; @@ -693,7 +693,7 @@ impl<'a> Parser<'a> { span: self.prev_token.span.shrink_to_lo(), tokens: None, }; - let struct_expr = snapshot.parse_struct_expr(None, path, false); + let struct_expr = snapshot.parse_expr_struct(None, path, false); let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No); return Some(match (struct_expr, block_tail) { (Ok(expr), Err(mut err)) => { @@ -708,7 +708,7 @@ impl<'a> Parser<'a> { err.delay_as_bug(); self.restore_snapshot(snapshot); let mut tail = self.mk_block( - vec![self.mk_stmt_err(expr.span)], + thin_vec![self.mk_stmt_err(expr.span)], s, lo.to(self.prev_token.span), ); @@ -1624,7 +1624,7 @@ impl<'a> Parser<'a> { // Handle `await { <expr> }`. // This needs to be handled separately from the next arm to avoid // interpreting `await { <expr> }?` as `<expr>?.await`. - self.parse_block_expr(None, self.token.span, BlockCheckMode::Default) + self.parse_expr_block(None, self.token.span, BlockCheckMode::Default) } else { self.parse_expr() } @@ -2175,7 +2175,7 @@ impl<'a> Parser<'a> { /// 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. - pub(super) fn deduplicate_recovered_params_names(&self, fn_inputs: &mut Vec<Param>) { + pub(super) fn deduplicate_recovered_params_names(&self, fn_inputs: &mut ThinVec<Param>) { let mut seen_inputs = FxHashSet::default(); for input in fn_inputs.iter_mut() { let opt_ident = if let (PatKind::Ident(_, ident, _), TyKind::Err) = @@ -2199,7 +2199,7 @@ impl<'a> Parser<'a> { /// like the user has forgotten them. pub fn handle_ambiguous_unbraced_const_arg( &mut self, - args: &mut Vec<AngleBracketedArg>, + args: &mut ThinVec<AngleBracketedArg>, ) -> PResult<'a, bool> { // If we haven't encountered a closing `>`, then the argument is malformed. // It's likely that the user has written a const expression without enclosing it diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2fc8ce98af0..33254d034c9 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -31,6 +31,7 @@ use rustc_session::lint::BuiltinLintDiagnostics; use rustc_span::source_map::{self, Span, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Pos}; +use thin_vec::{thin_vec, ThinVec}; /// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression /// dropped into the token stream, which happens while parsing the result of @@ -102,7 +103,7 @@ impl<'a> Parser<'a> { self.collect_tokens_no_attrs(|this| this.parse_expr()) } - pub fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> { + pub fn parse_expr_anon_const(&mut self) -> PResult<'a, AnonConst> { self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value }) } @@ -124,7 +125,7 @@ impl<'a> Parser<'a> { } /// Parses a sequence of expressions delimited by parentheses. - fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> { + fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<P<Expr>>> { self.parse_paren_comma_seq(|p| p.parse_expr_catch_underscore()).map(|(r, _)| r) } @@ -135,7 +136,7 @@ impl<'a> Parser<'a> { r: Restrictions, already_parsed_attrs: Option<AttrWrapper>, ) -> PResult<'a, P<Expr>> { - self.with_res(r, |this| this.parse_assoc_expr(already_parsed_attrs)) + self.with_res(r, |this| this.parse_expr_assoc(already_parsed_attrs)) } /// Parses an associative expression. @@ -143,15 +144,15 @@ impl<'a> Parser<'a> { /// This parses an expression accounting for associativity and precedence of the operators in /// the expression. #[inline] - fn parse_assoc_expr( + fn parse_expr_assoc( &mut self, already_parsed_attrs: Option<AttrWrapper>, ) -> PResult<'a, P<Expr>> { - self.parse_assoc_expr_with(0, already_parsed_attrs.into()) + self.parse_expr_assoc_with(0, already_parsed_attrs.into()) } /// Parses an associative expression with operators of at least `min_prec` precedence. - pub(super) fn parse_assoc_expr_with( + pub(super) fn parse_expr_assoc_with( &mut self, min_prec: usize, lhs: LhsExpr, @@ -166,9 +167,9 @@ impl<'a> Parser<'a> { _ => None, }; if self.token.is_range_separator() { - return self.parse_prefix_range_expr(attrs); + return self.parse_expr_prefix_range(attrs); } else { - self.parse_prefix_expr(attrs)? + self.parse_expr_prefix(attrs)? } }; let last_type_ascription_set = self.last_type_ascription.is_some(); @@ -292,7 +293,7 @@ impl<'a> Parser<'a> { } else if op == AssocOp::DotDot || op == AssocOp::DotDotEq { // If we didn't have to handle `x..`/`x..=`, it would be pretty easy to // generalise it to the Fixity::None code. - lhs = self.parse_range_expr(prec, lhs, op, cur_op_span)?; + lhs = self.parse_expr_range(prec, lhs, op, cur_op_span)?; break; } @@ -305,7 +306,7 @@ impl<'a> Parser<'a> { Fixity::None => 1, }; let rhs = self.with_res(restrictions - Restrictions::STMT_EXPR, |this| { - this.parse_assoc_expr_with(prec + prec_adjustment, LhsExpr::NotYetParsed) + this.parse_expr_assoc_with(prec + prec_adjustment, LhsExpr::NotYetParsed) })?; let span = self.mk_expr_sp(&lhs, lhs_span, rhs.span); @@ -457,7 +458,7 @@ impl<'a> Parser<'a> { /// Parses `x..y`, `x..=y`, and `x..`/`x..=`. /// The other two variants are handled in `parse_prefix_range_expr` below. - fn parse_range_expr( + fn parse_expr_range( &mut self, prec: usize, lhs: P<Expr>, @@ -465,7 +466,7 @@ impl<'a> Parser<'a> { cur_op_span: Span, ) -> PResult<'a, P<Expr>> { let rhs = if self.is_at_start_of_range_notation_rhs() { - Some(self.parse_assoc_expr_with(prec + 1, LhsExpr::NotYetParsed)?) + Some(self.parse_expr_assoc_with(prec + 1, LhsExpr::NotYetParsed)?) } else { None }; @@ -490,7 +491,7 @@ impl<'a> Parser<'a> { } /// Parses prefix-forms of range notation: `..expr`, `..`, `..=expr`. - fn parse_prefix_range_expr(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { + fn parse_expr_prefix_range(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { // Check for deprecated `...` syntax. if self.token == token::DotDotDot { self.err_dotdotdot_syntax(self.token.span); @@ -517,7 +518,7 @@ impl<'a> Parser<'a> { this.bump(); let (span, opt_end) = if this.is_at_start_of_range_notation_rhs() { // RHS must be parsed with more associativity than the dots. - this.parse_assoc_expr_with(op.unwrap().precedence() + 1, LhsExpr::NotYetParsed) + this.parse_expr_assoc_with(op.unwrap().precedence() + 1, LhsExpr::NotYetParsed) .map(|x| (lo.to(x.span), Some(x)))? } else { (lo, None) @@ -528,7 +529,7 @@ impl<'a> Parser<'a> { } /// Parses a prefix-unary-operator expr. - fn parse_prefix_expr(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { + fn parse_expr_prefix(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { let attrs = self.parse_or_use_outer_attributes(attrs)?; let lo = self.token.span; @@ -546,20 +547,20 @@ impl<'a> Parser<'a> { // Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr() match this.token.uninterpolate().kind { // `!expr` - token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), + token::Not => make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Not)), // `~expr` token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), // `-expr` token::BinOp(token::Minus) => { - make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) + make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Neg)) } // `*expr` token::BinOp(token::Star) => { - make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref)) + make_it!(this, attrs, |this, _| this.parse_expr_unary(lo, UnOp::Deref)) } // `&expr` and `&&expr` token::BinOp(token::And) | token::AndAnd => { - make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo)) + make_it!(this, attrs, |this, _| this.parse_expr_borrow(lo)) } // `+lit` token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => { @@ -578,7 +579,7 @@ impl<'a> Parser<'a> { this.sess.emit_err(err); this.bump(); - this.parse_prefix_expr(None) + this.parse_expr_prefix(None) } // Recover from `++x`: token::BinOp(token::Plus) @@ -591,28 +592,28 @@ impl<'a> Parser<'a> { this.bump(); this.bump(); - let operand_expr = this.parse_dot_or_call_expr(Default::default())?; + let operand_expr = this.parse_expr_dot_or_call(Default::default())?; this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt) } token::Ident(..) if this.token.is_keyword(kw::Box) => { - make_it!(this, attrs, |this, _| this.parse_box_expr(lo)) + make_it!(this, attrs, |this, _| this.parse_expr_box(lo)) } token::Ident(..) if this.may_recover() && this.is_mistaken_not_ident_negation() => { make_it!(this, attrs, |this, _| this.recover_not_expr(lo)) } - _ => return this.parse_dot_or_call_expr(Some(attrs)), + _ => return this.parse_expr_dot_or_call(Some(attrs)), } } - fn parse_prefix_expr_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)> { + fn parse_expr_prefix_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)> { self.bump(); - let expr = self.parse_prefix_expr(None); + let expr = self.parse_expr_prefix(None); let (span, expr) = self.interpolated_or_expr_span(expr)?; Ok((lo.to(span), expr)) } - fn parse_unary_expr(&mut self, lo: Span, op: UnOp) -> PResult<'a, (Span, ExprKind)> { - let (span, expr) = self.parse_prefix_expr_common(lo)?; + fn parse_expr_unary(&mut self, lo: Span, op: UnOp) -> PResult<'a, (Span, ExprKind)> { + let (span, expr) = self.parse_expr_prefix_common(lo)?; Ok((span, self.mk_unary(op, expr))) } @@ -620,12 +621,12 @@ impl<'a> Parser<'a> { fn recover_tilde_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { self.sess.emit_err(errors::TildeAsUnaryOperator(lo)); - self.parse_unary_expr(lo, UnOp::Not) + self.parse_expr_unary(lo, UnOp::Not) } /// Parse `box expr`. - fn parse_box_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { - let (span, expr) = self.parse_prefix_expr_common(lo)?; + fn parse_expr_box(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { + let (span, expr) = self.parse_expr_prefix_common(lo)?; self.sess.gated_spans.gate(sym::box_syntax, span); Ok((span, ExprKind::Box(expr))) } @@ -663,7 +664,7 @@ impl<'a> Parser<'a> { ), }); - self.parse_unary_expr(lo, UnOp::Not) + self.parse_expr_unary(lo, UnOp::Not) } /// Returns the span of expr, if it was not interpolated or the span of the interpolated token. @@ -721,7 +722,7 @@ impl<'a> Parser<'a> { segments[0].ident.span, ), }; - match self.parse_labeled_expr(label, false) { + match self.parse_expr_labeled(label, false) { Ok(expr) => { type_err.cancel(); self.sess.emit_err(errors::MalformedLoopLabel { @@ -815,7 +816,7 @@ impl<'a> Parser<'a> { ("cast", None) }; - let with_postfix = self.parse_dot_or_call_expr_with_(cast_expr, span)?; + let with_postfix = self.parse_expr_dot_or_call_with_(cast_expr, span)?; // Check if an illegal postfix operator has been added after the cast. // If the resulting expression is not a cast, it is an illegal postfix operator. @@ -886,15 +887,15 @@ impl<'a> Parser<'a> { } /// Parse `& mut? <expr>` or `& raw [ const | mut ] <expr>`. - fn parse_borrow_expr(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { + fn parse_expr_borrow(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { self.expect_and()?; let has_lifetime = self.token.is_lifetime() && self.look_ahead(1, |t| t != &token::Colon); let lifetime = has_lifetime.then(|| self.expect_lifetime()); // For recovery, see below. let (borrow_kind, mutbl) = self.parse_borrow_modifiers(lo); let expr = if self.token.is_range_separator() { - self.parse_prefix_range_expr(None) + self.parse_expr_prefix_range(None) } else { - self.parse_prefix_expr(None) + self.parse_expr_prefix(None) }; let (hi, expr) = self.interpolated_or_expr_span(expr)?; let span = lo.to(hi); @@ -924,16 +925,16 @@ impl<'a> Parser<'a> { } /// Parses `a.b` or `a(13)` or `a[4]` or just `a`. - fn parse_dot_or_call_expr(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { + fn parse_expr_dot_or_call(&mut self, attrs: Option<AttrWrapper>) -> PResult<'a, P<Expr>> { let attrs = self.parse_or_use_outer_attributes(attrs)?; self.collect_tokens_for_expr(attrs, |this, attrs| { - let base = this.parse_bottom_expr(); + let base = this.parse_expr_bottom(); let (span, base) = this.interpolated_or_expr_span(base)?; - this.parse_dot_or_call_expr_with(base, span, attrs) + this.parse_expr_dot_or_call_with(base, span, attrs) }) } - pub(super) fn parse_dot_or_call_expr_with( + pub(super) fn parse_expr_dot_or_call_with( &mut self, e0: P<Expr>, lo: Span, @@ -942,7 +943,7 @@ impl<'a> Parser<'a> { // Stitch the list of outer attributes onto the return value. // A little bit ugly, but the best way given the current code // structure - let res = self.parse_dot_or_call_expr_with_(e0, lo); + let res = self.parse_expr_dot_or_call_with_(e0, lo); if attrs.is_empty() { res } else { @@ -956,7 +957,7 @@ impl<'a> Parser<'a> { } } - fn parse_dot_or_call_expr_with_(&mut self, mut e: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_dot_or_call_with_(&mut self, mut e: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> { loop { let has_question = if self.prev_token.kind == TokenKind::Ident(kw::Return, false) { // we are using noexpect here because we don't expect a `?` directly after a `return` @@ -979,15 +980,15 @@ impl<'a> Parser<'a> { }; if has_dot { // expr.f - e = self.parse_dot_suffix_expr(lo, e)?; + e = self.parse_expr_dot_suffix(lo, e)?; continue; } if self.expr_is_complete(&e) { return Ok(e); } e = match self.token.kind { - token::OpenDelim(Delimiter::Parenthesis) => self.parse_fn_call_expr(lo, e), - token::OpenDelim(Delimiter::Bracket) => self.parse_index_expr(lo, e)?, + token::OpenDelim(Delimiter::Parenthesis) => self.parse_expr_fn_call(lo, e), + token::OpenDelim(Delimiter::Bracket) => self.parse_expr_index(lo, e)?, _ => return Ok(e), } } @@ -999,14 +1000,14 @@ impl<'a> Parser<'a> { && self.look_ahead(3, |t| t.can_begin_expr()) } - fn parse_dot_suffix_expr(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> { + fn parse_expr_dot_suffix(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> { match self.token.uninterpolate().kind { token::Ident(..) => self.parse_dot_suffix(base, lo), token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => { - Ok(self.parse_tuple_field_access_expr(lo, base, symbol, suffix, None)) + Ok(self.parse_expr_tuple_field_access(lo, base, symbol, suffix, None)) } token::Literal(token::Lit { kind: token::Float, symbol, suffix }) => { - Ok(self.parse_tuple_field_access_expr_float(lo, base, symbol, suffix)) + Ok(self.parse_expr_tuple_field_access_float(lo, base, symbol, suffix)) } _ => { self.error_unexpected_after_dot(); @@ -1028,7 +1029,7 @@ impl<'a> Parser<'a> { // support pushing "future tokens" (would be also helpful to `break_and_eat`), or // we should break everything including floats into more basic proc-macro style // tokens in the lexer (probably preferable). - fn parse_tuple_field_access_expr_float( + fn parse_expr_tuple_field_access_float( &mut self, lo: Span, base: P<Expr>, @@ -1071,7 +1072,7 @@ impl<'a> Parser<'a> { match &*components { // 1e2 [IdentLike(i)] => { - self.parse_tuple_field_access_expr(lo, base, Symbol::intern(&i), suffix, None) + self.parse_expr_tuple_field_access(lo, base, Symbol::intern(&i), suffix, None) } // 1. [IdentLike(i), Punct('.')] => { @@ -1087,7 +1088,7 @@ impl<'a> Parser<'a> { let symbol = Symbol::intern(&i); self.token = Token::new(token::Ident(symbol, false), ident_span); let next_token = (Token::new(token::Dot, dot_span), self.token_spacing); - self.parse_tuple_field_access_expr(lo, base, symbol, None, Some(next_token)) + self.parse_expr_tuple_field_access(lo, base, symbol, None, Some(next_token)) } // 1.2 | 1.2e3 [IdentLike(i1), Punct('.'), IdentLike(i2)] => { @@ -1108,11 +1109,11 @@ impl<'a> Parser<'a> { // See issue #76399 and PR #76285 for more details let next_token1 = (Token::new(token::Dot, dot_span), Spacing::Alone); let base1 = - self.parse_tuple_field_access_expr(lo, base, symbol1, None, Some(next_token1)); + self.parse_expr_tuple_field_access(lo, base, symbol1, None, Some(next_token1)); let symbol2 = Symbol::intern(&i2); let next_token2 = Token::new(token::Ident(symbol2, false), ident2_span); self.bump_with((next_token2, self.token_spacing)); // `.` - self.parse_tuple_field_access_expr(lo, base1, symbol2, suffix, None) + self.parse_expr_tuple_field_access(lo, base1, symbol2, suffix, None) } // 1e+ | 1e- (recovered) [IdentLike(_), Punct('+' | '-')] | @@ -1130,7 +1131,7 @@ impl<'a> Parser<'a> { } } - fn parse_tuple_field_access_expr( + fn parse_expr_tuple_field_access( &mut self, lo: Span, base: P<Expr>, @@ -1151,7 +1152,7 @@ impl<'a> Parser<'a> { } /// Parse a function call expression, `expr(...)`. - fn parse_fn_call_expr(&mut self, lo: Span, fun: P<Expr>) -> P<Expr> { + fn parse_expr_fn_call(&mut self, lo: Span, fun: P<Expr>) -> P<Expr> { let snapshot = if self.token.kind == token::OpenDelim(Delimiter::Parenthesis) && self.look_ahead_type_ascription_as_field() { @@ -1162,7 +1163,7 @@ impl<'a> Parser<'a> { let open_paren = self.token.span; let mut seq = self - .parse_paren_expr_seq() + .parse_expr_paren_seq() .map(|args| self.mk_expr(lo.to(self.prev_token.span), self.mk_call(fun, args))); if let Some(expr) = self.maybe_recover_struct_lit_bad_delims(lo, open_paren, &mut seq, snapshot) @@ -1235,7 +1236,7 @@ impl<'a> Parser<'a> { } /// Parse an indexing expression `expr[...]`. - fn parse_index_expr(&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>> { let prev_span = self.prev_token.span; let open_delim_span = self.token.span; self.bump(); // `[` @@ -1258,7 +1259,7 @@ impl<'a> Parser<'a> { if self.check(&token::OpenDelim(Delimiter::Parenthesis)) { // Method call `expr.f()` - let args = self.parse_paren_expr_seq()?; + let args = self.parse_expr_paren_seq()?; let fn_span = fn_span_lo.to(self.prev_token.span); let span = lo.to(self.prev_token.span); Ok(self.mk_expr( @@ -1286,7 +1287,7 @@ impl<'a> Parser<'a> { /// /// N.B., this does not parse outer attributes, and is private because it only works /// correctly if called from `parse_dot_or_call_expr()`. - fn parse_bottom_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> { maybe_recover_from_interpolated_ty_qpath!(self, true); maybe_whole_expr!(self); @@ -1299,13 +1300,13 @@ impl<'a> Parser<'a> { // This match arm is a special-case of the `_` match arm below and // could be removed without changing functionality, but it's faster // to have it here, especially for programs with large constants. - self.parse_lit_expr() + self.parse_expr_lit() } else if self.check(&token::OpenDelim(Delimiter::Parenthesis)) { - self.parse_tuple_parens_expr() + self.parse_expr_tuple_parens() } else if self.check(&token::OpenDelim(Delimiter::Brace)) { - self.parse_block_expr(None, lo, BlockCheckMode::Default) + self.parse_expr_block(None, lo, BlockCheckMode::Default) } else if self.check(&token::BinOp(token::Or)) || self.check(&token::OrOr) { - self.parse_closure_expr().map_err(|mut err| { + self.parse_expr_closure().map_err(|mut err| { // If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }` // then suggest parens around the lhs. if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) { @@ -1314,42 +1315,42 @@ impl<'a> Parser<'a> { err }) } else if self.check(&token::OpenDelim(Delimiter::Bracket)) { - self.parse_array_or_repeat_expr(Delimiter::Bracket) + self.parse_expr_array_or_repeat(Delimiter::Bracket) } else if self.check_path() { - self.parse_path_start_expr() + self.parse_expr_path_start() } else if self.check_keyword(kw::Move) || self.check_keyword(kw::Static) || self.check_const_closure() { - self.parse_closure_expr() + self.parse_expr_closure() } else if self.eat_keyword(kw::If) { - self.parse_if_expr() + self.parse_expr_if() } else if self.check_keyword(kw::For) { if self.choose_generics_over_qpath(1) { - self.parse_closure_expr() + self.parse_expr_closure() } else { assert!(self.eat_keyword(kw::For)); - self.parse_for_expr(None, self.prev_token.span) + self.parse_expr_for(None, self.prev_token.span) } } else if self.eat_keyword(kw::While) { - self.parse_while_expr(None, self.prev_token.span) + self.parse_expr_while(None, self.prev_token.span) } else if let Some(label) = self.eat_label() { - self.parse_labeled_expr(label, true) + self.parse_expr_labeled(label, true) } else if self.eat_keyword(kw::Loop) { let sp = self.prev_token.span; - self.parse_loop_expr(None, self.prev_token.span).map_err(|mut err| { + self.parse_expr_loop(None, self.prev_token.span).map_err(|mut err| { err.span_label(sp, "while parsing this `loop` expression"); err }) } else if self.eat_keyword(kw::Match) { let match_sp = self.prev_token.span; - self.parse_match_expr().map_err(|mut err| { + self.parse_expr_match().map_err(|mut err| { err.span_label(match_sp, "while parsing this `match` expression"); err }) } else if self.eat_keyword(kw::Unsafe) { let sp = self.prev_token.span; - self.parse_block_expr(None, lo, BlockCheckMode::Unsafe(ast::UserProvided)).map_err( + self.parse_expr_block(None, lo, BlockCheckMode::Unsafe(ast::UserProvided)).map_err( |mut err| { err.span_label(sp, "while parsing this `unsafe` expression"); err @@ -1363,17 +1364,17 @@ impl<'a> Parser<'a> { self.expect_keyword(kw::Try)?; self.parse_try_block(lo) } else if self.eat_keyword(kw::Return) { - self.parse_return_expr() + self.parse_expr_return() } else if self.eat_keyword(kw::Continue) { - self.parse_continue_expr(lo) + self.parse_expr_continue(lo) } else if self.eat_keyword(kw::Break) { - self.parse_break_expr() + self.parse_expr_break() } else if self.eat_keyword(kw::Yield) { - self.parse_yield_expr() + self.parse_expr_yield() } else if self.is_do_yeet() { - self.parse_yeet_expr() + self.parse_expr_yeet() } else if self.check_keyword(kw::Let) { - self.parse_let_expr() + self.parse_expr_let() } else if self.eat_keyword(kw::Underscore) { Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore)) } else if !self.unclosed_delims.is_empty() && self.check(&token::Semi) { @@ -1396,19 +1397,19 @@ impl<'a> Parser<'a> { // Check for `async {` and `async move {`. self.parse_async_block() } else { - self.parse_closure_expr() + self.parse_expr_closure() } } else if self.eat_keyword(kw::Await) { self.recover_incorrect_await_syntax(lo, self.prev_token.span) } else { - self.parse_lit_expr() + self.parse_expr_lit() } } else { - self.parse_lit_expr() + self.parse_expr_lit() } } - fn parse_lit_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_lit(&mut self) -> PResult<'a, P<Expr>> { let lo = self.token.span; match self.parse_opt_token_lit() { Some((token_lit, _)) => { @@ -1419,7 +1420,7 @@ impl<'a> Parser<'a> { } } - fn parse_tuple_parens_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_tuple_parens(&mut self) -> PResult<'a, P<Expr>> { let lo = self.token.span; self.expect(&token::OpenDelim(Delimiter::Parenthesis))?; let (es, trailing_comma) = match self.parse_seq_to_end( @@ -1443,20 +1444,20 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr) } - fn parse_array_or_repeat_expr(&mut self, close_delim: Delimiter) -> PResult<'a, P<Expr>> { + fn parse_expr_array_or_repeat(&mut self, close_delim: Delimiter) -> PResult<'a, P<Expr>> { let lo = self.token.span; self.bump(); // `[` or other open delim let close = &token::CloseDelim(close_delim); let kind = if self.eat(close) { // Empty vector - ExprKind::Array(Vec::new()) + ExprKind::Array(ThinVec::new()) } else { // Non-empty vector let first_expr = self.parse_expr()?; if self.eat(&token::Semi) { // Repeating array syntax: `[ 0; 512 ]` - let count = self.parse_anon_const_expr()?; + let count = self.parse_expr_anon_const()?; self.expect(close)?; ExprKind::Repeat(first_expr, count) } else if self.eat(&token::Comma) { @@ -1468,14 +1469,14 @@ impl<'a> Parser<'a> { } else { // Vector with one element self.expect(close)?; - ExprKind::Array(vec![first_expr]) + ExprKind::Array(thin_vec![first_expr]) } }; let expr = self.mk_expr(lo.to(self.prev_token.span), kind); self.maybe_recover_from_bad_qpath(expr) } - fn parse_path_start_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_path_start(&mut self) -> PResult<'a, P<Expr>> { let (qself, path) = if self.eat_lt() { let (qself, path) = self.parse_qpath(PathStyle::Expr)?; (Some(qself), path) @@ -1512,7 +1513,7 @@ impl<'a> Parser<'a> { } /// Parse `'label: $expr`. The label is already parsed. - fn parse_labeled_expr( + fn parse_expr_labeled( &mut self, label_: Label, mut consume_colon: bool, @@ -1521,15 +1522,15 @@ impl<'a> Parser<'a> { let label = Some(label_); let ate_colon = self.eat(&token::Colon); let expr = if self.eat_keyword(kw::While) { - self.parse_while_expr(label, lo) + self.parse_expr_while(label, lo) } else if self.eat_keyword(kw::For) { - self.parse_for_expr(label, lo) + self.parse_expr_for(label, lo) } else if self.eat_keyword(kw::Loop) { - self.parse_loop_expr(label, lo) + self.parse_expr_loop(label, lo) } else if self.check_noexpect(&token::OpenDelim(Delimiter::Brace)) || self.token.is_whole_block() { - self.parse_block_expr(label, lo, BlockCheckMode::Default) + self.parse_expr_block(label, lo, BlockCheckMode::Default) } else if !ate_colon && self.may_recover() && (matches!(self.token.kind, token::CloseDelim(_) | token::Comma) @@ -1600,7 +1601,7 @@ impl<'a> Parser<'a> { // Replace `'label: non_block_expr` with `'label: {non_block_expr}` in order to suppress future errors about `break 'label`. let stmt = self.mk_stmt(span, StmtKind::Expr(expr)); - let blk = self.mk_block(vec![stmt], BlockCheckMode::Default, span); + let blk = self.mk_block(thin_vec![stmt], BlockCheckMode::Default, span); self.mk_expr(span, ExprKind::Block(blk, label)) }); @@ -1669,7 +1670,7 @@ impl<'a> Parser<'a> { } /// Parse `"return" expr?`. - fn parse_return_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_return(&mut self) -> PResult<'a, P<Expr>> { let lo = self.prev_token.span; let kind = ExprKind::Ret(self.parse_expr_opt()?); let expr = self.mk_expr(lo.to(self.prev_token.span), kind); @@ -1677,7 +1678,7 @@ impl<'a> Parser<'a> { } /// Parse `"do" "yeet" expr?`. - fn parse_yeet_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_yeet(&mut self) -> PResult<'a, P<Expr>> { let lo = self.token.span; self.bump(); // `do` @@ -1699,13 +1700,13 @@ impl<'a> Parser<'a> { /// `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. - fn parse_break_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_break(&mut self) -> PResult<'a, P<Expr>> { let lo = self.prev_token.span; let mut label = self.eat_label(); let kind = if self.token == token::Colon && let Some(label) = label.take() { // The value expression can be a labeled loop, see issue #86948, e.g.: // `loop { break 'label: loop { break 'label 42; }; }` - let lexpr = self.parse_labeled_expr(label, true)?; + let lexpr = self.parse_expr_labeled(label, true)?; self.sess.emit_err(errors::LabeledLoopInBreak { span: lexpr.span, sub: errors::WrapExpressionInParentheses { @@ -1758,7 +1759,7 @@ impl<'a> Parser<'a> { } /// Parse `"continue" label?`. - fn parse_continue_expr(&mut self, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_continue(&mut self, lo: Span) -> PResult<'a, P<Expr>> { let mut label = self.eat_label(); // Recover `continue label` -> `continue 'label` @@ -1775,7 +1776,7 @@ impl<'a> Parser<'a> { } /// Parse `"yield" expr?`. - fn parse_yield_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_yield(&mut self) -> PResult<'a, P<Expr>> { let lo = self.prev_token.span; let kind = ExprKind::Yield(self.parse_expr_opt()?); let span = lo.to(self.prev_token.span); @@ -1992,7 +1993,7 @@ impl<'a> Parser<'a> { /// expression. fn maybe_suggest_brackets_instead_of_braces(&mut self, lo: Span) -> Option<P<Expr>> { let mut snapshot = self.create_snapshot_for_diagnostic(); - match snapshot.parse_array_or_repeat_expr(Delimiter::Brace) { + match snapshot.parse_expr_array_or_repeat(Delimiter::Brace) { Ok(arr) => { self.sess.emit_err(errors::ArrayBracketsInsteadOfSpaces { span: arr.span, @@ -2055,7 +2056,7 @@ impl<'a> Parser<'a> { } /// Parses a block or unsafe block. - pub(super) fn parse_block_expr( + pub(super) fn parse_expr_block( &mut self, opt_label: Option<Label>, lo: Span, @@ -2085,7 +2086,7 @@ impl<'a> Parser<'a> { } /// Parses a closure expression (e.g., `move |args| expr`). - fn parse_closure_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_closure(&mut self) -> PResult<'a, P<Expr>> { let lo = self.token.span; let binder = if self.check_keyword(kw::For) { @@ -2095,7 +2096,7 @@ impl<'a> Parser<'a> { self.sess.gated_spans.gate(sym::closure_lifetime_binder, span); - ClosureBinder::For { span, generic_params: P::from_vec(lifetime_defs) } + ClosureBinder::For { span, generic_params: lifetime_defs } } else { ClosureBinder::NotPresent }; @@ -2122,7 +2123,7 @@ impl<'a> Parser<'a> { _ => { // If an explicit return type is given, require a block to appear (RFC 968). let body_lo = self.token.span; - self.parse_block_expr(None, body_lo, BlockCheckMode::Default)? + self.parse_expr_block(None, body_lo, BlockCheckMode::Default)? } }; @@ -2187,7 +2188,7 @@ impl<'a> Parser<'a> { let arg_start = self.token.span.lo(); let inputs = if self.eat(&token::OrOr) { - Vec::new() + ThinVec::new() } else { self.expect(&token::BinOp(token::Or))?; let args = self @@ -2235,9 +2236,9 @@ impl<'a> Parser<'a> { } /// Parses an `if` expression (`if` token already eaten). - fn parse_if_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_if(&mut self) -> PResult<'a, P<Expr>> { let lo = self.prev_token.span; - let cond = self.parse_cond_expr()?; + let cond = self.parse_expr_cond()?; self.parse_if_after_cond(lo, cond) } @@ -2315,12 +2316,12 @@ impl<'a> Parser<'a> { self.error_on_if_block_attrs(lo, false, block.span, attrs); block }; - let els = if self.eat_keyword(kw::Else) { Some(self.parse_else_expr()?) } else { None }; + let els = if self.eat_keyword(kw::Else) { Some(self.parse_expr_else()?) } else { None }; Ok(self.mk_expr(lo.to(self.prev_token.span), ExprKind::If(cond, thn, els))) } /// Parses the condition of a `if` or `while` expression. - fn parse_cond_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_cond(&mut self) -> PResult<'a, P<Expr>> { let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)?; @@ -2333,7 +2334,7 @@ impl<'a> Parser<'a> { } /// Parses a `let $pat = $expr` pseudo-expression. - fn parse_let_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_let(&mut self) -> PResult<'a, P<Expr>> { // This is a *approximate* heuristic that detects if `let` chains are // being parsed in the right position. It's approximate because it // doesn't deny all invalid `let` expressions, just completely wrong usages. @@ -2363,7 +2364,7 @@ impl<'a> Parser<'a> { self.expect(&token::Eq)?; } let expr = self.with_res(self.restrictions | Restrictions::NO_STRUCT_LITERAL, |this| { - this.parse_assoc_expr_with(1 + prec_let_scrutinee_needs_par(), None.into()) + this.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into()) })?; let span = lo.to(expr.span); self.sess.gated_spans.gate(sym::let_chains, span); @@ -2371,11 +2372,11 @@ impl<'a> Parser<'a> { } /// Parses an `else { ... }` expression (`else` token already eaten). - fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_else(&mut self) -> PResult<'a, P<Expr>> { let else_span = self.prev_token.span; // `else` let attrs = self.parse_outer_attributes()?; // For recovery. let expr = if self.eat_keyword(kw::If) { - self.parse_if_expr()? + self.parse_expr_if()? } else if self.check(&TokenKind::OpenDelim(Delimiter::Brace)) { self.parse_simple_block()? } else { @@ -2449,7 +2450,7 @@ impl<'a> Parser<'a> { } /// Parses `for <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten). - fn parse_for_expr(&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>> { // Record whether we are about to parse `for (`. // This is used below for recovery in case of `for ( $stuff ) $block` // in which case we will suggest `for $stuff $block`. @@ -2480,7 +2481,7 @@ impl<'a> Parser<'a> { self.sess .emit_err(errors::MissingExpressionInForLoop { span: expr.span.shrink_to_lo() }); let err_expr = self.mk_expr(expr.span, ExprKind::Err); - let block = self.mk_block(vec![], BlockCheckMode::Default, self.prev_token.span); + let block = self.mk_block(thin_vec![], BlockCheckMode::Default, self.prev_token.span); return Ok(self.mk_expr( lo.to(self.prev_token.span), ExprKind::ForLoop(pat, err_expr, block, opt_label), @@ -2507,8 +2508,8 @@ impl<'a> Parser<'a> { } /// Parses a `while` or `while let` expression (`while` token already eaten). - fn parse_while_expr(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> { - let cond = self.parse_cond_expr().map_err(|mut err| { + fn parse_expr_while(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> { + let cond = self.parse_expr_cond().map_err(|mut err| { err.span_label(lo, "while parsing the condition of this `while` expression"); err })?; @@ -2525,7 +2526,7 @@ impl<'a> Parser<'a> { } /// Parses `loop { ... }` (`loop` token already eaten). - fn parse_loop_expr(&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>> { let loop_span = self.prev_token.span; let (attrs, body) = self.parse_inner_attrs_and_block()?; Ok(self.mk_expr_with_attrs( @@ -2543,7 +2544,7 @@ impl<'a> Parser<'a> { } /// Parses a `match ... { ... }` expression (`match` token already eaten). - fn parse_match_expr(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_match(&mut self) -> PResult<'a, P<Expr>> { let match_span = self.prev_token.span; let lo = self.prev_token.span; let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; @@ -2565,7 +2566,7 @@ impl<'a> Parser<'a> { } let attrs = self.parse_inner_attributes()?; - let mut arms: Vec<Arm> = Vec::new(); + let mut arms = ThinVec::new(); while self.token != token::CloseDelim(Delimiter::Brace) { match self.parse_arm() { Ok(arm) => arms.push(arm), @@ -2913,7 +2914,7 @@ impl<'a> Parser<'a> { if let Err(err) = self.expect(&token::OpenDelim(Delimiter::Brace)) { return Some(Err(err)); } - let expr = self.parse_struct_expr(qself.clone(), path.clone(), true); + let expr = self.parse_expr_struct(qself.clone(), path.clone(), true); if let (Ok(expr), false) = (&expr, struct_allowed) { // This is a struct literal, but we don't can't accept them here. self.sess.emit_err(errors::StructLiteralNotAllowedHere { @@ -2934,8 +2935,8 @@ impl<'a> Parser<'a> { pth: ast::Path, recover: bool, close_delim: Delimiter, - ) -> PResult<'a, (Vec<ExprField>, ast::StructRest, bool)> { - let mut fields = Vec::new(); + ) -> PResult<'a, (ThinVec<ExprField>, ast::StructRest, bool)> { + let mut fields = ThinVec::new(); let mut base = ast::StructRest::None; let mut recover_async = false; @@ -3042,7 +3043,7 @@ impl<'a> Parser<'a> { } /// Precondition: already parsed the '{'. - pub(super) fn parse_struct_expr( + pub(super) fn parse_expr_struct( &mut self, qself: Option<P<ast::QSelf>>, pth: ast::Path, @@ -3211,7 +3212,7 @@ impl<'a> Parser<'a> { ExprKind::Index(expr, idx) } - fn mk_call(&self, f: P<Expr>, args: Vec<P<Expr>>) -> ExprKind { + fn mk_call(&self, f: P<Expr>, args: ThinVec<P<Expr>>) -> ExprKind { ExprKind::Call(f, args) } diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 23f49ec55a1..8d0f168e09d 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -14,10 +14,11 @@ use rustc_ast::{ use rustc_errors::{Applicability, PResult}; use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; +use thin_vec::ThinVec; enum PredicateOrStructBody { Predicate(ast::WherePredicate), - StructBody(Vec<ast::FieldDef>), + StructBody(ThinVec<ast::FieldDef>), } impl<'a> Parser<'a> { @@ -121,8 +122,8 @@ impl<'a> Parser<'a> { /// Parses a (possibly empty) list of lifetime and type parameters, possibly including /// a trailing comma and erroneous trailing attributes. - pub(super) fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> { - let mut params = Vec::new(); + pub(super) fn parse_generic_params(&mut self) -> PResult<'a, ThinVec<ast::GenericParam>> { + let mut params = ThinVec::new(); let mut done = false; while !done { let attrs = self.parse_outer_attributes()?; @@ -251,13 +252,13 @@ impl<'a> Parser<'a> { self.expect_gt()?; (params, span_lo.to(self.prev_token.span)) } else { - (vec![], self.prev_token.span.shrink_to_hi()) + (ThinVec::new(), self.prev_token.span.shrink_to_hi()) }; Ok(ast::Generics { params, where_clause: WhereClause { has_where_token: false, - predicates: Vec::new(), + predicates: ThinVec::new(), span: self.prev_token.span.shrink_to_hi(), }, span, @@ -277,17 +278,17 @@ impl<'a> Parser<'a> { &mut self, struct_name: Ident, body_insertion_point: Span, - ) -> PResult<'a, (WhereClause, Option<Vec<ast::FieldDef>>)> { + ) -> PResult<'a, (WhereClause, Option<ThinVec<ast::FieldDef>>)> { self.parse_where_clause_common(Some((struct_name, body_insertion_point))) } fn parse_where_clause_common( &mut self, struct_: Option<(Ident, Span)>, - ) -> PResult<'a, (WhereClause, Option<Vec<ast::FieldDef>>)> { + ) -> PResult<'a, (WhereClause, Option<ThinVec<ast::FieldDef>>)> { let mut where_clause = WhereClause { has_where_token: false, - predicates: Vec::new(), + predicates: ThinVec::new(), span: self.prev_token.span.shrink_to_hi(), }; let mut tuple_struct_body = None; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index f164bb330f3..9d9ae154ad4 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -26,7 +26,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::DUMMY_SP; use std::fmt::Write; use std::mem; -use thin_vec::ThinVec; +use thin_vec::{thin_vec, ThinVec}; impl<'a> Parser<'a> { /// Parses a source module as a crate. This is the main entry point for the parser. @@ -56,12 +56,12 @@ impl<'a> Parser<'a> { pub fn parse_mod( &mut self, term: &TokenKind, - ) -> PResult<'a, (AttrVec, Vec<P<Item>>, ModSpans)> { + ) -> PResult<'a, (AttrVec, ThinVec<P<Item>>, ModSpans)> { let lo = self.token.span; let attrs = self.parse_inner_attributes()?; let post_attr_lo = self.token.span; - let mut items = vec![]; + let mut items = ThinVec::new(); while let Some(item) = self.parse_item(ForceCollect::No)? { items.push(item); self.maybe_consume_incorrect_semicolon(&items); @@ -646,20 +646,20 @@ impl<'a> Parser<'a> { &mut self, attrs: &mut AttrVec, mut parse_item: impl FnMut(&mut Parser<'a>) -> PResult<'a, Option<Option<T>>>, - ) -> PResult<'a, Vec<T>> { + ) -> PResult<'a, ThinVec<T>> { let open_brace_span = self.token.span; // Recover `impl Ty;` instead of `impl Ty {}` if self.token == TokenKind::Semi { self.sess.emit_err(errors::UseEmptyBlockNotSemi { span: self.token.span }); self.bump(); - return Ok(vec![]); + return Ok(ThinVec::new()); } self.expect(&token::OpenDelim(Delimiter::Brace))?; attrs.extend(self.parse_inner_attributes()?); - let mut items = Vec::new(); + let mut items = ThinVec::new(); while !self.eat(&token::CloseDelim(Delimiter::Brace)) { if self.recover_doc_comment_before_brace() { continue; @@ -997,7 +997,7 @@ impl<'a> Parser<'a> { /// ```text /// USE_TREE_LIST = Ø | (USE_TREE `,`)* USE_TREE [`,`] /// ``` - fn parse_use_tree_list(&mut self) -> PResult<'a, Vec<(UseTree, ast::NodeId)>> { + fn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, ast::NodeId)>> { self.parse_delim_comma_seq(Delimiter::Brace, |p| { p.recover_diff_marker(); Ok((p.parse_use_tree()?, DUMMY_NODE_ID)) @@ -1288,7 +1288,7 @@ impl<'a> Parser<'a> { let (variants, _) = if self.token == TokenKind::Semi { self.sess.emit_err(errors::UseEmptyBlockNotSemi { span: self.token.span }); self.bump(); - (vec![], false) + (thin_vec![], false) } else { self.parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant()).map_err( |mut e| { @@ -1331,7 +1331,7 @@ impl<'a> Parser<'a> { }; let disr_expr = - if this.eat(&token::Eq) { Some(this.parse_anon_const_expr()?) } else { None }; + if this.eat(&token::Eq) { Some(this.parse_expr_anon_const()?) } else { None }; let vr = ast::Variant { ident, @@ -1457,8 +1457,8 @@ impl<'a> Parser<'a> { adt_ty: &str, ident_span: Span, parsed_where: bool, - ) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> { - let mut fields = Vec::new(); + ) -> PResult<'a, (ThinVec<FieldDef>, /* recovered */ bool)> { + let mut fields = ThinVec::new(); let mut recovered = false; if self.eat(&token::OpenDelim(Delimiter::Brace)) { while self.token != token::CloseDelim(Delimiter::Brace) { @@ -1498,7 +1498,7 @@ impl<'a> Parser<'a> { Ok((fields, recovered)) } - pub(super) fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<FieldDef>> { + pub(super) fn parse_tuple_struct_body(&mut self) -> PResult<'a, ThinVec<FieldDef>> { // This is the case where we find `struct Foo<T>(T) where T: Copy;` // Unit like structs are handled in parse_item_struct function self.parse_paren_comma_seq(|p| { @@ -1722,7 +1722,7 @@ impl<'a> Parser<'a> { } if self.token.kind == token::Eq { self.bump(); - let const_expr = self.parse_anon_const_expr()?; + let const_expr = self.parse_expr_anon_const()?; let sp = ty.span.shrink_to_hi().to(const_expr.value.span); self.struct_span_err(sp, "default values on `struct` fields aren't supported") .span_suggestion( @@ -2374,7 +2374,7 @@ impl<'a> Parser<'a> { } /// Parses the parameter list of a function, including the `(` and `)` delimiters. - pub(super) fn parse_fn_params(&mut self, req_name: ReqName) -> PResult<'a, Vec<Param>> { + pub(super) fn parse_fn_params(&mut self, req_name: ReqName) -> PResult<'a, ThinVec<Param>> { let mut first_param = true; // Parse the arguments, starting out with `self` being allowed... let (mut params, _) = self.parse_paren_comma_seq(|p| { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index a74f408d774..fda9151478f 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -36,9 +36,10 @@ use rustc_errors::{ use rustc_session::parse::ParseSess; use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; - use std::ops::Range; use std::{cmp, mem, slice}; +use thin_vec::ThinVec; +use tracing::debug; use crate::errors::{ DocCommentDoesNotDocumentAnything, IncorrectVisibilityRestriction, MismatchedClosingDelimiter, @@ -853,11 +854,11 @@ impl<'a> Parser<'a> { sep: SeqSep, expect: TokenExpectType, mut f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool /* trailing */, bool /* recovered */)> { + ) -> PResult<'a, (ThinVec<T>, bool /* trailing */, bool /* recovered */)> { let mut first = true; let mut recovered = false; let mut trailing = false; - let mut v = vec![]; + let mut v = ThinVec::new(); let unclosed_delims = !self.unclosed_delims.is_empty(); while !self.expect_any_with_type(kets, expect) { @@ -981,7 +982,11 @@ impl<'a> Parser<'a> { let initial_semicolon = self.token.span; while self.eat(&TokenKind::Semi) { - let _ = self.parse_stmt(ForceCollect::Yes)?; + let _ = + self.parse_stmt_without_recovery(false, ForceCollect::Yes).unwrap_or_else(|e| { + e.cancel(); + None + }); } expect_err.set_primary_message( @@ -1037,7 +1042,7 @@ impl<'a> Parser<'a> { ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool, bool)> { + ) -> PResult<'a, (ThinVec<T>, bool, bool)> { self.parse_seq_to_before_tokens(&[ket], sep, TokenExpectType::Expect, f) } @@ -1049,7 +1054,7 @@ impl<'a> Parser<'a> { ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool /* trailing */)> { + ) -> PResult<'a, (ThinVec<T>, bool /* trailing */)> { let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?; if !recovered { self.eat(ket); @@ -1066,7 +1071,7 @@ impl<'a> Parser<'a> { ket: &TokenKind, sep: SeqSep, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool)> { + ) -> PResult<'a, (ThinVec<T>, bool)> { self.expect(bra)?; self.parse_seq_to_end(ket, sep, f) } @@ -1075,7 +1080,7 @@ impl<'a> Parser<'a> { &mut self, delim: Delimiter, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool)> { + ) -> PResult<'a, (ThinVec<T>, bool)> { self.parse_unspanned_seq( &token::OpenDelim(delim), &token::CloseDelim(delim), @@ -1087,7 +1092,7 @@ impl<'a> Parser<'a> { fn parse_paren_comma_seq<T>( &mut self, f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, - ) -> PResult<'a, (Vec<T>, bool)> { + ) -> PResult<'a, (ThinVec<T>, bool)> { self.parse_delim_comma_seq(Delimiter::Parenthesis, f) } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index b054dc59a0c..8e920f1c421 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -8,6 +8,7 @@ use crate::errors::{ TrailingVertNotAllowed, UnexpectedLifetimeInPattern, UnexpectedVertVertBeforeFunctionParam, UnexpectedVertVertInPattern, }; +use crate::fluent_generated as fluent; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor}; use rustc_ast::ptr::P; @@ -17,12 +18,11 @@ use rustc_ast::{ PatField, PatKind, Path, QSelf, RangeEnd, RangeSyntax, }; use rustc_ast_pretty::pprust; -use rustc_errors::{ - fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult, -}; +use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, PResult}; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::{respan, Span, Spanned}; use rustc_span::symbol::{kw, sym, Ident}; +use thin_vec::{thin_vec, ThinVec}; #[derive(PartialEq, Copy, Clone)] pub enum Expected { @@ -155,7 +155,7 @@ impl<'a> Parser<'a> { // If there was a leading vert, treat this as an or-pattern. This improves // diagnostics. let span = leading_vert_span.to(self.prev_token.span); - return Ok((self.mk_pat(span, PatKind::Or(vec![first_pat])), trailing_vert)); + return Ok((self.mk_pat(span, PatKind::Or(thin_vec![first_pat])), trailing_vert)); } return Ok((first_pat, trailing_vert)); @@ -163,7 +163,7 @@ impl<'a> Parser<'a> { // Parse the patterns `p_1 | ... | p_n` where `n > 0`. let lo = leading_vert_span.unwrap_or(first_pat.span); - let mut pats = vec![first_pat]; + let mut pats = thin_vec![first_pat]; loop { match self.eat_or_separator(Some(lo)) { EatOrResult::AteOr => {} @@ -853,7 +853,7 @@ impl<'a> Parser<'a> { e.span_label(path.span, "while parsing the fields for this pattern"); e.emit(); self.recover_stmt(); - (vec![], true) + (ThinVec::new(), true) }); self.bump(); Ok(PatKind::Struct(qself, path, fields, etc)) @@ -932,8 +932,8 @@ impl<'a> Parser<'a> { } /// Parses the fields of a struct-like pattern. - fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<PatField>, bool)> { - let mut fields = Vec::new(); + fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec<PatField>, bool)> { + let mut fields = ThinVec::new(); let mut etc = false; let mut ate_comma = true; let mut delayed_err: Option<DiagnosticBuilder<'a, ErrorGuaranteed>> = None; diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 49959a8981c..b50d2984a4e 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -332,7 +332,7 @@ impl<'a> Parser<'a> { style: PathStyle, lo: Span, ty_generics: Option<&Generics>, - ) -> PResult<'a, Vec<AngleBracketedArg>> { + ) -> PResult<'a, ThinVec<AngleBracketedArg>> { // We need to detect whether there are extra leading left angle brackets and produce an // appropriate error and suggestion. This cannot be implemented by looking ahead at // upcoming tokens for a matching `>` character - if there are unmatched `<` tokens @@ -472,8 +472,8 @@ impl<'a> Parser<'a> { pub(super) fn parse_angle_args( &mut self, ty_generics: Option<&Generics>, - ) -> PResult<'a, Vec<AngleBracketedArg>> { - let mut args = Vec::new(); + ) -> PResult<'a, ThinVec<AngleBracketedArg>> { + let mut args = ThinVec::new(); while let Some(arg) = self.parse_angle_arg(ty_generics)? { args.push(arg); if !self.eat(&token::Comma) { @@ -653,7 +653,7 @@ impl<'a> Parser<'a> { pub(super) fn parse_const_arg(&mut self) -> PResult<'a, AnonConst> { // Parse const argument. let value = if let token::OpenDelim(Delimiter::Brace) = self.token.kind { - self.parse_block_expr(None, self.token.span, BlockCheckMode::Default)? + self.parse_expr_block(None, self.token.span, BlockCheckMode::Default)? } else { self.handle_unambiguous_unbraced_const_arg()? }; diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 3afda5f69f0..92a22ffc2b0 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -20,8 +20,8 @@ use rustc_ast::{StmtKind, DUMMY_NODE_ID}; use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult}; use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym}; - use std::mem; +use thin_vec::{thin_vec, ThinVec}; impl<'a> Parser<'a> { /// Parses a statement. This stops just before trailing semicolons on everything but items. @@ -146,14 +146,14 @@ impl<'a> Parser<'a> { } let expr = if this.eat(&token::OpenDelim(Delimiter::Brace)) { - this.parse_struct_expr(None, path, true)? + this.parse_expr_struct(None, path, true)? } else { let hi = this.prev_token.span; this.mk_expr(lo.to(hi), ExprKind::Path(None, path)) }; let expr = this.with_res(Restrictions::STMT_EXPR, |this| { - this.parse_dot_or_call_expr_with(expr, lo, attrs) + this.parse_expr_dot_or_call_with(expr, lo, attrs) })?; // `DUMMY_SP` will get overwritten later in this function Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None)) @@ -163,7 +163,7 @@ impl<'a> Parser<'a> { // Perform this outside of the `collect_tokens_trailing_token` closure, // since our outer attributes do not apply to this part of the expression let expr = self.with_res(Restrictions::STMT_EXPR, |this| { - this.parse_assoc_expr_with( + this.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr, starts_statement: true }, ) @@ -199,8 +199,8 @@ impl<'a> Parser<'a> { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); let e = self.maybe_recover_from_bad_qpath(e)?; - let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; - let e = self.parse_assoc_expr_with( + let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?; + let e = self.parse_expr_assoc_with( 0, LhsExpr::AlreadyParsed { expr: e, starts_statement: false }, )?; @@ -544,7 +544,7 @@ impl<'a> Parser<'a> { s: BlockCheckMode, recover: AttemptLocalParseRecovery, ) -> PResult<'a, P<Block>> { - let mut stmts = vec![]; + let mut stmts = ThinVec::new(); let mut snapshot = None; while !self.eat(&token::CloseDelim(Delimiter::Brace)) { if self.token == token::Eof { @@ -662,7 +662,12 @@ impl<'a> Parser<'a> { Ok(Some(stmt)) } - pub(super) fn mk_block(&self, stmts: Vec<Stmt>, rules: BlockCheckMode, span: Span) -> P<Block> { + pub(super) fn mk_block( + &self, + stmts: ThinVec<Stmt>, + rules: BlockCheckMode, + span: Span, + ) -> P<Block> { P(Block { stmts, id: DUMMY_NODE_ID, @@ -682,6 +687,6 @@ impl<'a> Parser<'a> { } pub(super) fn mk_block_err(&self, span: Span) -> P<Block> { - self.mk_block(vec![self.mk_stmt_err(span)], BlockCheckMode::Default, span) + self.mk_block(thin_vec![self.mk_stmt_err(span)], BlockCheckMode::Default, span) } } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 4f4252b532e..6fe4da71f6b 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -21,7 +21,7 @@ use rustc_errors::{Applicability, PResult}; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Symbol; -use thin_vec::thin_vec; +use thin_vec::{thin_vec, ThinVec}; /// Any `?` or `~const` modifiers that appear at the start of a bound. struct BoundModifiers { @@ -273,7 +273,7 @@ impl<'a> Parser<'a> { TyKind::Infer } else if self.check_fn_front_matter(false, Case::Sensitive) { // Function pointer type - self.parse_ty_bare_fn(lo, Vec::new(), None, recover_return_sign)? + self.parse_ty_bare_fn(lo, ThinVec::new(), None, recover_return_sign)? } else if self.check_keyword(kw::For) { // Function pointer type or bound list (trait object type) starting with a poly-trait. // `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T` @@ -352,7 +352,7 @@ impl<'a> Parser<'a> { match ty.kind { // `(TY_BOUND_NOPAREN) + BOUND + ...`. TyKind::Path(None, path) if maybe_bounds => { - self.parse_remaining_bounds_path(Vec::new(), path, lo, true) + self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true) } TyKind::TraitObject(bounds, TraitObjectSyntax::None) if maybe_bounds && bounds.len() == 1 && !trailing_plus => @@ -378,7 +378,7 @@ impl<'a> Parser<'a> { fn parse_remaining_bounds_path( &mut self, - generic_params: Vec<GenericParam>, + generic_params: ThinVec<GenericParam>, path: ast::Path, lo: Span, parse_plus: bool, @@ -433,7 +433,7 @@ impl<'a> Parser<'a> { }; let ty = if self.eat(&token::Semi) { - let mut length = self.parse_anon_const_expr()?; + let mut length = self.parse_expr_anon_const()?; if let Err(e) = self.expect(&token::CloseDelim(Delimiter::Bracket)) { // Try to recover from `X<Y, ...>` when `X::<Y, ...>` works self.check_mistyped_turbofish_with_multiple_type_params(e, &mut length.value)?; @@ -494,7 +494,7 @@ impl<'a> Parser<'a> { // To avoid ambiguity, the type is surrounded by parentheses. fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> { self.expect(&token::OpenDelim(Delimiter::Parenthesis))?; - let expr = self.parse_anon_const_expr()?; + let expr = self.parse_expr_anon_const()?; self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; Ok(TyKind::Typeof(expr)) } @@ -511,7 +511,7 @@ impl<'a> Parser<'a> { fn parse_ty_bare_fn( &mut self, lo: Span, - mut params: Vec<GenericParam>, + mut params: ThinVec<GenericParam>, param_insertion_point: Option<Span>, recover_return_sign: RecoverReturnSign, ) -> PResult<'a, TyKind> { @@ -545,13 +545,13 @@ impl<'a> Parser<'a> { fn recover_fn_ptr_with_generics( &mut self, lo: Span, - params: &mut Vec<GenericParam>, + params: &mut ThinVec<GenericParam>, param_insertion_point: Option<Span>, ) -> PResult<'a, ()> { let generics = self.parse_generics()?; let arity = generics.params.len(); - let mut lifetimes: Vec<_> = generics + let mut lifetimes: ThinVec<_> = generics .params .into_iter() .filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime)) @@ -662,7 +662,7 @@ impl<'a> Parser<'a> { }))) } else if allow_plus == AllowPlus::Yes && self.check_plus() { // `Trait1 + Trait2 + 'a` - self.parse_remaining_bounds_path(Vec::new(), path, lo, true) + self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true) } else { // Just a type path. Ok(TyKind::Path(None, path)) @@ -993,7 +993,7 @@ impl<'a> Parser<'a> { } /// Optionally parses `for<$generic_params>`. - pub(super) fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> { + pub(super) fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, ThinVec<GenericParam>> { if self.eat_keyword(kw::For) { self.expect_lt()?; let params = self.parse_generic_params()?; @@ -1002,7 +1002,7 @@ impl<'a> Parser<'a> { // parameters, and the lifetime parameters must not have bounds. Ok(params) } else { - Ok(Vec::new()) + Ok(ThinVec::new()) } } @@ -1012,7 +1012,7 @@ impl<'a> Parser<'a> { fn recover_fn_trait_with_lifetime_params( &mut self, fn_path: &mut ast::Path, - lifetime_defs: &mut Vec<GenericParam>, + lifetime_defs: &mut ThinVec<GenericParam>, ) -> PResult<'a, ()> { let fn_path_segment = fn_path.segments.last_mut().unwrap(); let generic_args = if let Some(p_args) = &fn_path_segment.args { @@ -1046,7 +1046,7 @@ impl<'a> Parser<'a> { // Parse `(T, U) -> R`. let inputs_lo = self.token.span; - let inputs: Vec<_> = + let inputs: ThinVec<_> = self.parse_fn_params(|_| false)?.into_iter().map(|input| input.ty).collect(); let inputs_span = inputs_lo.to(self.prev_token.span); let output = self.parse_ret_ty(AllowPlus::No, RecoverQPath::No, RecoverReturnSign::No)?; @@ -1072,7 +1072,7 @@ impl<'a> Parser<'a> { kind: ast::GenericParamKind::Lifetime, colon_span: None, }) - .collect::<Vec<GenericParam>>(); + .collect::<ThinVec<GenericParam>>(); lifetime_defs.append(&mut generic_params); let generic_args_span = generic_args.span(); |
