mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Implement promotoe_local_to_const assist
This commit is contained in:
parent
f87debcf87
commit
06286ee90b
6 changed files with 280 additions and 11 deletions
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue