Skip to content

fix(code-intel): index calls inside Rust macro arguments so dead-code stops reporting live functions - #736

Merged
ajianaz merged 1 commit into
developfrom
fix/rust-macro-call-edges
Nov 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/rust-macro-call-edges

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

Calls inside the arguments of Rust macros (json!, vec!, format!, assert!, matches!, println!, user macros) become call edges, so cora dead-code, callers, impact and trace see them.

Why

Closes #715. In tree-sitter-rust the argument of a macro invocation is a raw token_tree, not parsed expressions, so there is no call_expression inside it and extract_calls_from_node never saw those calls. In the reporter's workspace tool_kind (called in json!({ "kind": tool_kind(tool) })) and approval_config_option (called in vec[approval_config_option(x)]) were reported by dead-code as having no callers.

How

  • index/ast.rs: walk_calls calls the new token_tree_calls on every token_tree. It looks at consecutive children: an identifier followed by a token_tree that starts with ( is a call to that identifier. Nested token trees are reached by the existing recursive walk, so json!({ "k": f(x) }) finds f at the inner { } level.
  • a::b(x) yields b and x.m() yields m, which is what normalize_callee_name does for real call expressions, so edges still join against symbol names.
  • The macro's own name is not a call (json is followed by !, not a token tree), and an identifier after fn, struct, enum, union, trait, mod or type is a definition (a fn helper() inside a macro_rules! body) and is skipped.
  • The issue also suggests marking these edges from-macro with lower confidence. AstEdge has no confidence field and the issue wants them to count for dead-code anyway, so I left that out rather than add a schema column; it can follow if callers should hide them under a --strict flag.
  • Not in this PR: resolving Type::method by type (fix(code-intel): calls resolve by bare function name; Type::method and use paths are not resolved (callers, impact, trace, affected inflate or miss) #714), turbofish calls (f::<T>(x) is not matched), and macros that build identifiers.

Testing

  • cargo test --features tree-sitter passes (1352 unit tests + integration suites)
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --features tree-sitter -- -D warnings passes
  • cargo build --release --features tree-sitter passes (left to CI)
  • The issue's scenario with the real binaries on one fixture (two functions called only inside json! and vec!, one truly unused): the previous binary's cora dead-code listed all three; the new one lists only really_unused.
  • Mutation check: with the token-tree scan disabled, 2 of the 3 new tests fail.

New tests: calls in json!, vec!, format!, assert!, matches!, println! (path form), dbg! (method form) and a plain call are all edges; macro names and fn inside macro_rules! are not; a call is recorded once and with the line it is on. Re-run cora index to pick the change up on an existing project.

Related Issues

Closes #715. Related: #714, #716.

Checklist

  • Branch name follows convention (fix/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

ajianaz added a commit that referenced this pull request Nov 16, 2026
…729)

## What
The three CI fixes that only work together, in one PR: the Clippy
`needless_bool` rewrite, the `Cargo.lock` bumps for `rustix` and
`libz-sys`, the `rusqlite` 0.41 upgrade for the SQLite CVE, and the
sorted directory walk that de-flakes a test. It supersedes #728 and
#730, whose commits are included here.

## Why
Every PR to `develop` fails the same three checks, none of them caused
by the PR, so no single fix can be green on its own and none can be
merged under the required checks:
- **Clippy**: `clippy::needless_bool` at `src/engine/rules/builtin.rs`
on Rust 1.100 (the CI toolchain; local 1.97 does not report it).
- **Security Audit (CVE)**: `rustix 1.1.5` (RUSTSEC-2026-0486),
`libz-sys 1.1.30` (RUSTSEC-2026-0418) and `libsqlite3-sys 0.28.0`
(CVE-2026-119375, SQLite before 3.54.0).
- **Test**:
`mcp::agent_tools::tests::finalize_agrees_with_prepare_only_for_the_same_filters`
depends on the filesystem's `readdir` order.

## How
- `26768e8` (#728): `builtin.rs` returns the condition directly;
`Cargo.lock` only: `rustix` 1.1.6, `libz-sys` 1.1.33.
- `beee771`: `rusqlite` 0.31 to 0.41 (`libsqlite3-sys` 0.39.1, SQLite
3.54.1), `rust-version` 1.85 to 1.89, `usize` binds as `i64` in
`index/brain.rs`, and `[lints.clippy] collapsible_if = "allow"` because
Rust 1.89 enables let-chains and clippy would report 56 hits in
untouched code (a wide mechanical rewrite for a later change).
- `1275b71` (#730): `WalkBuilder::sort_by_file_name`, and the test uses
a selection whose `path` and `source-first` orders differ by
construction.
- Two merge commits bring #728 and #730 in with no conflicts.
- MSRV 1.89 is user-visible for anyone building with `cargo install` on
an older toolchain; the release notes should say so.

## Testing

- [x] `cargo test --features tree-sitter` passes (1313 unit tests +
integration suites)
- [x] `cargo fmt --all -- --check` passes
- [x] `cargo clippy --all-targets --features tree-sitter -- -D warnings`
passes (the CI Clippy check on Rust 1.100 is the real proof for
`needless_bool`)
- [ ] `cargo build --release --features tree-sitter` passes (left to CI)
- [x] Locked versions after the merges: rustix 1.1.6, libz-sys 1.1.33,
libsqlite3-sys 0.39.1, rusqlite 0.41.1.
- [x] Database compatibility of the `rusqlite` upgrade was checked in
both directions (old release binary indexed 800 symbols, new build read,
re-indexed and ran a `brain` search on the same `cora.db`, old binary
read it back, `PRAGMA integrity_check` = `ok`).
- Individually, the earlier runs showed: #728 Clippy green (fix proven),
#730 Test green (flake fixed), #729 Audit with only `rustix`/`libz-sys`
left.

## Related Issues
Supersedes #728 and #730. Unblocks #727, #731, #732, #733, #734, #735,
#736, #737.

## Checklist

- [x] Branch name follows convention (`chore/`)
- [x] Branch is from `develop`
- [x] Commit messages follow [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] No secrets or credentials committed
- [x] One logical change per PR: one logical goal (a green CI), several
small causes that cannot be separated under the required checks

🤖 Generated with [Claude Code](https://claude.ai/code)

https://claude.ai/code/session_01F36Uc6swK21c7x7J14k1wc

---------

Co-authored-by: Claude <[email protected]>
… stops reporting live functions (#715)

The arguments of a macro are a raw `token_tree`, not parsed expressions, so
`json!({ "k": f(x) })`, `vec![f(x)]`, `format!`, `assert!`, `matches!` and any
other macro produced no call_expression and therefore no call edge.

walk_calls now scans each token_tree for `identifier` followed by a
parenthesised token_tree. Paths and method calls yield their last segment (as
normalize_callee_name does), the macro's own name is not a call, and an
identifier after fn/struct/enum/union/trait/mod/type (a definition inside a
macro_rules! body) is skipped.
@ajianaz
ajianaz force-pushed the fix/rust-macro-call-edges branch from d455257 to c6dceb5 Compare November 16, 2026 01:16
@ajianaz
ajianaz merged commit 86908f3 into develop Nov 16, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(code-intel): calls inside Rust macro bodies (json!, vec!, format!, matches!, assert!) are not indexed; dead-code reports live functions

1 participant