diff --git a/graphify/extractors/rust.py b/graphify/extractors/rust.py index aae59c67d..83759ed41 100644 --- a/graphify/extractors/rust.py +++ b/graphify/extractors/rust.py @@ -723,8 +723,9 @@ def extract_rust(path: Path) -> dict: if arg: def name_use(written: str, path: str) -> None: # The name as written, for the corpus rewire (#4439): the id folds its - # case. Not for the standard library, whose `File` is never the corpus's. - if path.lstrip(": ").split("::")[0].strip() not in ("std", "core", "alloc"): + # case. Only for a path rooted in this crate: `serde::Serialize` or + # `std::fs::File` is never the corpus's own `Serialize` or `File`. + if path.lstrip(": ").split("::")[0].strip() in ("crate", "self", "super"): edges[-1]["_rust_use_name"] = written.split(" as ")[0].strip() module_name = _rust_use_module(_read_text(arg, source)) grouped = arg.type in ("use_list", "scoped_use_list") diff --git a/tests/test_rust_use_trees.py b/tests/test_rust_use_trees.py index e3f10e0b0..e515b3c41 100644 --- a/tests/test_rust_use_trees.py +++ b/tests/test_rust_use_trees.py @@ -236,8 +236,10 @@ def test_a_use_of_a_name_declared_twice_stays_unresolved(tmp_path: Path): assert _imports(result, "user.rs") == ["thing"] -def test_a_std_use_does_not_land_on_a_same_named_declaration(tmp_path: Path): +def test_a_use_from_another_crate_does_not_land_on_a_same_named_declaration(tmp_path: Path): + """Only a path rooted at `crate`, `self` or `super` names this crate's own item.""" result = _extract(tmp_path, { - "src/lib.rs": "pub mod a;\npub mod user;\n", "src/a.rs": "pub struct File;\npub struct Command;\n", - "src/user.rs": "use std::fs::File;\nuse std::{process::Command, io};\n"}) - assert _imports(result, "user.rs") == ["command", "file", "io"] + "src/lib.rs": "pub mod a;\npub mod user;\n", + "src/a.rs": "pub struct File;\npub struct Command;\npub struct Serialize;\n", + "src/user.rs": "use std::fs::File;\nuse std::{process::Command, io};\nuse serde::Serialize;\n"}) + assert _imports(result, "user.rs") == ["command", "file", "io", "serialize"]