fix: emit visible re-export path when canonical traverses a private module#16925
Open
swjng wants to merge 1 commit intorust-lang:masterfrom
Open
fix: emit visible re-export path when canonical traverses a private module#16925swjng wants to merge 1 commit intorust-lang:masterfrom
swjng wants to merge 1 commit intorust-lang:masterfrom
Conversation
Collaborator
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
815b650 to
db0756a
Compare
|
Lintcheck changes for 23bec31
This comment will be updated if you push new changes |
This comment has been minimized.
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.
db0756a to
23bec31
Compare
Collaborator
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
redundant_closure_for_method_callswas emitting suggestions built fromtcx.def_pathdirectly. When the canonical path traversed a privatemodule, the suggestion did not compile (E0603), and
clippy --fixreplaced working code with broken code.
Closes #16731.
changelog: [
redundant_closure_for_method_calls]: avoid suggesting paths that go through a private moduleApproach
In
get_path_to_callee, three tiers:accessible from the caller.
root for the shortest visible path. Skips
pub use _ as _and#[doc(hidden)]; descends throughMod | Enum | Trait.Applicability::MaybeIncorrectif neitherworks — the diagnostic still shows, but
--fixno longerauto-applies it.
get_path_from_caller_to_method_typenow returns(String, Applicability); the single caller ineta_reduction.rsisupdated.
Test plan
tests/ui/eta.rs(mod issue16731) coveringinherent 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 --checkclean.AI tools used: Claude Code. All changes reviewed and tested by the author.