From ac505b21a8f3f1f03bfeed9209cfcf920c223852 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 15 Oct 2021 19:27:19 +0200 Subject: [PATCH] Fix missing_fields diagnostic fix replacing wrong text ranges --- .../src/handlers/missing_fields.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/ide_diagnostics/src/handlers/missing_fields.rs b/crates/ide_diagnostics/src/handlers/missing_fields.rs index d5b84715156..3d416591fe6 100644 --- a/crates/ide_diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide_diagnostics/src/handlers/missing_fields.rs @@ -54,6 +54,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option return None, }; let old_field_list = field_list_parent.record_expr_field_list()?; + let new_field_list = old_field_list.clone_for_update(); let mut locals = FxHashMap::default(); ctx.sema.scope(field_list_parent.syntax()).process_all_names(&mut |name, def| { @@ -80,11 +81,19 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option { $($tt)*}; } fn main() { - let _x = id![Foo { a: 42 }]; + let _x = id![Foo {a:42, b: todo!() }]; } pub struct Foo { pub a: i32, pub b: i32 }