From 4bf6b160a90721aa5c11c6306ae4b1144afff4c6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 31 Jan 2024 10:34:40 +0100 Subject: [PATCH 1/3] Fix incorrect range uses in missing_fields quick fixes --- .../src/handlers/missing_fields.rs | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index 37ac912f064..feaf1aa7278 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -13,7 +13,7 @@ ast::{self, make}, AstNode, SyntaxNode, SyntaxNodePtr, }; -use text_edit::TextEdit; +use text_edit::{TextEdit, TextRange}; use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext}; @@ -59,9 +59,15 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option, d: &hir::MissingFields) -> Option, d: &hir::MissingFields) -> Option, d: &hir::MissingFields) -> Option { let missing_fields = ctx.sema.record_pattern_missing_fields(field_list_parent); @@ -160,11 +161,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option Date: Wed, 31 Jan 2024 10:54:52 +0100 Subject: [PATCH 2/3] Better error message for when proc-macros have not yet been built --- .../ide-diagnostics/src/handlers/unresolved_proc_macro.rs | 2 +- crates/rust-analyzer/src/reload.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/ide-diagnostics/src/handlers/unresolved_proc_macro.rs b/crates/ide-diagnostics/src/handlers/unresolved_proc_macro.rs index 015a3d6b2ce..340f77feea8 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_proc_macro.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_proc_macro.rs @@ -32,7 +32,7 @@ pub(crate) fn unresolved_proc_macro( let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning }; let def_map = ctx.sema.db.crate_def_map(d.krate); let message = if config_enabled { - def_map.proc_macro_loading_error().unwrap_or("proc macro not found in the built dylib") + def_map.proc_macro_loading_error().unwrap_or("internal error") } else { match d.kind { hir::MacroKind::Attr if proc_macros_enabled => "attribute macro expansion is disabled", diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 2a0478d62f5..dcf6089ca7b 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -528,10 +528,16 @@ fn recreate_crate_graph(&mut self, cause: String) { (crate_graph, proc_macros, crate_graph_file_dependencies) }; + let mut change = Change::new(); if self.config.expand_proc_macros() { + change.set_proc_macros( + crate_graph + .iter() + .map(|id| (id, Err("Proc-macros have not been built yet".to_owned()))) + .collect(), + ); self.fetch_proc_macros_queue.request_op(cause, proc_macro_paths); } - let mut change = Change::new(); change.set_crate_graph(crate_graph); self.analysis_host.apply_change(change); self.crate_graph_file_dependencies = crate_graph_file_dependencies; From 545382db2532801bd6fb05532d71114f8fb509fd Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 8 Feb 2024 14:54:52 +0100 Subject: [PATCH 3/3] Fix warnings --- crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs | 2 +- crates/ide-diagnostics/src/handlers/missing_fields.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index 51be8960b8c..712842372b6 100644 --- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -359,7 +359,7 @@ fn ctor_sub_tys<'a>( &'a self, ctor: &'a rustc_pattern_analysis::constructor::Constructor, ty: &'a Self::Ty, - ) -> impl Iterator + ExactSizeIterator + Captures<'a> { + ) -> impl ExactSizeIterator + Captures<'a> { let single = |ty| smallvec![ty]; let tys: SmallVec<[_; 2]> = match ctor { Struct | Variant(_) | UnionField => match ty.kind(Interner) { diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index feaf1aa7278..3bc043c8fc6 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -13,7 +13,7 @@ ast::{self, make}, AstNode, SyntaxNode, SyntaxNodePtr, }; -use text_edit::{TextEdit, TextRange}; +use text_edit::TextEdit; use crate::{fix, Diagnostic, DiagnosticCode, DiagnosticsContext};