Skip to content

macro binding scan: an argument-free item macro from outside the workspace may define a trusted macro name #16348

Not planned

Description

@EffortlessSteven

Found by Devin's review on #16346 (comment 4712657180). This is a property of the macro binding scan as a whole, not of that PR.

Gap (false credit, narrow): macro_binding_ambiguities / macro_binding_candidates (crates/ripr/src/analysis/syntax/owner_pin.rs) judge a macro call by its argument tokens. An item-position call to a macro from a crate outside the workspace, with no relevant tokens in its arguments (install_macros!();), may expand to macro_rules! println { .. }, macro_rules! assert_eq { .. } or macro_rules! json { .. }. The new definition's textual scope then covers the rest of that module and every child module declared after it. The scan reports no site, so a bare trusted name in that scope is read as the standard or drop-in macro.

Who is affected: every consumer of the trusted-name scan:

  • helper-wrapper transparency (helper_transfer::transparent_macro_name_rebound);
  • the trusted assertion readings in classify/owner_pin.rs;
  • activation's macro_names_rebound.

Fix direction to evaluate:

  • Treat an item-position call of an unresolved, non-trusted macro as a possible definition site for the trusted names. Bound it to its textual scope where the scan already models one, as for include! (A glob import cannot rebind a std-prelude macro in a compiling crate #16060).
  • Exempt only calls whose expansion is known to define no macro: verified cfg_if!, the audited wrapper table, thread_local!, lazy_static! after an audit.
  • Measure the credit lost on the dogfood and corpus workspaces before landing, since thread_local!/lazy_static!-style item macros are common.
  • Bump FILE_FACT_CACHE_SCHEMA_VERSION, since stored candidates must widen too.

Generated by Claude Code

Activity

  1. coderabbitai commented on Nov 26, 2026

    @coderabbitai
    🔗 Related PRs

    #8772 - fix(rust): preserve retained macro-site disclosure parity (#8265) [merged]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. added
    status/needs-work
    on Nov 26, 2026
  3. EffortlessSteven commented on Nov 27, 2026

    @EffortlessSteven
    MemberAuthor

    Claiming this for the 0.11 correctness pass, under thread "Close open correctness issues for 0.11". A PR will follow.


    Generated by Claude Code

  4. EffortlessSteven commented on Nov 27, 2026

    @EffortlessSteven
    MemberAuthor

    Closing as not planned: rustc rejects the shapes this gap depends on, so code that compiles cannot reach the false credit.

    Evidence. Small reproductions were compiled with rustc 1.95.0 (the MSRV) and rustc 1.100.0. Each one fails with E0659 (assert_eq is ambiguous: a macro-expanded name conflicts with a less macro-expanded name from an outer scope). The shapes tried:

    • An item-position install!(); whose expansion is macro_rules! assert_eq, followed by a bare assert_eq!. Tried in the same module, in a child module declared after it, and in a #[cfg(test)] test, under the 2015, 2018, 2021 and 2024 editions.
    • #[macro_export] macro_rules! assert_eq coming from an expansion inside a module, then called bare from the crate root.
    • An expansion that defines vec (a std prelude macro, in the same category as println).
    • An expansion that defines json while a use ..::json import is in scope. This covers the verified drop-in readings.
    • An expansion that emits #[macro_use] extern crate x; or use x::assert_eq;.
    • include! of a file that defines macro_rules! assert_eq.

    An expanded use in a parent module does not reach a child module, and a sibling module is not affected, so those cases are already sound.

    Cost of the proposed fix. A prototype added an ItemMacroCall binding site with the exemptions listed in this issue. It took credit from 8 Rust rows in cargo xtask verdict-corpus check-all, including two from the real bytesize crate (commutative_op! and quickcheck! item calls), and false verdicts stayed at 0. The prototype is not landing: it costs real credit for a case the compiler already refuses.

    Narrow residual, not acted on. In a #[no_std] crate the prelude has no vec/format/println/print/eprint/eprintln/dbg, so an expanded macro_rules! vec there does compile. None of these names is an assertion macro. It only matters if ripr gives oracle credit through a bare std-only macro in a no_std crate with no other source for the name. Open a new issue with a reproducing fixture if that turns up.

    A possible follow-up for credit recovery: the existing #16060 Included site also refuses core prelude names that rustc would reject anyway.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfinding-qualityimplementation-slicestatus/needs-worktesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions