Unnamed repository; edit this file 'description' to name the repository.
fix: Fix completions panicking with certain macro setups
Lukas Wirth 2024-02-27
parent 5fead60 · commit cc7fe32
-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 49c7d36919..90e5914327 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 4bb412d01c..ad62aee22e 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 a869029d09..1fb6570b6a 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 92af688977..79c503e0a1 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 99bb12896f..e234090a07 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 dadee204d1..dc932da80c 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(())
}