Skip to content

Commit dd884e0

Browse files
committed
Do not discern between statements with and without semicolon after lowering to HIR
1 parent 374c63e commit dd884e0

File tree

19 files changed

+55
-146
lines changed

19 files changed

+55
-146
lines changed

src/librustc/cfg/construct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
106106
hir::StmtKind::Item(_) => {
107107
pred
108108
}
109-
hir::StmtKind::Expr(ref expr) |
110-
hir::StmtKind::Semi(ref expr) => {
109+
hir::StmtKind::Expr(ref expr) => {
111110
self.expr(&expr, pred)
112111
}
113112
};

src/librustc/hir/intravisit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
967967
match statement.node {
968968
StmtKind::Local(ref local) => visitor.visit_local(local),
969969
StmtKind::Item(item) => visitor.visit_nested_item(item),
970-
StmtKind::Expr(ref expression) |
971-
StmtKind::Semi(ref expression) => {
970+
StmtKind::Expr(ref expression) => {
972971
visitor.visit_expr(expression)
973972
}
974973
}

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,12 +4902,11 @@ impl<'a> LoweringContext<'a> {
49024902

49034903
let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
49044904
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
4905-
let body_stmt = self.stmt(body.span, hir::StmtKind::Expr(body_expr));
49064905

49074906
let loop_block = P(self.block_all(
49084907
e.span,
4909-
hir_vec![next_let, match_stmt, pat_let, body_stmt],
4910-
None,
4908+
hir_vec![next_let, match_stmt, pat_let],
4909+
Some(body_expr),
49114910
));
49124911

49134912
// `[opt_ident]: loop { ... }`
@@ -5110,20 +5109,13 @@ impl<'a> LoweringContext<'a> {
51105109
})
51115110
.collect();
51125111
}
5113-
StmtKind::Expr(ref e) => {
5112+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => {
51145113
hir::Stmt {
51155114
hir_id: self.lower_node_id(s.id),
51165115
node: hir::StmtKind::Expr(P(self.lower_expr(e))),
51175116
span: s.span,
51185117
}
51195118
},
5120-
StmtKind::Semi(ref e) => {
5121-
hir::Stmt {
5122-
hir_id: self.lower_node_id(s.id),
5123-
node: hir::StmtKind::Semi(P(self.lower_expr(e))),
5124-
span: s.span,
5125-
}
5126-
},
51275119
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
51285120
}]
51295121
}

src/librustc/hir/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,20 +1205,16 @@ pub enum StmtKind {
12051205
/// An item binding.
12061206
Item(ItemId),
12071207

1208-
/// An expression without a trailing semi-colon (must have unit type).
1208+
/// An expression statement.
12091209
Expr(P<Expr>),
1210-
1211-
/// An expression with a trailing semi-colon (may have any type).
1212-
Semi(P<Expr>),
12131210
}
12141211

12151212
impl StmtKind {
12161213
pub fn attrs(&self) -> &[Attribute] {
12171214
match *self {
12181215
StmtKind::Local(ref l) => &l.attrs,
12191216
StmtKind::Item(_) => &[],
1220-
StmtKind::Expr(ref e) |
1221-
StmtKind::Semi(ref e) => &e.attrs,
1217+
StmtKind::Expr(ref e) => &e.attrs,
12221218
}
12231219
}
12241220
}

src/librustc/hir/print.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -992,23 +992,17 @@ impl<'a> State<'a> {
992992
match st.node {
993993
hir::StmtKind::Local(ref loc) => {
994994
self.print_local(loc.init.deref(), |this| this.print_local_decl(&loc))?;
995+
self.s.word(";")?;
995996
}
996997
hir::StmtKind::Item(item) => {
997998
self.ann.nested(self, Nested::Item(item))?
998999
}
9991000
hir::StmtKind::Expr(ref expr) => {
10001001
self.space_if_not_bol()?;
10011002
self.print_expr(&expr)?;
1002-
}
1003-
hir::StmtKind::Semi(ref expr) => {
1004-
self.space_if_not_bol()?;
1005-
self.print_expr(&expr)?;
10061003
self.s.word(";")?;
10071004
}
10081005
}
1009-
if stmt_ends_with_semi(&st.node) {
1010-
self.s.word(";")?;
1011-
}
10121006
self.maybe_print_trailing_comment(st.span, None)
10131007
}
10141008

