Skip to content

Commit 14e5ba0

Browse files
committed
Mark expr_requires_semi_to_be_stmt call sites
For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization.
1 parent 951984e commit 14e5ba0

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

compiler/rustc_ast/src/util/classify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ use crate::{ast, token::Delimiter};
4242
/// _ => m! {} - 1, // binary subtraction operator
4343
/// }
4444
/// ```
45-
pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
45+
#[allow(non_snake_case)]
46+
pub fn expr_requires_semi_to_be_stmt_FIXME(e: &ast::Expr) -> bool {
4647
!matches!(
4748
e.kind,
4849
ast::ExprKind::If(..)

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ impl<'a> State<'a> {
12531253
ast::StmtKind::Expr(expr) => {
12541254
self.space_if_not_bol();
12551255
self.print_expr_outer_attr_style(expr, false, FixupContext::new_stmt());
1256-
if classify::expr_requires_semi_to_be_stmt(expr) {
1256+
if classify::expr_requires_semi_to_be_stmt_FIXME(expr) {
12571257
self.word(";");
12581258
}
12591259
}

compiler/rustc_ast_pretty/src/pprust/state/fixup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl FixupContext {
128128
/// The documentation on `FixupContext::leftmost_subexpression_in_stmt` has
129129
/// examples.
130130
pub fn would_cause_statement_boundary(self, expr: &Expr) -> bool {
131-
self.leftmost_subexpression_in_stmt && !classify::expr_requires_semi_to_be_stmt(expr)
131+
self.leftmost_subexpression_in_stmt && !classify::expr_requires_semi_to_be_stmt_FIXME(expr)
132132
}
133133

134134
/// Determine whether parentheses are needed around the given `let`

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ trait UnusedDelimLint {
686686
ExprKind::Index(base, _subscript, _) => base,
687687
_ => break,
688688
};
689-
if !classify::expr_requires_semi_to_be_stmt(innermost) {
689+
if !classify::expr_requires_semi_to_be_stmt_FIXME(innermost) {
690690
return true;
691691
}
692692
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'a> Parser<'a> {
484484
/// Checks if this expression is a successfully parsed statement.
485485
fn expr_is_complete(&self, e: &Expr) -> bool {
486486
self.restrictions.contains(Restrictions::STMT_EXPR)
487-
&& !classify::expr_requires_semi_to_be_stmt(e)
487+
&& !classify::expr_requires_semi_to_be_stmt_FIXME(e)
488488
}
489489

490490
/// Parses `x..y`, `x..=y`, and `x..`/`x..=`.
@@ -2672,7 +2672,7 @@ impl<'a> Parser<'a> {
26722672
// If it's not a free-standing expression, and is followed by a block,
26732673
// then it's very likely the condition to an `else if`.
26742674
if self.check(&TokenKind::OpenDelim(Delimiter::Brace))
2675-
&& classify::expr_requires_semi_to_be_stmt(&cond) =>
2675+
&& classify::expr_requires_semi_to_be_stmt_FIXME(&cond) =>
26762676
{
26772677
self.dcx().emit_err(errors::ExpectedElseBlock {
26782678
first_tok_span,
@@ -3114,7 +3114,7 @@ impl<'a> Parser<'a> {
31143114
err
31153115
})?;
31163116

3117-
let require_comma = classify::expr_requires_semi_to_be_stmt(&expr)
3117+
let require_comma = classify::expr_requires_semi_to_be_stmt_FIXME(&expr)
31183118
&& this.token != token::CloseDelim(Delimiter::Brace);
31193119

31203120
if !require_comma {

compiler/rustc_parse/src/parser/stmt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'a> Parser<'a> {
649649
match &mut stmt.kind {
650650
// Expression without semicolon.
651651
StmtKind::Expr(expr)
652-
if classify::expr_requires_semi_to_be_stmt(expr)
652+
if classify::expr_requires_semi_to_be_stmt_FIXME(expr)
653653
&& !expr.attrs.is_empty()
654654
&& ![token::Eof, token::Semi, token::CloseDelim(Delimiter::Brace)]
655655
.contains(&self.token.kind) =>
@@ -663,7 +663,8 @@ impl<'a> Parser<'a> {
663663

664664
// Expression without semicolon.
665665
StmtKind::Expr(expr)
666-
if self.token != token::Eof && classify::expr_requires_semi_to_be_stmt(expr) =>
666+
if self.token != token::Eof
667+
&& classify::expr_requires_semi_to_be_stmt_FIXME(expr) =>
667668
{
668669
// Just check for errors and recover; do not eat semicolon yet.
669670

0 commit comments

Comments
 (0)