Skip to content

rust: a test module's own same-name type shadows the production receiver type, so owner pins credit the production method (false exposed) #6905

Closed

Description

@EffortlessSteven

Problem

Owner-return pins resolve a test receiver's type by name only. A #[cfg(test)] mod tests that declares its own type with the production type's name shadows the production type inside the test module. Its methods are not the changed owner, but ripr still treats them as the changed owner. The result is a false exposed credit. That is the fail-open direction, which must never happen for an actionable signal.

Repro (RIPR-SPEC-0197 rule 6 shape; the same applies to rules 1-2 method pins)

// src/lib.rs
#[derive(Debug, PartialEq)]
pub struct W { x: u32 }

impl Clone for W {
    fn clone(&self) -> Self {
        W {
            x: 0, // changed line: wrong clone field
        }
    }
}

#[cfg(test)]
mod tests {
    #[derive(Debug, Clone, PartialEq)]
    struct W { x: u32 } // shadows crate::W inside this module

    #[test]
    fn clone_round_trip() {
        let w = W { x: 3 };
        assert_eq!(w.clone(), w); // runs the test-local derived clone
    }
}

What I expect, but have not confirmed by running ripr on this repro:

  • type_declared_in_workspace / declared_receiver see W.
  • derived_equality reads the production W, because local_type_equality skips test-module definitions.
  • The test-side binding let w = W { .. } is credited as the production W.
  • The changed x: 0, field of the production clone reads exposed. Yet no test runs that clone.

The same name shadowing affects every method pin whose receiver type is established by name (test_receiver_type / binding_type): an inherent method, a trait default method, or a clone field.

Goal it hurts

Verdict honesty. A changed owner must not read exposed when no test executes it.

Owner

crates/ripr/src/analysis/classify/owner_pin.rs (test_receiver_type, binding_type, named_or_slice, establish_clone_field). The fix belongs to the owner-pin receiver identity. It should not go in a renderer or in reveal.

Suggested direction (fail closed)

Refuse a receiver type name that any type declaration in the test's own module scope (or anywhere in the test file outside the production declaration) also declares. Same-name test-only declarations should refuse the pin rather than be skipped.

Found while reviewing #6773 (clone-field pins, RIPR-SPEC-0197 rule 6); not a regression introduced there.

Activity

  1. EffortlessSteven commented on Oct 7, 2026

    @EffortlessSteven
    MemberAuthor

    Reconciliation: claim landed via PR #6948, squash-merged as 4f12abe (2026-10-07T04:20:04Z, exact head cfedede, 15 files).

    Acceptance covered: test-module types shadowing the owner receiver now refuse the pin (AST-ancestry scope with line-span fallback); macro-generated test-module shadows fail closed via the lexical arm; SPEC-0197 rule extended; traceability mapped; shadow fixture plus goldens; changelog entry.

    Proof: 67/67 owner_pin lib tests with the new shadow test verified red-first, evidence-promotion-honesty pass, goldens zero-drift, traceability/spec/clippy/fmt clean, 8/8 review threads resolved, required Ripr Rust Small Result green on the exact head. Required proof came from a manual workflow_dispatch after the #5373 scheduling misfire (no pull_request runs for the lane branch); per the #5394 caveat the dispatch skips the PR-evidence gate, so I re-ran that gate locally against the exact diff and will record the outcome here.

    Residuals (not this claim): #6950 out-of-line shadows, #6951, #6957 nested-module precision.

    Instrument note: gh pr merge refused twice on a stale client-side BLOCKED precheck while every rule passed; the direct REST merge endpoint accepted the same ordinary protected squash (no admin flag).

  2. EffortlessSteven commented on Oct 7, 2026

    @EffortlessSteven
    MemberAuthor

    PR-evidence gap closure (the #5394-skipped gate), run locally against the exact pre-merge diff b74e6b1...cfedede with CI parity env: all 10 producer plus check steps pass (ripr-pr, ripr-review-comments, impacted-evidence, ripr-pr-summary, ripr-annotations, each with --check). The dispatch-based required proof plus this local gate leaves no unexecuted PR-evidence dimension for #6948.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions