@@ -8868,6 +8868,180 @@ TEST(pipeline_go_rw_usage_never_cross_into_c) {
88688868 PASS();
88698869}
88708870
8871+ /* The Rust registries were built from the mixed-language def set: a Perl
8872+ * `sub new` became a Rust free function, and the project-wide
8873+ * lsp_short_name_unique fallback bound `Store::new()` to it at 0.90 (found by
8874+ * the generic-engine lane on its 12-language fixture). A Rust call never
8875+ * targets another language's definition. pad_files > 0 forces the parallel
8876+ * resolver, whose Rust registry is the shared all-defs build. */
8877+ /* Pads a Rust fixture with pad_files filler modules (pad_files > 0 forces the
8878+ * parallel resolver: CBM_WORKERS=4 for the run), runs the full pipeline into
8879+ * <tmp>/<db_name> and opens the store. NULL store = the run failed. */
8880+ static cbm_store_t *rust_fixture_run(const char *tmp, int pad_files, const char *db_name,
8881+ cbm_pipeline_t **out_p) {
8882+ for (int i = 0; i < pad_files; i++) {
8883+ char name[64];
8884+ char body[128];
8885+ snprintf(name, sizeof(name), "src/filler%d.rs", i);
8886+ snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);
8887+ write_temp_file(tmp, name, body);
8888+ }
8889+ char *saved = NULL;
8890+ if (pad_files > 0) {
8891+ char *old_workers = getenv("CBM_WORKERS");
8892+ saved = old_workers ? strdup(old_workers) : NULL;
8893+ cbm_setenv("CBM_WORKERS", "4", 1);
8894+ }
8895+ char db_path[512];
8896+ snprintf(db_path, sizeof(db_path), "%s/%s", tmp, db_name);
8897+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
8898+ int rc = p ? cbm_pipeline_run(p) : -1;
8899+ if (pad_files > 0) {
8900+ if (saved) {
8901+ cbm_setenv("CBM_WORKERS", saved, 1);
8902+ free(saved);
8903+ } else {
8904+ cbm_unsetenv("CBM_WORKERS");
8905+ }
8906+ }
8907+ *out_p = p;
8908+ return rc == 0 ? cbm_store_open_path(db_path) : NULL;
8909+ }
8910+
8911+ static int rust_registry_rust_only_case(int pad_files) {
8912+ char tmp[256];
8913+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_only_XXXXXX");
8914+ if (!cbm_mkdtemp(tmp)) {
8915+ FAIL("tmpdir");
8916+ }
8917+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"app\"\nversion = \"0.1.0\"\n");
8918+ write_temp_file(tmp, "src/store.rs",
8919+ "pub struct Store {\n"
8920+ " n: u32,\n"
8921+ "}\n"
8922+ "\n"
8923+ "impl Store {\n"
8924+ " pub fn new() -> Store {\n"
8925+ " Store { n: 0 }\n"
8926+ " }\n"
8927+ "\n"
8928+ " pub fn get(&self, k: u32) -> u32 {\n"
8929+ " self.n + k\n"
8930+ " }\n"
8931+ "}\n");
8932+ write_temp_file(tmp, "src/main.rs",
8933+ "mod store;\n"
8934+ "\n"
8935+ "use crate::store::Store;\n"
8936+ "\n"
8937+ "fn run() -> u32 {\n"
8938+ " let s = Store::new();\n"
8939+ " s.get(1)\n"
8940+ "}\n"
8941+ "\n"
8942+ "fn main() {\n"
8943+ " run();\n"
8944+ "}\n");
8945+ write_temp_file(tmp, "perlsrc/Lib.pm",
8946+ "package Lib;\n"
8947+ "\n"
8948+ "sub new {\n"
8949+ " my ($class) = @_;\n"
8950+ " return bless {}, $class;\n"
8951+ "}\n"
8952+ "\n"
8953+ "1;\n");
8954+ cbm_pipeline_t *p = NULL;
8955+ cbm_store_t *s = rust_fixture_run(tmp, pad_files, "rust_only.db", &p);
8956+ ASSERT_NOT_NULL(s);
8957+ const char *project = cbm_pipeline_project_name(p);
8958+
8959+ /* Never onto the Perl constructor ... */
8960+ ASSERT_EQ(named_edge_to_file_count(s, project, "CALLS", "run", "new", "perlsrc/Lib.pm"), 0);
8961+ /* ... and the Rust call still binds the Rust associated function. */
8962+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "run", "new", "src/store.rs"), 1);
8963+
8964+ cbm_store_close(s);
8965+ cbm_pipeline_free(p);
8966+ th_rmtree(tmp);
8967+ PASS();
8968+ }
8969+
8970+ TEST(pipeline_rust_call_never_binds_another_language) {
8971+ return rust_registry_rust_only_case(0);
8972+ }
8973+
8974+ TEST(pipeline_rust_call_never_binds_another_language_parallel) {
8975+ return rust_registry_rust_only_case(52);
8976+ }
8977+
8978+ /* `Opts::write(true)` is an associated function. The LSP leaves it to the
8979+ * registry (import_map -> fsx.Opts.write), but its free-function short-name
8980+ * fallback bound it to the project's only free `write` (cache.write) first, and
8981+ * that LSP row pre-empted the right answer. With the cross-language namesakes
8982+ * gone (above), this hijack replaced 600+ correct qualified_suffix/import_map
8983+ * edges on the Rust corpus. A type-qualified call never takes that fallback. */
8984+ static int rust_assoc_call_free_namesake_case(int pad_files) {
8985+ char tmp[256];
8986+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_assoc_XXXXXX");
8987+ if (!cbm_mkdtemp(tmp)) {
8988+ FAIL("tmpdir");
8989+ }
8990+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"app\"\nversion = \"0.1.0\"\n");
8991+ write_temp_file(tmp, "src/fsx.rs",
8992+ "pub struct Opts {\n"
8993+ " pub w: bool,\n"
8994+ "}\n"
8995+ "\n"
8996+ "impl Opts {\n"
8997+ " pub fn write(w: bool) -> Opts {\n"
8998+ " Opts { w }\n"
8999+ " }\n"
9000+ "}\n");
9001+ write_temp_file(tmp, "src/cache.rs",
9002+ "pub fn write(p: &str) -> usize {\n"
9003+ " p.len()\n"
9004+ "}\n");
9005+ write_temp_file(tmp, "src/main.rs",
9006+ "mod cache;\n"
9007+ "mod fsx;\n"
9008+ "\n"
9009+ "use crate::fsx::Opts;\n"
9010+ "\n"
9011+ "fn run() -> bool {\n"
9012+ " let o = Opts::write(true);\n"
9013+ " o.w\n"
9014+ "}\n"
9015+ "\n"
9016+ "fn main() {\n"
9017+ " run();\n"
9018+ " cache::write(\"x\");\n"
9019+ "}\n");
9020+ cbm_pipeline_t *p = NULL;
9021+ cbm_store_t *s = rust_fixture_run(tmp, pad_files, "rust_assoc.db", &p);
9022+ ASSERT_NOT_NULL(s);
9023+ const char *project = cbm_pipeline_project_name(p);
9024+
9025+ /* The associated function, never the free namesake ... */
9026+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "run", "write", "src/fsx.rs"), 1);
9027+ ASSERT_EQ(named_edge_to_file_count(s, project, "CALLS", "run", "write", "src/cache.rs"), 0);
9028+ /* ... while the module-qualified free call keeps its target. */
9029+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "main", "write", "src/cache.rs"), 1);
9030+
9031+ cbm_store_close(s);
9032+ cbm_pipeline_free(p);
9033+ th_rmtree(tmp);
9034+ PASS();
9035+ }
9036+
9037+ TEST(pipeline_rust_assoc_call_never_binds_free_namesake) {
9038+ return rust_assoc_call_free_namesake_case(0);
9039+ }
9040+
9041+ TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel) {
9042+ return rust_assoc_call_free_namesake_case(52);
9043+ }
9044+
88719045TEST(pipeline_go_rw_usage_never_cross_into_c_parallel) {
88729046 /* Parallel twin of the test above: USAGE and WRITES/READS each have a
88739047 * second, independent resolver in pass_parallel.c (resolve_file_usages /
@@ -23845,6 +24019,10 @@ SUITE(pipeline) {
2384524019 RUN_TEST(pipeline_html_embedded_member_call_stays_unbound);
2384624020 RUN_TEST(pipeline_go_rw_usage_never_cross_into_c);
2384724021 RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);
24022+ RUN_TEST(pipeline_rust_call_never_binds_another_language);
24023+ RUN_TEST(pipeline_rust_call_never_binds_another_language_parallel);
24024+ RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake);
24025+ RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel);
2384824026 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);
2384924027 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method_parallel);
2385024028 RUN_TEST(pipeline_go_bare_ref_never_binds_field);
0 commit comments