@@ -9042,6 +9042,94 @@ TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel) {
90429042 return rust_assoc_call_free_namesake_case(52);
90439043}
90449044
9045+ /* F-R4 (#763, Rust): calls inside a method of a generic impl (`impl<T> Gen<T>`,
9046+ * `impl<'a> Life<'a>`) were sourced from the File node: the call scope kept the
9047+ * generic arguments the def side strips. Each method must be the source of its
9048+ * own call. pad_files > 0 forces the parallel resolver. */
9049+ static int rust_generic_impl_attribution_case(int pad_files) {
9050+ char tmp[256];
9051+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_gimpl_XXXXXX");
9052+ if (!cbm_mkdtemp(tmp)) {
9053+ FAIL("tmpdir");
9054+ }
9055+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"fx\"\nversion = \"0.1.0\"\n");
9056+ write_temp_file(
9057+ tmp, "src/lib.rs",
9058+ "pub struct Gen<T> { v: T }\n"
9059+ "impl<T> Gen<T> {\n"
9060+ " pub fn in_generic(&self) -> u32 { helper_a() + self.other_g() + Self::assoc_g() }\n"
9061+ " pub fn other_g(&self) -> u32 { 3 }\n"
9062+ " pub fn assoc_g() -> u32 { 4 }\n"
9063+ "}\n"
9064+ "pub struct Life<'a> { s: &'a str }\n"
9065+ "impl<'a> Life<'a> {\n"
9066+ " pub fn in_lifetime(&self) -> u32 { helper_b() + self.other_l() }\n"
9067+ " pub fn other_l(&self) -> u32 { 5 }\n"
9068+ "}\n"
9069+ "pub fn helper_a() -> u32 { 1 }\n"
9070+ "pub fn helper_b() -> u32 { 2 }\n");
9071+ for (int i = 0; i < pad_files; i++) {
9072+ char name[64];
9073+ char body[128];
9074+ snprintf(name, sizeof(name), "src/filler%d.rs", i);
9075+ snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);
9076+ write_temp_file(tmp, name, body);
9077+ }
9078+
9079+ char *saved = NULL;
9080+ if (pad_files > 0) {
9081+ char *old_workers = getenv("CBM_WORKERS");
9082+ saved = old_workers ? strdup(old_workers) : NULL;
9083+ cbm_setenv("CBM_WORKERS", "4", 1);
9084+ }
9085+ char db_path[512];
9086+ snprintf(db_path, sizeof(db_path), "%s/rust_gimpl.db", tmp);
9087+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
9088+ ASSERT_NOT_NULL(p);
9089+ ASSERT_EQ(cbm_pipeline_run(p), 0);
9090+ const char *project = cbm_pipeline_project_name(p);
9091+ cbm_store_t *s = cbm_store_open_path(db_path);
9092+ ASSERT_NOT_NULL(s);
9093+
9094+ ASSERT_TRUE(cross_file_call_exists(s, project, "in_generic", "helper_a"));
9095+ ASSERT_TRUE(cross_file_call_exists(s, project, "in_lifetime", "helper_b"));
9096+ /* ... and not from the file. */
9097+ ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_a"));
9098+ ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_b"));
9099+ /* The LSP side names the impl's self type without its arguments too: its
9100+ * rows join these callers (lsp_*, not a registry fallback), and `self.` /
9101+ * `Self::` dispatch inside a generic impl resolves (Self::assoc_g had no
9102+ * edge at all). */
9103+ ASSERT_TRUE(
9104+ cross_file_call_has_strategy(s, project, "in_generic", "helper_a", "\"strategy\":\"lsp_"));
9105+ ASSERT_TRUE(
9106+ cross_file_call_has_strategy(s, project, "in_generic", "other_g", "\"strategy\":\"lsp_"));
9107+ ASSERT_TRUE(cross_file_call_exists(s, project, "in_generic", "assoc_g"));
9108+ ASSERT_TRUE(
9109+ cross_file_call_has_strategy(s, project, "in_lifetime", "other_l", "\"strategy\":\"lsp_"));
9110+
9111+ cbm_store_close(s);
9112+ cbm_pipeline_free(p);
9113+ if (pad_files > 0) {
9114+ if (saved) {
9115+ cbm_setenv("CBM_WORKERS", saved, 1);
9116+ free(saved);
9117+ } else {
9118+ cbm_unsetenv("CBM_WORKERS");
9119+ }
9120+ }
9121+ th_rmtree(tmp);
9122+ PASS();
9123+ }
9124+
9125+ TEST(pipeline_rust_generic_impl_method_sources_its_calls) {
9126+ return rust_generic_impl_attribution_case(0);
9127+ }
9128+
9129+ TEST(pipeline_rust_generic_impl_method_sources_its_calls_parallel) {
9130+ return rust_generic_impl_attribution_case(52);
9131+ }
9132+
90459133TEST(pipeline_go_rw_usage_never_cross_into_c_parallel) {
90469134 /* Parallel twin of the test above: USAGE and WRITES/READS each have a
90479135 * second, independent resolver in pass_parallel.c (resolve_file_usages /
@@ -24748,6 +24836,8 @@ SUITE(pipeline) {
2474824836 RUN_TEST(pipeline_rust_call_never_binds_another_language_parallel);
2474924837 RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake);
2475024838 RUN_TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel);
24839+ RUN_TEST(pipeline_rust_generic_impl_method_sources_its_calls);
24840+ RUN_TEST(pipeline_rust_generic_impl_method_sources_its_calls_parallel);
2475124841 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);
2475224842 RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method_parallel);
2475324843 RUN_TEST(pipeline_go_bare_ref_never_binds_field);
0 commit comments