/// For modules, we want to capture the "last" statement in the code,
/// if it was an expression. Rather than keep track of the value of every
/// expression, instead add a fake return at the end if the final statement
/// is an expression.
For modules, we want to capture the "last" statement in the code,
if it was an expression. Rather than keep track of the value of every
expression, instead add a fake return at the end if the final statement
is an expression.
For modules we want to capture the " last " statement in the code if it was an expression . Rather than keep track of the value of every expression instead add a fake return at the end if the final statement is an expression .
fn inject_return(x: &mut AstStmt) {
    match &mut x.node {
        Stmt::Statements(xs) => {
            if let Some(x) = xs.last_mut() {
                inject_return(x)
            }
        }
        Stmt::Expression(e) => {
            let e = mem::replace(
                e,
                Spanned {
                    node: Expr::Tuple(Vec::new()),
                    span: Span::default(),
                },
            );
            x.node = Stmt::Return(Some(e));
        }
        _ => {}
    }
}
fn inject_return ( x : & mut AstStmt ) { match & mut x . node { Stmt :: Statements ( xs ) => { if let Some ( x ) = xs . last_mut ( ) { inject_return ( x ) } } Stmt :: Expression ( e ) => { let e = mem :: replace ( e , Spanned { node : Expr :: Tuple ( Vec :: new ( ) ) , span : Span :: default ( ) , } , ) ; x . node = Stmt :: Return ( Some ( e ) ) ; } _ => { } } }
For modules, we want to capture the "last" statement in the code,
if it was an expression.
For modules we want to capture the " last " statement in the code if it was an expression .
x
&mut AstStmt