@@ -8874,6 +8874,40 @@ TEST(pipeline_go_rw_usage_never_cross_into_c) {
88748874 * the generic-engine lane on its 12-language fixture). A Rust call never
88758875 * targets another language's definition. pad_files > 0 forces the parallel
88768876 * 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+
88778911static int rust_registry_rust_only_case(int pad_files) {
88788912 char tmp[256];
88798913 snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_only_XXXXXX");
@@ -8917,28 +8951,10 @@ static int rust_registry_rust_only_case(int pad_files) {
89178951 "}\n"
89188952 "\n"
89198953 "1;\n");
8920- for (int i = 0; i < pad_files; i++) {
8921- char name[64];
8922- char body[128];
8923- snprintf(name, sizeof(name), "src/filler%d.rs", i);
8924- snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);
8925- write_temp_file(tmp, name, body);
8926- }
8927-
8928- char *saved = NULL;
8929- if (pad_files > 0) {
8930- char *old_workers = getenv("CBM_WORKERS");
8931- saved = old_workers ? strdup(old_workers) : NULL;
8932- cbm_setenv("CBM_WORKERS", "4", 1);
8933- }
8934- char db_path[512];
8935- snprintf(db_path, sizeof(db_path), "%s/rust_only.db", tmp);
8936- cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
8937- ASSERT_NOT_NULL(p);
8938- ASSERT_EQ(cbm_pipeline_run(p), 0);
8939- const char *project = cbm_pipeline_project_name(p);
8940- cbm_store_t *s = cbm_store_open_path(db_path);
8954+ cbm_pipeline_t *p = NULL;
8955+ cbm_store_t *s = rust_fixture_run(tmp, pad_files, "rust_only.db", &p);
89418956 ASSERT_NOT_NULL(s);
8957+ const char *project = cbm_pipeline_project_name(p);
89428958
89438959 /* Never onto the Perl constructor ... */
89448960 ASSERT_EQ(named_edge_to_file_count(s, project, "CALLS", "run", "new", "perlsrc/Lib.pm"), 0);
@@ -8947,14 +8963,6 @@ static int rust_registry_rust_only_case(int pad_files) {
89478963
89488964 cbm_store_close(s);
89498965 cbm_pipeline_free(p);
8950- if (pad_files > 0) {
8951- if (saved) {
8952- cbm_setenv("CBM_WORKERS", saved, 1);
8953- free(saved);
8954- } else {
8955- cbm_unsetenv("CBM_WORKERS");
8956- }
8957- }
89588966 th_rmtree(tmp);
89598967 PASS();
89608968}
@@ -8967,6 +8975,73 @@ TEST(pipeline_rust_call_never_binds_another_language_parallel) {
89678975 return rust_registry_rust_only_case(52);
89688976}
89698977
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+
89709045TEST(pipeline_go_rw_usage_never_cross_into_c_parallel) {
89719046 /* Parallel twin of the test above: USAGE and WRITES/READS each have a
89729047 * second, independent resolver in pass_parallel.c (resolve_file_usages /
@@ -23829,6 +23904,8 @@ SUITE(pipeline) {
2382923904 RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);
2383023905 RUN_TEST(pipeline_rust_call_never_binds_another_language);
2383123906 RUN_TEST(pipeline_rust_call_never_binds_another_language_parallel);
23907+ RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake);
23908+ RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel);
2383223909 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);
2383323910 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method_parallel);
2383423911 RUN_TEST(pipeline_go_bare_ref_never_binds_field);
0 commit comments