From 6027eae51ed6825fc7f32e665df557bccbc37a93 Mon Sep 17 00:00:00 2001 From: Wyatt Herkamp Date: Tue, 5 Mar 2024 08:34:52 -0500 Subject: [PATCH] Fix Tests + Fix Warnings --- .../src/handlers/unresolved_field.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/ide-diagnostics/src/handlers/unresolved_field.rs b/crates/ide-diagnostics/src/handlers/unresolved_field.rs index be78761f169..cffee7ffd4f 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_field.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_field.rs @@ -50,13 +50,11 @@ pub(crate) fn unresolved_field( } fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option> { - if d.method_with_same_name_exists { - let mut method_fix = method_fix(ctx, &d.expr).unwrap_or_default(); - method_fix.push(add_field_fix(ctx, d)?); - Some(method_fix) - } else { - Some(vec![add_field_fix(ctx, d)?]) + let mut fixes = if d.method_with_same_name_exists { method_fix(ctx, &d.expr) } else { None }; + if let Some(fix) = add_field_fix(ctx, d) { + fixes.get_or_insert_with(Vec::new).push(fix); } + fixes } fn add_field_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Option { @@ -77,7 +75,7 @@ fn add_field_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Opti if let Some(new_field_type) = ctx.sema.type_of_expr(&expr).map(|v| v.adjusted()) { let display = new_field_type.display_source_code(ctx.sema.db, target_module.into(), true).ok(); - make::ty(display.as_deref().unwrap_or_else(|| "()")) + make::ty(display.as_deref().unwrap_or("()")) } else { make::ty("()") }; @@ -106,7 +104,7 @@ fn add_field_fix(ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedField) -> Opti } None => { // Empty Struct. Add a field right before the closing brace - let indent = IndentLevel::from_node(&adt_syntax.value) + 1; + let indent = IndentLevel::from_node(adt_syntax.value) + 1; let record_field_list = adt_syntax.value.children().find(|v| v.kind() == SyntaxKind::RECORD_FIELD_LIST)?; let offset = record_field_list.first_token().map(|f| f.text_range().end())?;