mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-04 07:27:20 +00:00
* fix(rust): see through Box, Rc and Arc on struct field types (#3498) The struct-field normalizer in rust/range-binding.ts cut a type at its first `<`. A `repo: Box<User>` field was typed `Box`, so `self.repo.save()` bound nothing. It also stripped a leading `&` but not a lifetime, so a borrowed field, which always carries one (`&'a User`), came out as `'a User`. Box, Rc and Arc auto-deref on a method call, so the field now takes their first type argument: bare or path-qualified (`std::rc::Rc<User>`), and nested (`Rc<Box<User>>`). Borrows with a lifetime or `mut` are stripped, and `Box<dyn Trait>` reduces to the trait through the stripDynBound helper that parameters already use (#2604). RefCell, Cell, Mutex, RwLock, Option and Vec are deliberately left alone. A method on the inner type needs `.borrow()`, `.get()`, `.lock()`, `.read()`, a match or an index first, so the receiver really is the wrapper, and a direct call through one must not bind. Shape arm: rust `decoratedFieldType` moves INVISIBLE-GAP -> RESOLVES, with the edge on `User::save`. The corpus has no smart-pointer or borrowed struct field, so the count arm and every other cell are unchanged, and the corpus edge (2838) and drop (192) sets match main exactly. Scope-capture fingerprints are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(rust): keep opaque pointer fields wrapped * fix(rust): refuse opaque macro expansions * test(rust): pin pointer wrapper targets and opacity limits (#3665) - Assert a same-file Box keeps its own save target while User.save stays unbound (review thread on custom same-named wrappers). - Pin the documented workspace-wide recall limit: an unrelated unresolved import or macro_rules! keeps an otherwise valid pointer field wrapped. - Drop per-case logging and group the opaque/expansion cases in describe blocks. - Collapse the stacked pointer-field receipts in BASELINE.md into one current section listing every workspace-wide refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: preserve Rust integration notes * test(rust): assert complete pointer targets --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2 KiB
TypeScript
50 lines
2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { writeFixtureRepo, runPipelineFromRepo, getRelationships } from './resolvers/helpers.js';
|
|
const cases = [
|
|
['dependency macro', 'ext::declare_describe!();', false],
|
|
['macro-use dependency', '#[macro_use] extern crate ext; declare_describe!();', false],
|
|
['attribute macro', '#[ext::declare_describe] struct Marker;', false],
|
|
['derive macro', '#[derive(ext::Describe)] struct Marker;', false],
|
|
['include-generated items', 'include!("generated.rs");', false],
|
|
[
|
|
'nested dependency macro',
|
|
'fn seed(){ println!("{}", { ext::declare_describe!(); 0 }); }',
|
|
false,
|
|
],
|
|
// Expected limits: unrelated opaque evidence disables inference workspace-wide.
|
|
['unrelated external import', 'use serde::Serialize;', false],
|
|
['unrelated macro definition', 'macro_rules! noop { () => {}; }', false],
|
|
['standard derive', '#[derive(Clone)] struct Marker;', true],
|
|
['standard macro expression', 'fn seed(){ println!("seed"); }', true],
|
|
] as const;
|
|
describe('Rust pointer fields near macro expansion', () => {
|
|
it.each(cases)(
|
|
'%s keeps expansion-sensitive pointer ownership',
|
|
async (_name, prefix, positive) => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pointer-expansion-'));
|
|
try {
|
|
writeFixtureRepo(root, {
|
|
'src/lib.rs': `use std::rc::Rc;
|
|
trait Describe { fn describe(&self); }
|
|
${prefix}
|
|
struct User; impl User { fn describe(&self) {} }
|
|
struct Other; impl Other { fn describe(&self) {} }
|
|
struct Holder { repo: Rc<User> }
|
|
fn probe(h: &Holder) { h.repo.describe(); }
|
|
`,
|
|
});
|
|
const r = await runPipelineFromRepo(root, () => {});
|
|
const targets = getRelationships(r, 'CALLS')
|
|
.filter((e) => e.source === 'probe')
|
|
.map((e) => e.rel.targetId);
|
|
expect(targets).toEqual(positive ? ['Function:src/lib.rs:User.describe#0'] : []);
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
},
|
|
180000,
|
|
);
|
|
});
|