Skip to content

Commit 2850116

Browse files
committed
Replace parse_[sth]_expr with parse_expr_[sth] function names
This resolves an inconsistency in naming style for functions on the parser, between functions parsing specific kinds of items and those for expressions, favoring the parse_item_[sth] style used by functions for items. There are multiple advantages of that style: * functions of both categories are collected in the same place in the rustdoc output. * it helps with autocompletion, as you can narrow down your search for a function to those about expressions. * it mirrors rust's path syntax where less specific things come first, then it gets more specific, i.e. std::collections::hash_map::Entry The disadvantage is that it doesn't "read like a sentence" any more, but I think the advantages weigh more greatly. This change was mostly application of this command: sed -i -E 's/(fn |\.)parse_([[:alnum:]_]+)_expr/\1parse_expr_\2/' compiler/rustc_parse/src/parser/*.rs Plus very minor fixes outside of rustc_parse, and an invocation of x fmt.
1 parent 07c993e commit 2850116

File tree

7 files changed

+131
-131
lines changed

7 files changed

+131
-131
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn parse_asm_args<'a>(
152152
ast::InlineAsmOperand::InOut { reg, expr, late: true }
153153
}
154154
} else if p.eat_keyword(kw::Const) {
155-
let anon_const = p.parse_anon_const_expr()?;
155+
let anon_const = p.parse_expr_anon_const()?;
156156
ast::InlineAsmOperand::Const { anon_const }
157157
} else if p.eat_keyword(sym::sym) {
158158
let expr = p.parse_expr()?;

compiler/rustc_parse/src/parser/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl<'a> Parser<'a> {
693693
span: self.prev_token.span.shrink_to_lo(),
694694
tokens: None,
695695
};
696-
let struct_expr = snapshot.parse_struct_expr(None, path, false);
696+
let struct_expr = snapshot.parse_expr_struct(None, path, false);
697697
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
698698
return Some(match (struct_expr, block_tail) {
699699
(Ok(expr), Err(mut err)) => {
@@ -1624,7 +1624,7 @@ impl<'a> Parser<'a> {
16241624
// Handle `await { <expr> }`.
16251625
// This needs to be handled separately from the next arm to avoid
16261626
// interpreting `await { <expr> }?` as `<expr>?.await`.
1627-
self.parse_block_expr(None, self.token.span, BlockCheckMode::Default)
1627+
self.parse_expr_block(None, self.token.span, BlockCheckMode::Default)
16281628
} else {
16291629
self.parse_expr()
16301630
}

compiler/rustc_parse/src/parser/expr.rs

+118-118
Large diffs are not rendered by default.

compiler/rustc_parse/src/parser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<'a> Parser<'a> {
13311331
};
13321332

13331333
let disr_expr =
1334-
if this.eat(&token::Eq) { Some(this.parse_anon_const_expr()?) } else { None };
1334+
if this.eat(&token::Eq) { Some(this.parse_expr_anon_const()?) } else { None };
13351335

13361336
let vr = ast::Variant {
13371337
ident,
@@ -1722,7 +1722,7 @@ impl<'a> Parser<'a> {
17221722
}
17231723
if self.token.kind == token::Eq {
17241724
self.bump();
1725-
let const_expr = self.parse_anon_const_expr()?;
1725+
let const_expr = self.parse_expr_anon_const()?;
17261726
let sp = ty.span.shrink_to_hi().to(const_expr.value.span);
17271727
self.struct_span_err(sp, "default values on `struct` fields aren't supported")
17281728
.span_suggestion(

compiler/rustc_parse/src/parser/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl<'a> Parser<'a> {
653653
pub(super) fn parse_const_arg(&mut self) -> PResult<'a, AnonConst> {
654654
// Parse const argument.
655655
let value = if let token::OpenDelim(Delimiter::Brace) = self.token.kind {
656-
self.parse_block_expr(None, self.token.span, BlockCheckMode::Default)?
656+
self.parse_expr_block(None, self.token.span, BlockCheckMode::Default)?
657657
} else {
658658
self.handle_unambiguous_unbraced_const_arg()?
659659
};

compiler/rustc_parse/src/parser/stmt.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ impl<'a> Parser<'a> {
146146
}
147147

148148
let expr = if this.eat(&token::OpenDelim(Delimiter::Brace)) {
149-
this.parse_struct_expr(None, path, true)?
149+
this.parse_expr_struct(None, path, true)?
150150
} else {
151151
let hi = this.prev_token.span;
152152
this.mk_expr(lo.to(hi), ExprKind::Path(None, path))
153153
};
154154

155155
let expr = this.with_res(Restrictions::STMT_EXPR, |this| {
156-
this.parse_dot_or_call_expr_with(expr, lo, attrs)
156+
this.parse_expr_dot_or_call_with(expr, lo, attrs)
157157
})?;
158158
// `DUMMY_SP` will get overwritten later in this function
159159
Ok((this.mk_stmt(rustc_span::DUMMY_SP, StmtKind::Expr(expr)), TrailingToken::None))
@@ -163,7 +163,7 @@ impl<'a> Parser<'a> {
163163
// Perform this outside of the `collect_tokens_trailing_token` closure,
164164
// since our outer attributes do not apply to this part of the expression
165165
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
166-
this.parse_assoc_expr_with(
166+
this.parse_expr_assoc_with(
167167
0,
168168
LhsExpr::AlreadyParsed { expr, starts_statement: true },
169169
)
@@ -199,8 +199,8 @@ impl<'a> Parser<'a> {
199199
// Since none of the above applied, this is an expression statement macro.
200200
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
201201
let e = self.maybe_recover_from_bad_qpath(e)?;
202-
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
203-
let e = self.parse_assoc_expr_with(
202+
let e = self.parse_expr_dot_or_call_with(e, lo, attrs)?;
203+
let e = self.parse_expr_assoc_with(
204204
0,
205205
LhsExpr::AlreadyParsed { expr: e, starts_statement: false },
206206
)?;

compiler/rustc_parse/src/parser/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'a> Parser<'a> {
433433
};
434434

435435
let ty = if self.eat(&token::Semi) {
436-
let mut length = self.parse_anon_const_expr()?;
436+
let mut length = self.parse_expr_anon_const()?;
437437
if let Err(e) = self.expect(&token::CloseDelim(Delimiter::Bracket)) {
438438
// Try to recover from `X<Y, ...>` when `X::<Y, ...>` works
439439
self.check_mistyped_turbofish_with_multiple_type_params(e, &mut length.value)?;
@@ -494,7 +494,7 @@ impl<'a> Parser<'a> {
494494
// To avoid ambiguity, the type is surrounded by parentheses.
495495
fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> {
496496
self.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
497-
let expr = self.parse_anon_const_expr()?;
497+
let expr = self.parse_expr_anon_const()?;
498498
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
499499
Ok(TyKind::Typeof(expr))
500500
}

0 commit comments

Comments
 (0)