internal: use more mutable APIs

This commit is contained in:
Aleksey Kladov 2021-05-14 20:00:35 +03:00
parent 6c21d04307
commit 883dd1568f
3 changed files with 33 additions and 53 deletions

View file

@ -330,6 +330,22 @@ impl ast::AssocItemList {
}
}
impl ast::Fn {
pub fn get_or_create_body(&self) -> ast::BlockExpr {
if self.body().is_none() {
let body = make::ext::empty_block_expr().clone_for_update();
match self.semicolon_token() {
Some(semi) => {
ted::replace(semi, body.syntax());
ted::insert(Position::before(body.syntax), make::tokens::single_space());
}
None => ted::append_child(self.syntax(), body.syntax()),
}
}
self.body().unwrap()
}
}
#[cfg(test)]
mod tests {
use std::fmt;