Fixed statement bodies
This commit is contained in:
@@ -103,7 +103,7 @@ impl GenRust for Expression {
|
|||||||
if ensure_semicolon {
|
if ensure_semicolon {
|
||||||
ctx.expr_ensure_semicolon = true;
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
|
||||||
if !self.is_soft_return() {
|
if !self.is_block() {
|
||||||
cg.add(";");
|
cg.add(";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,10 +95,14 @@ impl RustCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_brackets_body(&mut self, ctx: &mut Context, expr: &StatementBody) {
|
pub fn ensure_brackets_body(&mut self, ctx: &mut Context, body: &StatementBody) {
|
||||||
match expr {
|
match body {
|
||||||
StatementBody::Statement(expr) => self.ensure_brackets_expr(ctx, expr),
|
|
||||||
StatementBody::Expression(expr) => self.ensure_brackets_expr(ctx, expr),
|
StatementBody::Expression(expr) => self.ensure_brackets_expr(ctx, expr),
|
||||||
|
|
||||||
|
StatementBody::Statement(expr) => {
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
|
self.ensure_brackets_expr(ctx, expr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ impl GenRust for StatementBody {
|
|||||||
match self {
|
match self {
|
||||||
Self::Expression(expr) => expr.gen_rust(ctx, cg),
|
Self::Expression(expr) => expr.gen_rust(ctx, cg),
|
||||||
Self::Statement(stmt) => {
|
Self::Statement(stmt) => {
|
||||||
|
ctx.expr_ensure_semicolon = true;
|
||||||
stmt.gen_rust(ctx, cg);
|
stmt.gen_rust(ctx, cg);
|
||||||
cg.add(";");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,9 +84,9 @@ pub enum Generic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Expression {
|
impl Expression {
|
||||||
pub fn is_soft_return(&self) -> bool {
|
pub fn is_block(&self) -> bool {
|
||||||
if let Expression::Statement(stmt) = self {
|
if let Expression::Statement(stmt) = self {
|
||||||
stmt.is_soft_return()
|
stmt.is_block()
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,28 +64,15 @@ pub struct StatementBranch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Statement {
|
impl Statement {
|
||||||
pub fn is_soft_return(&self) -> bool {
|
pub fn is_block(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Block(_) | Self::Match(_, _) => true,
|
Self::Block(_)
|
||||||
Self::While(branch) => branch.body.is_soft_return(),
|
| Self::Match(_, _)
|
||||||
Self::For { body, .. } | Self::Loop(body) | Self::CStyleFor { body, .. } => {
|
| Self::While(_)
|
||||||
body.is_soft_return()
|
| Self::For { .. }
|
||||||
}
|
| Self::Loop(..)
|
||||||
Self::If {
|
| Self::CStyleFor { .. }
|
||||||
initial,
|
| Self::If { .. } => true,
|
||||||
else_if,
|
|
||||||
else_branch,
|
|
||||||
} => {
|
|
||||||
else_branch
|
|
||||||
.as_ref()
|
|
||||||
.map(|v| v.is_soft_return())
|
|
||||||
.unwrap_or_default()
|
|
||||||
|| else_if
|
|
||||||
.last()
|
|
||||||
.map(|b| b.body.is_soft_return())
|
|
||||||
.unwrap_or_default()
|
|
||||||
|| initial.body.is_soft_return()
|
|
||||||
}
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ void main() {
|
|||||||
void do_stuff() {
|
void do_stuff() {
|
||||||
vec!(1, 2, 3).into_iter().map(Option<i32> |var v| {Some(v)}).collect::<Vec<_>>();
|
vec!(1, 2, 3).into_iter().map(Option<i32> |var v| {Some(v)}).collect::<Vec<_>>();
|
||||||
|
|
||||||
if (43=69) testing1();
|
if (43==69) testing1();
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 testing1() {
|
i32 testing1() {
|
||||||
|
|||||||
Reference in New Issue
Block a user