mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Merge #11145
11145: feat: add config to use reasonable default expression instead of todo! when filling missing fields r=Veykril a=bnjjj Use `Default::default()` in struct fields when we ask to fill it instead of putting `todo!()` for every fields before: ```rust pub enum Other { One, Two, } pub struct Test { text: String, num: usize, other: Other, } fn t_test() { let test = Test {<|>}; } ``` after: ```rust pub enum Other { One, Two, } pub struct Test { text: String, num: usize, other: Other, } fn t_test() { let test = Test { text: String::new(), num: 0, other: todo!(), }; } ``` Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
This commit is contained in:
commit
40009e07d0
11 changed files with 271 additions and 25 deletions
|
@ -59,6 +59,28 @@ pub mod ext {
|
|||
pub fn expr_todo() -> ast::Expr {
|
||||
expr_from_text("todo!()")
|
||||
}
|
||||
pub fn expr_ty_default(ty: &ast::Type) -> ast::Expr {
|
||||
expr_from_text(&format!("{}::default()", ty))
|
||||
}
|
||||
pub fn expr_ty_new(ty: &ast::Type) -> ast::Expr {
|
||||
expr_from_text(&format!("{}::new()", ty))
|
||||
}
|
||||
|
||||
pub fn zero_number() -> ast::Expr {
|
||||
expr_from_text("0")
|
||||
}
|
||||
pub fn zero_float() -> ast::Expr {
|
||||
expr_from_text("0.0")
|
||||
}
|
||||
pub fn empty_str() -> ast::Expr {
|
||||
expr_from_text(r#""""#)
|
||||
}
|
||||
pub fn empty_char() -> ast::Expr {
|
||||
expr_from_text("'\x00'")
|
||||
}
|
||||
pub fn default_bool() -> ast::Expr {
|
||||
expr_from_text("false")
|
||||
}
|
||||
pub fn empty_block_expr() -> ast::BlockExpr {
|
||||
block_expr(None, None)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue