From cc7fe32ba3555845342f6ccebdc7167739be7b56 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 27 Feb 2024 09:35:57 +0100 Subject: [PATCH] fix: Fix completions panicking with certain macro setups --- Cargo.toml | 4 ++++ crates/hir-ty/src/method_resolution.rs | 5 +++-- crates/hir/src/semantics.rs | 6 ++++-- crates/ide-completion/src/context/analysis.rs | 1 + xtask/src/flags.rs | 5 ++++- xtask/src/install.rs | 4 +++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49c7d369190e..90e591432792 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,10 @@ incremental = true # Set this to 1 or 2 to get more useful backtraces in debugger. debug = 0 +[profile.dev-rel] +inherits = "release" +debug = 2 + [patch.'crates-io'] # rowan = { path = "../rowan" } diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index 4bb412d01c28..ad62aee22e51 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -1148,7 +1148,6 @@ fn iterate_trait_method_candidates( ) -> ControlFlow<()> { let db = table.db; let env = table.trait_env.clone(); - let self_is_array = matches!(self_ty.kind(Interner), chalk_ir::TyKind::Array(..)); let canonical_self_ty = table.canonicalize(self_ty.clone()).value; @@ -1160,7 +1159,9 @@ fn iterate_trait_method_candidates( // 2021. // This is to make `[a].into_iter()` not break code with the new `IntoIterator` impl for // arrays. - if data.skip_array_during_method_dispatch && self_is_array { + if data.skip_array_during_method_dispatch + && matches!(self_ty.kind(Interner), chalk_ir::TyKind::Array(..)) + { // FIXME: this should really be using the edition of the method name's span, in case it // comes from a macro if db.crate_graph()[env.krate].edition < Edition::Edition2021 { diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index a869029d0966..1fb6570b6a40 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -969,8 +969,10 @@ impl<'db> SemanticsImpl<'db> { match value.parent() { Some(parent) => Some(InFile::new(file_id, parent)), None => { - self.cache(value.clone(), file_id); - Some(file_id.macro_file()?.call_node(db)) + let call_node = file_id.macro_file()?.call_node(db); + // cache the node + self.parse_or_expand(call_node.file_id); + Some(call_node) } } }) diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index 92af68897783..79c503e0a10d 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -963,6 +963,7 @@ fn classify_name_ref( match find_node_in_file_compensated(sema, original_file, &expr) { Some(it) => { + // buggy let innermost_ret_ty = sema .ancestors_with_macros(it.syntax().clone()) .find_map(find_ret_ty) diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index 99bb12896f10..e234090a07ce 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs @@ -23,6 +23,8 @@ xflags::xflags! { optional --mimalloc /// Use jemalloc allocator for server optional --jemalloc + /// build in release with debug info set to 2 + optional --dev-rel } cmd fuzz-tests {} @@ -80,6 +82,7 @@ pub struct Install { pub server: bool, pub mimalloc: bool, pub jemalloc: bool, + pub dev_rel: bool, } #[derive(Debug)] @@ -187,7 +190,7 @@ impl Install { } else { Malloc::System }; - Some(ServerOpt { malloc }) + Some(ServerOpt { malloc, dev_rel: self.dev_rel }) } pub(crate) fn client(&self) -> Option { if !self.client && self.server { diff --git a/xtask/src/install.rs b/xtask/src/install.rs index dadee204d1ac..dc932da80c26 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs @@ -31,6 +31,7 @@ const VS_CODES: &[&str] = &["code", "code-exploration", "code-insiders", "codium pub(crate) struct ServerOpt { pub(crate) malloc: Malloc, + pub(crate) dev_rel: bool, } pub(crate) enum Malloc { @@ -135,8 +136,9 @@ fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> { Malloc::Mimalloc => &["--features", "mimalloc"], Malloc::Jemalloc => &["--features", "jemalloc"], }; + let profile = if opts.dev_rel { "dev-rel" } else { "release" }; - let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --locked --force --features force-always-assert {features...}"); + let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --profile={profile} --locked --force --features force-always-assert {features...}"); cmd.run()?; Ok(()) }