Implement promotoe_local_to_const assist

This commit is contained in:
Lukas Wirth 2021-10-14 21:49:46 +02:00
parent f87debcf87
commit 06286ee90b
6 changed files with 280 additions and 11 deletions

View file

@ -555,6 +555,19 @@ pub fn expr_stmt(expr: ast::Expr) -> ast::ExprStmt {
ast_from_text(&format!("fn f() {{ {}{} (); }}", expr, semi))
}
pub fn item_const(
visibility: Option<ast::Visibility>,
name: ast::Name,
ty: ast::Type,
expr: ast::Expr,
) -> ast::Const {
let visibility = match visibility {
None => String::new(),
Some(it) => format!("{} ", it),
};
ast_from_text(&format!("{} const {}: {} = {};", visibility, name, ty, expr))
}
pub fn param(pat: ast::Pat, ty: ast::Type) -> ast::Param {
ast_from_text(&format!("fn f({}: {}) {{ }}", pat, ty))
}