@@ -2325,36 +2319,6 @@ impl<'a> State<'a> {
23252319
}
23262320
}
23272321

2328-
// Dup'ed from parse::classify, but adapted for the HIR.
2329-
/// Does this expression require a semicolon to be treated
2330-
/// as a statement? The negation of this: 'can this expression
2331-
/// be used as a statement without a semicolon' -- is used
2332-
/// as an early-bail-out in the parser so that, for instance,
2333-
/// if true {...} else {...}
2334-
/// |x| 5
2335-
/// isn't parsed as (if true {...} else {...} | x) | 5
2336-
fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool {
2337-
match e.node {
2338-
hir::ExprKind::Match(..) |
2339-
hir::ExprKind::Block(..) |
2340-
hir::ExprKind::While(..) |
2341-
hir::ExprKind::Loop(..) => false,
2342-
_ => true,
2343-
}
2344-
}
2345-
2346-
/// this statement requires a semicolon after it.
2347-
/// note that in one case (stmt_semi), we've already
2348-
/// seen the semicolon, and thus don't need another.
2349-
fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool {
2350-
match *stmt {
2351-
hir::StmtKind::Local(_) => true,
2352-
hir::StmtKind::Item(_) => false,
2353-
hir::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(&e),
2354-
hir::StmtKind::Semi(..) => false,
2355-
}
2356-
}
2357-
23582322
fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
23592323
use crate::hir::BinOpKind::*;
23602324
match op {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
603603
// only the fn body we were given.
604604
}
605605

606-
hir::StmtKind::Expr(ref expr) |
607-
hir::StmtKind::Semi(ref expr) => {
606+
hir::StmtKind::Expr(ref expr) => {
608607
self.consume_expr(&expr);
609608
}
610609
}

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10041004
self.define_bindings_in_pat(&local.pat, succ)
10051005
}
10061006
hir::StmtKind::Item(..) => succ,
1007-
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {
1007+
hir::StmtKind::Expr(ref expr) => {
10081008
self.propagate_through_expr(&expr, succ)
10091009
}
10101010
}

src/librustc/middle/region.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
804804
);
805805
visitor.cx.var_parent = visitor.cx.parent;
806806
}
807-
hir::StmtKind::Expr(..) |
808-
hir::StmtKind::Semi(..) => {}
807+
hir::StmtKind::Expr(..) => {}
809808
}
810809
visitor.visit_stmt(statement)
811810
}

src/librustc_lint/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);
3939
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
4040
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
4141
let expr = match s.node {
42-
hir::StmtKind::Semi(ref expr) => &**expr,
42+
hir::StmtKind::Expr(ref expr) => &**expr,
4343
_ => return,
4444
};
4545

@@ -227,7 +227,7 @@ declare_lint_pass!(PathStatements => [PATH_STATEMENTS]);
227227

228228
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
229229
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
230-
if let hir::StmtKind::Semi(ref expr) = s.node {
230+
if let hir::StmtKind::Expr(ref expr) = s.node {
231231
if let hir::ExprKind::Path(_) = expr.node {
232232
cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect");
233233
}

src/librustc_mir/hair/cx/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ fn mirror_stmts<'a, 'tcx>(
5151
let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id);
5252
let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id));
5353
match stmt.node {
54-
hir::StmtKind::Expr(ref expr) |
55-
hir::StmtKind::Semi(ref expr) => {
54+
hir::StmtKind::Expr(ref expr) => {
5655
result.push(StmtRef::Mirror(Box::new(Stmt {
5756
kind: StmtKind::Expr {
5857
scope: region::Scope {

0 commit comments

Comments
 (0)