Fix crate-name import resolution for bin+lib crates

Register the Cargo package name (normalized - -> _) as an alias for
src/lib.rs in the resolver, so 'use <crate>::{...}' in src/main.rs
resolves to src/lib.rs. Adds rustdemo/Cargo.toml fixture and test
coverage; updates blast-radius test for the new transitive edge.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
endergebnisandCopilot committed 2026-09-04 03:07:47 +02:00
1 parent 0bb09da454
commit 6875998ab6
4 files changed
+64 -5

No files matched your search

+20 -2
View File
@@ -90,6 +90,22 @@ fn rust_index_search_and_dead() {
"source contains function body"
);
// `use rustdemo::add` in main.rs resolves via the package-name alias.
let importers = run_json(&[
"--project",
fx.to_str().unwrap(),
"find",
"importers",
"src/lib.rs",
]);
let names: Vec<&str> = importers
.as_array()
.unwrap()
.iter()
.map(|v| v.as_str().unwrap())
.collect();
assert!(names.contains(&"src/main.rs"), "main.rs imports lib.rs");
// dead.rs is flagged; entry points lib.rs/main.rs are not.
let dead = run_json(&["--project", fx.to_str().unwrap(), "find", "dead"]);
let paths: Vec<&str> = dead["files"]
@@ -118,7 +134,7 @@ fn inspect_blast_radius_finds_affected_files() {
"blast-radius",
"src/util.rs",
]);
assert_eq!(blast["count"], 1);
assert_eq!(blast["count"], 2);
assert_eq!(blast["file"], "src/util.rs");
let affected: Vec<&str> = blast["affected"]
.as_array()
@@ -126,7 +142,9 @@ fn inspect_blast_radius_finds_affected_files() {
.iter()
.map(|f| f["path"].as_str().unwrap())
.collect();
assert_eq!(affected, ["src/lib.rs"], "lib.rs imports util.rs");
// lib.rs imports util.rs directly; main.rs reaches it via the crate name.
assert!(affected.contains(&"src/lib.rs"), "lib.rs imports util.rs");
assert!(affected.contains(&"src/main.rs"), "main.rs → lib.rs → util.rs");
}
#[test]