Skip to content

Commit

Permalink
fix: Fix completions panicking with certain macro setups
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Feb 27, 2024
1 parent 5fead60 commit cc7fe32
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
5 changes: 3 additions & 2 deletions crates/hir-ty/src/method_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions crates/ide-completion/src/context/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion xtask/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -80,6 +82,7 @@ pub struct Install {
pub server: bool,
pub mimalloc: bool,
pub jemalloc: bool,
pub dev_rel: bool,
}

#[derive(Debug)]
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion xtask/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}

0 comments on commit cc7fe32

Please sign in to comment.