Repository navigation
fix(rust): relate a sibling-crate test calling Type::method() on an imported type (#4558) - #4897
Conversation
…mported type (#4558) A type-path call T::name( can only reach a definition inside an impl of a type named T, or one whose context is unknown (trait default, blanket impl, lexical fallback). Record that context on parser-backed FunctionFacts and, for such a call with T imported from a declared path dependency of the owner's crate (or spelled dep::T::name), count only those definitions as competitors. Free functions and other types' same-named methods no longer refuse the call. Declared dependency names are Cargo.toml keys; fold '-' to '_' before matching use paths (tracing-core is use tracing_core::...). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
…type-path rule Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
|
Warning Review limit reachedNext included review available in 49 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (33)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to resolve ambiguity for type-path calls (e.g., T::name()) across Rust workspace crates by tracking the implementation context of functions (FunctionImplContext). It updates the AST parser to extract this context and refactors dependency edge checks to utilize it, preventing false positives when common method names are used. The feedback suggests a robust improvement in ra.rs to ensure that local functions defined inside associated constants, statics, or block expressions within an impl or trait block are correctly treated as free functions rather than being incorrectly associated with the enclosing type.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac752a47a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…l is free (#4558 review) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
- admit before the let-binding shadow check so `let current = LevelFilter::current()` relates - match call sites on comment/string-masked text so quoted paths do not admit - refuse when the owner crate imports a same-named type or glob from another crate - bump seam and file-fact cache schema versions for the new impl_context fact - add spec and traceability rows for the new tests Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
…pe-path admit (#4558) The tracing re-walk showed tracing-core's `use core::{num}` then `use num::*;` refusing the admit. A glob now counts only when its root is not std/core/alloc, a module the file declares, or a name imported through a local or std path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
…th admit (#4558) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W
…-4ws691 # Conflicts: # crates/ripr/src/analysis/seam_cache.rs
EffortlessSteven
left a comment
There was a problem hiding this comment.
Exact-head review of 88a132a: clean. CI is still running, so this records the source and oracle pass only.
What I inspected:
- The admit path in
related_tests.rs, and the order of its checks. The type-path admit runs before the let-binding, unattributed, local-shadow and competing-edge checks.- Those checks guard bare calls. A
T::name(call is guarded by its own competitor scan: any same-named definition whose context may beimpl T, or isUnknown, refuses. - An unattributed definition that is
Freecannot be reached byT::name(, so it does not refuse. Anything in an impl ofT, orUnknown, does.
- Those checks guard bare calls. A
- The owner-crate import scan.
- It runs only after a dependency-spelled
T::name(call has been captured, so it does not scan every candidate pair. - A statement that names
Tfrom a non-local root refuses. That includesstd::, which is conservative. - A glob refuses unless its root is std/core/alloc, a
modin the same file, or a name that file imports through a local or std path. - A chained re-export from another crate is still seen, because every file of the crate is scanned.
- It runs only after a dependency-spelled
- The producer (
function_impl_contextinra.rs).Fn,BlockExpr,ConstandStaticancestors giveFree; a trait givesUnknown.- An impl gives
Implonly for a plain path self type that is not a generic parameter; any other impl givesUnknown. - Lexical fallback gives
Unknown.
- The cache. The merge with main moved every bump one step past main's #4576 and
impl_attrsgenerations. The asserts and theOUTPUT_SCHEMA.mdexample were updated to match. - Oracle grip. Every rule has a discriminating negative experiment, listed in the PR body. The local-glob rule was added after the tracing re-walk exposed an over-refusal, and that rule's own negative experiment fails as expected.
- Public claim. The claims in the CHANGELOG, RIPR-SPEC-0172 and the PR body match the behaviour. The re-export and draft-mode non-claims are stated.
Missing: CodeRabbit is rate-limited, so its review is missing, not clean. Gemini, Devin and Codex reviewed earlier heads, and all of their threads are fixed and resolved.
Generated by Claude Code
Requested by Steven · project thread
Summary
Before: in tokio-rs/tracing, changing
LevelFilter::currentintracing-corenever related thetracing-subscribertest that assertsLevelFilter::current(), even withuse tracing_core::LevelFilter;. The cross-crate admit (#2972) keys competitors on the bare namecurrent, andtracing-subscriberdefines its ownSpanStack::current, so it read as a local shadow. The test's oracle was never considered.After: a call spelled
T::name(relates across crates whenTis the owner's impl self type and is imported from the owner's crate through its declared dependency name (or spelleddep::T::name(). Only definitions such a call could reach compete: methods of an impl of a type namedT, and definitions whose context is not established (trait default methods, blanket or non-path impls, lexical-fallback files). Free functions and other types' same-named methods no longer refuse it. In tracing with--mode deep/ready, the test now relates asdirect_owner_call.How: parser-backed
FunctionFacts carry a newimpl_context(Free,Impl { self_type },Unknown), set from the nearest enclosingfn/impl/trait. The ambiguity scan keeps the same-named definitions themselves, anddependency_edge_admits_owner_calltries the type-path rule before the #2972 shadow checks. Declared dependency names are Cargo.toml keys, so-is folded to_before matchingusepaths (tracing-core→tracing_core); without that no hyphenated path dependency could ever match an import.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Governing issue or accepted claim: #4558
Acceptance delta (one sentence): A sibling-crate test calling
Type::method()on the owner's type imported from the owner's crate relates to the changed method unless another definition that call could reach exists.Candidate Relationships
Candidate branch:
claude/project-thread-4ws691(restarted from main after #4611 merged). Open PRs searched: #4885 (same-method-name on another type, same crate) editsclassify/related_tests.rstoo but narrows a different relation and does not touch the dependency-edge admit; no equivalent PR. Not module-graph seeding (#4435).Scope
analysis/facts/model.rs:FunctionImplContextand theimpl_contextfield (serde defaultUnknown).analysis/syntax/ra.rs: parser producer;analysis/syntax/lexical.rs: explicitUnknown.analysis/classify/related_tests.rs:SameNameDefinitions,type_path_call_admits_owner,owner_crate_imports_type_name, declared-name hyphen folding.analysis/seam_cache.rs: file-fact cache 1.12 → 1.13, classified cache 1.18 → 1.19, sharded 0.24 → 0.25, compact 0.24 → 0.25 (one step past main's analysis(rust): produce a safe new integration-test target when no existing test can own the repair #4576 andimpl_attrsbumps, merged in 88a132a), so warm caches drop facts withoutimpl_context.Type::assoc()is refused when any crate on its path defines anotherfn assoc(tracingLevelFilter::current) #4558)" section;.ripr/traceability.tomlrows.impl_context: Default::default().Non-goals:
Tthe path names.use tracing_subscriber::filter::LevelFilter, the original tracing test): whichTa re-export names is not resolved, so that spelling stays refused.--mode draft(default) indexes only the changed packages, so no cross-crate test is visible there; unchanged.use … as T, glob imports, turbofish or whitespace spellings: refused.Support-tier Impact
Policy Impact
Proof
New tests:
type_path_call_imported_from_owner_crate_admits_across_crates(import form andcrate_a::LevelFilter::current(); declared namecrate-a)type_path_call_fails_closed_without_owner_identity: no import, renamed import, glob import, type imported from an unrelated crate, another impl of a same-named type, anUnknowndefinition, a call on another type, anUnknownownertype_path_call_refuses_foreign_type_names_and_quoted_paths: external same-named re-export, aliased brace import,pub use external::*,use ::external::*,use external::num; use num::*, and a quoted"LevelFilter::current()"beside a realother.current()type_path_call_admits_past_local_and_standard_globs:use core::{num}+use num::*(tracing-core's own shape),mod inner; use inner::*,use std::collections::*impl_context_names_the_self_type_only_for_plain_named_impls(free, module, function-local, fn in a const, inherent, trait impl with qualified self type, generic args, blanket, reference self type, trait default)let current = LevelFilter::current()and aself::re-export inside the owner crateNegative experiments:
Unknowntreated as unreachable fails the unknown-definition row; ignoring the self type fails the same-named-impl row; unmasked call text fails the quoted row; disabling the owner-crate import scan fails the foreign re-export rows; treating every glob as foreign fails the local-glob rows; dropping the const/static/block arms failsin_const.Re-walk (tracing d9d4c54 +
LevelFilter::currentchange, head 4c60168). The first review-fix cut over-refused here on tracing-core'suse num::*, which is what the glob-root rule fixes:use tracing_core::LevelFilter;direct_owner_calluse tracing_core::LevelFilter;use tracing_subscriber::filter::LevelFilter(original)Claim Boundary
May claim: sibling-crate
T::name()calls on a type imported from the owner's crate relate when no other reachable definition exists; hyphenated dependency names match their_spelling.Must not claim: re-exported types, aliases, draft-mode cross-crate discovery, or any change to exposure class rules.
Rollback
Revert the squash commit. The cache schema bumps make any cache written by this version rebuild on the reverted one.
Static Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Review
Gemini, Devin and Codex reviewed; all findings fixed and threads resolved (let-binding shadow, quoted call text, foreign same-named re-export, cache schema bump, traceability, const/static/block context). CodeRabbit: rate-limited, review missing.
Gates
cargo fmt --checkcargo xtask precommit🤖 Generated with Claude Code
https://claude.ai/code/session_01EqbiiuYkC94scgE9rZ5K8W