Skip to content

Commit d4d9d0c

Browse files
committed
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 #16266 Fixes #13255
2 parents 5fead60 + cc7fe32 commit d4d9d0c

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ incremental = true
2828
# Set this to 1 or 2 to get more useful backtraces in debugger.
2929
debug = 0
3030

31+
[profile.dev-rel]
32+
inherits = "release"
33+
debug = 2
34+
3135
[patch.'crates-io']
3236
# rowan = { path = "../rowan" }
3337

crates/hir-ty/src/method_resolution.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ fn iterate_trait_method_candidates(
11481148
) -> ControlFlow<()> {
11491149
let db = table.db;
11501150
let env = table.trait_env.clone();
1151-
let self_is_array = matches!(self_ty.kind(Interner), chalk_ir::TyKind::Array(..));
11521151

11531152
let canonical_self_ty = table.canonicalize(self_ty.clone()).value;
11541153

@@ -1160,7 +1159,9 @@ fn iterate_trait_method_candidates(
11601159
// 2021.
11611160
// This is to make `[a].into_iter()` not break code with the new `IntoIterator` impl for
11621161
// arrays.
1163-
if data.skip_array_during_method_dispatch && self_is_array {
1162+
if data.skip_array_during_method_dispatch
1163+
&& matches!(self_ty.kind(Interner), chalk_ir::TyKind::Array(..))
1164+
{
11641165
// FIXME: this should really be using the edition of the method name's span, in case it
11651166
// comes from a macro
11661167
if db.crate_graph()[env.krate].edition < Edition::Edition2021 {

crates/hir/src/semantics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,10 @@ impl<'db> SemanticsImpl<'db> {
969969
match value.parent() {
970970
Some(parent) => Some(InFile::new(file_id, parent)),
971971
None => {
972-
self.cache(value.clone(), file_id);
973-
Some(file_id.macro_file()?.call_node(db))
972+
let call_node = file_id.macro_file()?.call_node(db);
973+
// cache the node
974+
self.parse_or_expand(call_node.file_id);
975+
Some(call_node)
974976
}
975977
}
976978
})

crates/ide-completion/src/context/analysis.rs

+1
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ fn classify_name_ref(
963963

964964
match find_node_in_file_compensated(sema, original_file, &expr) {
965965
Some(it) => {
966+
// buggy
966967
let innermost_ret_ty = sema
967968
.ancestors_with_macros(it.syntax().clone())
968969
.find_map(find_ret_ty)

xtask/src/flags.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ xflags::xflags! {
2323
optional --mimalloc
2424
/// Use jemalloc allocator for server
2525
optional --jemalloc
26+
/// build in release with debug info set to 2
27+
optional --dev-rel
2628
}
2729

2830
cmd fuzz-tests {}
@@ -80,6 +82,7 @@ pub struct Install {
8082
pub server: bool,
8183
pub mimalloc: bool,
8284
pub jemalloc: bool,
85+
pub dev_rel: bool,
8386
}
8487

8588
#[derive(Debug)]
@@ -187,7 +190,7 @@ impl Install {
187190
} else {
188191
Malloc::System
189192
};
190-
Some(ServerOpt { malloc })
193+
Some(ServerOpt { malloc, dev_rel: self.dev_rel })
191194
}
192195
pub(crate) fn client(&self) -> Option<ClientOpt> {
193196
if !self.client && self.server {

xtask/src/install.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const VS_CODES: &[&str] = &["code", "code-exploration", "code-insiders", "codium
3131

3232
pub(crate) struct ServerOpt {
3333
pub(crate) malloc: Malloc,
34+
pub(crate) dev_rel: bool,
3435
}
3536

3637
pub(crate) enum Malloc {
@@ -135,8 +136,9 @@ fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> {
135136
Malloc::Mimalloc => &["--features", "mimalloc"],
136137
Malloc::Jemalloc => &["--features", "jemalloc"],
137138
};
139+
let profile = if opts.dev_rel { "dev-rel" } else { "release" };
138140

139-
let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --locked --force --features force-always-assert {features...}");
141+
let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --profile={profile} --locked --force --features force-always-assert {features...}");
140142
cmd.run()?;
141143
Ok(())
142144
}

0 commit comments

Comments
 (0)