Skip to content

Respect renamed dependencies when resolving configured paths - #17625

Open
fyrsta7 wants to merge 2 commits into
rust-lang:masterfrom
fyrsta7:fix/renamed-disallowed-paths
Open

Respect renamed dependencies when resolving configured paths#17625
fyrsta7 wants to merge 2 commits into
rust-lang:masterfrom
fyrsta7:fix/renamed-disallowed-paths

Conversation

@fyrsta7

@fyrsta7 fyrsta7 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Clippy's shared path resolver indexed external crates by their canonical metadata names. This meant that a path configured with the source-visible name of a renamed Cargo dependency could not resolve, even though that was the only name available in the crate's source code.

This keeps canonical-name lookup intact and also indexes prelude-visible --extern aliases by matching their canonical source paths to loaded crates. A source-visible alias takes precedence if it collides with another crate's canonical name, matching how paths resolve in source code. The shared fix applies to disallowed-methods, disallowed-types, and other configuration features that use the same path resolver.

The UI-Cargo regression covers alias resolution, canonical-name compatibility, and a collision with another crate's canonical name.

Fixes #17585

changelog: [disallowed_methods, disallowed_types]: resolve configured paths through renamed Cargo dependencies

Testing

  • TESTNAME=disallowed_paths_renamed_dependency cargo uitest
  • cargo test
  • cargo dev fmt --check

@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 24, 2026

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code wise LGTM.
I have one clairifiying question and a nit.

View changes since this review

Comment thread clippy_utils/src/paths.rs Outdated
Comment on lines 203 to 239
}
}
}
map

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
the init is getting a bit long which makes it harder to reason about...
Please split out into a method, since this way we can also add a good place for an brief explaing comment (that you arlready wrote in the PR description)

@fyrsta7 fyrsta7 Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've moved the initialization into a collect_crates_by_name helper and added a comment explaining that prelude-visible --extern aliases are matched to loaded crates by source path and take precedence over colliding canonical names.

Comment on lines +4 to +5
renamed_dependency::forbidden_by_alias();
renamed_dependency::forbidden_by_package_name();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is something I don't understand/know, but I would have expected these comments to be required...
Are they not??

Suggested change
renamed_dependency::forbidden_by_alias();
renamed_dependency::forbidden_by_package_name();
renamed_dependency::forbidden_by_alias(); //~ disallowed_methods
renamed_dependency::forbidden_by_package_name(); //~ disallowed_methods

@fyrsta7 fyrsta7 Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for asking. This test uses the ui-cargo harness, which validates diagnostics through Cargo.stderr rather than compiletest's inline //~ annotations. I checked the existing ui-cargo tests and they follow the same snapshot-based pattern, so I kept both expected disallowed_methods diagnostics in Cargo.stderr.

Comment on lines +8 to +9
renamed_dependency = { package = "actual_dependency", path = "actual_dependency" }
other_dependency = { package = "renamed_dependency", path = "renamed_dependency" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nasty and evil !!!

(it is a good test though)

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

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. 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.

disallowed-methods and similar options don't respect renamed renamed dependencies in Cargo.toml

3 participants