about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-27 08:39:34 +0000
committerbors <bors@rust-lang.org>2024-02-27 08:39:34 +0000
commitd4d9d0c85af7b796bee78e6bac9f908e0fcc5adf (patch)
tree320fac81ef5fa0900adcaef08bd0669a50738318
parent5fead606bc88d9ed3cb1109bea9c1cb1c42b4ac0 (diff)
parentcc7fe32ba3555845342f6ccebdc7167739be7b56 (diff)
downloadrust-d4d9d0c85af7b796bee78e6bac9f908e0fcc5adf.tar.gz
rust-d4d9d0c85af7b796bee78e6bac9f908e0fcc5adf.zip
Auto merge of #16691 - Veykril:completion-analysis-panic, r=Veykril
fix: Fix completions panicking with certain macro setups

Unable to figure out a test case for this but managed to run into it in r-a reproducably.

Fixes https://github.com/rust-lang/rust-analyzer/issues/16266 Fixes https://github.com/rust-lang/rust-analyzer/issues/13255
-rw-r--r--Cargo.toml4
-rw-r--r--crates/hir-ty/src/method_resolution.rs5
-rw-r--r--crates/hir/src/semantics.rs6
-rw-r--r--crates/ide-completion/src/context/analysis.rs1
-rw-r--r--xtask/src/flags.rs5
-rw-r--r--xtask/src/install.rs4
6 files changed, 19 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 49c7d369190..90e59143279 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 4bb412d01c2..ad62aee22e5 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 a869029d096..1fb6570b6a4 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 92af6889778..79c503e0a10 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 99bb12896f1..e234090a07c 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<ClientOpt> {
         if !self.client && self.server {
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index dadee204d1a..dc932da80c2 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(())
 }