mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-01 16:17:29 +00:00
Merge #10546
10546: feat: Implement promote_local_to_const assist r=Veykril a=Veykril Fixes #7692, that is now one can invoke the `extract_variable` assist on something and then follow that up with this assist to turn it into a const. bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
0af9d1fc8a
6 changed files with 280 additions and 11 deletions
|
@ -580,6 +580,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