Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5a02f69

Browse files
committed
Fix using wrong length for max_len arg
1 parent 0ed9a5f commit 5a02f69

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/tools/rust-analyzer/crates/hir-def/src/find_path.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn calculate_best_path(
381381
visited_modules,
382382
info.container,
383383
true,
384-
best_choice.as_ref().map_or(max_len, |it| it.path_len) - 1,
384+
best_choice.as_ref().map_or(max_len, |it| it.path.len()) - 1,
385385
);
386386
let Some(mut choice) = choice else {
387387
continue;
@@ -450,6 +450,11 @@ fn calculate_best_path_local(
450450
item: ItemInNs,
451451
max_len: usize,
452452
) -> Option<Choice> {
453+
if max_len <= 1 {
454+
// recursive base case, we can't find a path prefix of length 0, one segment is occupied by
455+
// the item's name itself.
456+
return None;
457+
}
453458
let mut best_choice = None::<Choice>;
454459
// FIXME: cache the `find_local_import_locations` output?
455460
find_local_import_locations(ctx.db, item, ctx.from, ctx.from_def_map, |name, module_id| {
@@ -463,7 +468,7 @@ fn calculate_best_path_local(
463468
visited_modules,
464469
module_id,
465470
false,
466-
best_choice.as_ref().map_or(max_len, |it| it.path_len) - 1,
471+
best_choice.as_ref().map_or(max_len, |it| it.path.len()) - 1,
467472
) {
468473
best_choice = Some(match best_choice.take() {
469474
Some(best_choice) => best_choice.select(path, name.clone()),

0 commit comments

Comments
 (0)