Repository: aptos-labs/aptos-core
File: third_party/move/move-compiler-v2/legacy-move-compiler/src/parser/syntax.rs (Rust)

Code before:
                _ => return Err(unexpected_token_error(context.tokens, "';'")),
            }
            break;
        }
        seq.push(item);

        // Check if semicolon can be optional for expressions that end with blocks
        let semicolon_optional = match &seq.last() {
            Some(last_item) => match &last_item.value {
                SequenceItem_::Seq(e) => exp_ends_with_block(e),
                _ => false,
            },
            None => false,
        };

        if semicolon_optional {
            // Semicolon is optional after block expressions
            if context.tokens.peek() == Tok::Semicolon {
                last_semicolon_loc = Some(current_token_loc(context.tokens));
                context.tokens.advance()?;
            }
        } else {
            // Semicolon is required
            last_semicolon_loc = Some(current_token_loc(context.tokens));
            consume_token(context.tokens, Tok::Semicolon)?;
        }
    }
    context.tokens.advance()?; // consume the RBrace
    Ok((uses, seq, last_semicolon_loc, Box::new(eopt)))
}

//**************************************************************************************************
// Expressions
//**************************************************************************************************

// Parse an expression term:
//      Term =
//          "break"
//          | "continue"
//          | "vector" ('<' Comma<Type> ">")? "[" Comma<Exp> "]"
//          | <Value>
//          | "(" Comma<Exp> ")"
//          | "(" <Exp> ":" <Type> ")"
//          | "(" <Exp> "as" <Type> ")"
//          | "{" <Sequence>
//          | "if" "(" <Exp> ")" <Exp> "else" "{" <Exp> "}"
//          | "if" "(" <Exp> ")" "{" <Exp> "}"
//          | "if" "(" <Exp> ")" <Exp> ("else" <Exp>)?
//          | "while" "(" <Exp> ")" "{" <Exp> "}"
//          | "while" "(" <Exp> ")" <Exp> (SpecBlock)?
//          | "loop" <Exp>

Review comment (suggestion):
nit: this can be simplified:

```suggestion
        if !semicolon_optional || context.tokens.peek() == Tok::Semicolon {
            last_semicolon_loc = Some(current_token_loc(context.tokens));
            consume_token(context.tokens, Tok::Semicolon)?;
        }
```


Code after:
                _ => return Err(unexpected_token_error(context.tokens, "';'")),
            }
            break;
        }
        seq.push(item);

        // Check if semicolon can be optional for expressions that end with `}`.
        let semicolon_optional = match &seq.last() {
            Some(last_item) => match &last_item.value {
                SequenceItem_::Seq(e) => exp_ends_with_rbrace(e),
                _ => false,
            },
            None => false,
        };

        if semicolon_optional {
            // Semicolon is optional after expressions that end with `}`.
            if context.tokens.peek() == Tok::Semicolon {
                last_semicolon_loc = Some(current_token_loc(context.tokens));
                context.tokens.advance()?;
            }
        } else {
            // Semicolon is required
            last_semicolon_loc = Some(current_token_loc(context.tokens));
            consume_token(context.tokens, Tok::Semicolon)?;
        }
    }
    context.tokens.advance()?; // consume the RBrace
    Ok((uses, seq, last_semicolon_loc, Box::new(eopt)))
}

//**************************************************************************************************
// Expressions
//**************************************************************************************************

// Parse an expression term:
//      Term =
//          "break"
//          | "continue"
//          | "vector" ('<' Comma<Type> ">")? "[" Comma<Exp> "]"
//          | <Value>
//          | "(" Comma<Exp> ")"
//          | "(" <Exp> ":" <Type> ")"
//          | "(" <Exp> "as" <Type> ")"
//          | "{" <Sequence>
//          | "if" "(" <Exp> ")" <Exp> "else" "{" <Exp> "}"
//          | "if" "(" <Exp> ")" "{" <Exp> "}"
//          | "if" "(" <Exp> ")" <Exp> ("else" <Exp>)?
//          | "while" "(" <Exp> ")" "{" <Exp> "}"
//          | "while" "(" <Exp> ")" <Exp> (SpecBlock)?
//          | "loop" <Exp>