Skip to content

Commit 9cf4b36

Browse files
committed
use None and Some(_) in Stmt::Expr() convension from syn1 to syn2 to match the existing behavior
1 parent 6cf66c4 commit 9cf4b36

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

c2rust-transpile/src/cfg/inc_cleanup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl IncCleanup {
3333

3434
let mut removed_tail_expr = false;
3535

36-
if let Stmt::Expr(expr, _) = &mut stmt {
36+
if let Stmt::Expr(expr, None) = &mut stmt {
3737
match expr {
3838
Expr::If(ExprIf {
3939
cond: _,
@@ -74,7 +74,7 @@ impl IncCleanup {
7474
}
7575

7676
fn is_idempotent_tail_expr(&self, stmt: &Stmt) -> bool {
77-
let tail_expr = if let Stmt::Expr(expr, _token) = stmt {
77+
let tail_expr = if let Stmt::Expr(expr, Some(_token)) = stmt {
7878
expr
7979
} else {
8080
return false;
@@ -151,7 +151,7 @@ fn cleanup_if(stmt: Stmt) -> Stmt {
151151
);
152152
} else if block.stmts.len() == 1 {
153153
// flatten nested if expression to else if chain
154-
if let Stmt::Expr(Expr::If(nested_if_expr), _semi) = &block.stmts[0] {
154+
if let Stmt::Expr(Expr::If(nested_if_expr), None) = &block.stmts[0] {
155155
return Stmt::Expr(
156156
Expr::If(ExprIf {
157157
cond: cond.clone(),

c2rust-transpile/src/cfg/structures.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl StructureState {
530530
}
531531
(false, false) => {
532532
fn is_expr(kind: &Stmt) -> bool {
533-
matches!(kind, Stmt::Expr(Expr::If(..) | Expr::Block(..), _semi))
533+
matches!(kind, Stmt::Expr(Expr::If(..) | Expr::Block(..), None))
534534
}
535535

536536
// Do the else statements contain a single If, IfLet or
@@ -542,7 +542,7 @@ impl StructureState {
542542
let stmt_expr = els_stmts.swap_remove(0);
543543
let stmt_expr_span = stmt_expr.span();
544544
let mut els_expr = match stmt_expr {
545-
Stmt::Expr(e, _semi) => e,
545+
Stmt::Expr(e, None) => e,
546546
_ => panic!("is_els_expr out of sync"),
547547
};
548548
els_expr.set_span(stmt_expr_span);
@@ -605,7 +605,7 @@ impl StructureState {
605605
let (body, body_span) = self.to_stmt(*body, comment_store);
606606

607607
// TODO: this is ugly but it needn't be. We are just pattern matching on particular ASTs.
608-
if let Some(stmt @ &Stmt::Expr(ref expr, _semi)) = body.first() {
608+
if let Some(stmt @ &Stmt::Expr(ref expr, None)) = body.first() {
609609
let stmt_span = stmt.span();
610610
let span = if !stmt_span.is_dummy() {
611611
stmt_span
@@ -625,7 +625,7 @@ impl StructureState {
625625
expr: None,
626626
..
627627
}),
628-
_token,
628+
Some(_),
629629
)] = then_branch.stmts.as_slice()
630630
{
631631
let e = mk().while_expr(

c2rust-transpile/src/translator/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ pub fn stmts_block(mut stmts: Vec<Stmt>) -> Block {
357357
Expr::Block(ExprBlock {
358358
block, label: None, ..
359359
}),
360-
_semi,
360+
None,
361361
)) if stmts.is_empty() => return block,
362362
Some(mut s) => {
363-
if let Stmt::Expr(e, _semi) = s {
364-
s = Stmt::Expr(e, _semi);
363+
if let Stmt::Expr(e, None) = s {
364+
s = Stmt::Expr(e, Some(Default::default()));
365365
}
366366
stmts.push(s);
367367
}
@@ -4025,7 +4025,7 @@ impl<'c> Translation<'c> {
40254025
expr: ret_val,
40264026
..
40274027
}),
4028-
_,
4028+
Some(_),
40294029
) = stmt
40304030
{
40314031
if blbl.ident == mk().label(lbl.pretty_print()).name.ident {

c2rust-transpile/src/translator/structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl<'a> Translation<'a> {
755755
}
756756

757757
let last_expr = match block.stmts[last] {
758-
Stmt::Expr(ref expr, _semi) => expr.clone(),
758+
Stmt::Expr(ref expr, None) => expr.clone(),
759759
_ => return Err(TranslationError::generic("Expected Expr Stmt")),
760760
};
761761
let method_call =

0 commit comments

Comments
 (0)