Skip to content

refactor: single source of truth for impl-qualified function names#627

Merged
rocketman-code merged 2 commits intomainfrom
refactor/misu-qualified-names
Apr 24, 2026
Merged

refactor: single source of truth for impl-qualified function names#627
rocketman-code merged 2 commits intomainfrom
refactor/misu-qualified-names

Conversation

@rocketman-code
Copy link
Copy Markdown
Owner

Summary

  • Add naming::qualified_name_for_fn that derives impl/trait-qualified names from AST position
  • Replace four independent name-construction code paths with calls to the shared function
  • Remove current_impl and current_trait state variables from FnCollector
  • Delete find_ancestor_impl_context and macro_call_impl_context
  • Add cross-path agreement test (resolve + rewriter produce identical names)

Net -53 lines of code. Resolve lost 97 lines of state management, rewriter lost 29 lines of duplicate logic.

Fixes a latent bug: find_ancestor_impl_context walked past enclosing functions, causing nested bare fns inside impl methods to inherit the impl prefix (Outer::helper instead of helper).

Test Plan

  • 6 unit tests for qualified_name_for_fn covering all edge cases
  • Cross-path agreement test: same source fed to resolve and rewriter, identical names asserted
  • All existing tests pass (0 regressions)
  • Rewriter test keys updated for trait default method format (T::method)

Walks up the AST from a function node to find the nearest enclosing
impl or trait block. Handles: standalone fn (bare name), inherent impl
(Type::method), trait impl (<Type as Trait>::method), trait default
(Trait::method), nested fn in impl (bare, breaks at enclosing fn),
and nested impl in fn (inner impl type).

Includes 6 unit tests and a cross-path agreement test that feeds the
same source to both FnCollector (resolve) and qualified_name_for_fn
(rewriter path), asserting identical names. Covers generics.

Updates stale InjectionCollector doc references.
Rewriter: delete qualified_fn_name, call naming::qualified_name_for_fn
at both guard-injection sites. Update test keys for trait-qualified
format (T::method).

Resolve: remove current_impl and current_trait state from FnCollector.
Simplify visit_impl, visit_impl_fn, visit_trait, visit_trait_fn,
walk_fn_body, and visit_nested_fn to use the shared function. Delete
find_ancestor_impl_context and macro_call_impl_context. The macro path
inlines a parent-walk with fn-break guard since expanded AST lacks
original parent context.

Fixes: find_ancestor_impl_context walked past enclosing functions,
causing nested bare fns inside impl methods to inherit the impl prefix.
@rocketman-code rocketman-code force-pushed the refactor/misu-qualified-names branch from ed59433 to 006b385 Compare April 24, 2026 05:56
@rocketman-code rocketman-code merged commit 31b4d90 into main Apr 24, 2026
11 checks passed
@rocketman-code rocketman-code deleted the refactor/misu-qualified-names branch April 24, 2026 06:00
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.

1 participant