From 0435463439471a81477ccdc0313f312abb14331e Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Thu, 30 Dec 2021 15:49:31 +0100 Subject: [PATCH] feat(diagnostics): use Default::default() expression instead of todo! when missing fields Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- .../src/handlers/missing_fields.rs | 21 +++++++++++++++---- crates/syntax/src/ast/make.rs | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/ide_diagnostics/src/handlers/missing_fields.rs b/crates/ide_diagnostics/src/handlers/missing_fields.rs index 8d17a7e714a..715ac8f9740 100644 --- a/crates/ide_diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide_diagnostics/src/handlers/missing_fields.rs @@ -1,6 +1,6 @@ use either::Either; -use hir::{db::AstDatabase, InFile}; -use ide_db::{assists::Assist, source_change::SourceChange}; +use hir::{db::AstDatabase, InFile, Type}; +use ide_db::{assists::Assist, helpers::FamousDefs, source_change::SourceChange}; use rustc_hash::FxHashMap; use stdx::format_to; use syntax::{algo, ast::make, AstNode, SyntaxNodePtr}; @@ -63,6 +63,19 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option { + Some(make::ext::expr_default()) + } + _ => Some(make::ext::expr_todo()), + } + }; + for (f, ty) in missing_fields.iter() { let field_expr = if let Some(local_candidate) = locals.get(&f.name(ctx.sema.db)) { cov_mark::hit!(field_shorthand); @@ -70,10 +83,10 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option ast::Expr { expr_from_text("todo!()") } + pub fn expr_default() -> ast::Expr { + expr_from_text("Default::default()") + } pub fn empty_block_expr() -> ast::BlockExpr { block_expr(None, None) }