Skip to content

fix: emit visible re-export path when canonical traverses a private module#16925

Open
swjng wants to merge 1 commit intorust-lang:masterfrom
swjng:fix-16731-private-module-path
Open

fix: emit visible re-export path when canonical traverses a private module#16925
swjng wants to merge 1 commit intorust-lang:masterfrom
swjng:fix-16731-private-module-path

Conversation

@swjng
Copy link
Copy Markdown

@swjng swjng commented Apr 28, 2026

Summary

redundant_closure_for_method_calls was emitting suggestions built from
tcx.def_path directly. When the canonical path traversed a private
module, the suggestion did not compile (E0603), and clippy --fix
replaced working code with broken code.

Closes #16731.

changelog: [redundant_closure_for_method_calls]: avoid suggesting paths that go through a private module

Approach

In get_path_to_callee, three tiers:

  1. Short relative path when every segment of the canonical path is
    accessible from the caller.
  2. Public re-export path otherwise — BFS the local crate from the
    root for the shortest visible path. Skips pub use _ as _ and
    #[doc(hidden)]; descends through Mod | Enum | Trait.
  3. Canonical name with Applicability::MaybeIncorrect if neither
    works — the diagnostic still shows, but --fix no longer
    auto-applies it.

get_path_from_caller_to_method_type now returns
(String, Applicability); the single caller in eta_reduction.rs is
updated.

Test plan

  • Regression cases in tests/ui/eta.rs (mod issue16731) covering
    inherent and trait methods re-exported across a private module.
  • cargo test --test compile-test (1759 + 188 + 46 tests) clean.
  • cargo test --test dogfood, cargo fmt --check clean.

AI tools used: Claude Code. All changes reviewed and tested by the author.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 28, 2026

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq

@rustbot

This comment has been minimized.

@swjng swjng force-pushed the fix-16731-private-module-path branch from 815b650 to db0756a Compare April 28, 2026 16:56
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Lintcheck changes for 23bec31

Lint Added Removed Changed
clippy::redundant_closure_for_method_calls 0 0 15

This comment will be updated if you push new changes

@rustbot

This comment has been minimized.

…odule

Suggestions previously walked `tcx.def_path` directly, producing the
canonical path of an item even when intermediate modules are private at
the call site. The result did not compile (E0603).

Check accessibility of every segment from the caller. When the canonical
path is unsafe, BFS the local crate for the shortest public re-export
path reachable from the caller and emit it as a `crate::...` absolute
path.
@swjng swjng force-pushed the fix-16731-private-module-path branch from db0756a to 23bec31 Compare April 30, 2026 15:33
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 30, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redundant_closure_for_method_calls auto-fix used private module

3 participants