Skip to content

disallowed_methods: handle full paths as replacement for method call #15242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

notriddle
Copy link
Contributor

This can't do the "correct" thing, and check if the method is defined, because FnCtxt::lookup_method isn't accessible in Clippy.

To work around this problem, we convert method calls to FQP syntax if the user specifies a full path as a replacement. If they specify only a name, then we only replace the name. Since clippy.toml resolves paths from the top level of the crate, this is basically guaranteed to produce a correct result, if we ignore method call adjustments like autoderef.

changelog: [disallowed_methods]: correctly handle methods called by FQP

Fixes #15067

This can't do the "correct" thing, and check if the method is defined,
because `FnCtxt::lookup_method` isn't accessible in Clippy.

To work around this problem, we convert method calls to FQP syntax
if the user specifies a full path as a replacement. If they specify
only a name, then we only replace the name. Since clippy.toml
resolves paths from the top level of the crate, this is basically
guaranteed to produce a correct result, if we ignore method call
adjustments like autoderef.
@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 10, 2025
Copy link
Contributor

@ada4a ada4a left a comment

Choose a reason for hiding this comment

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

I also tried looking into this yesterday, so just chiming in

Co-authored-by: Ada Alakbarova <58857108+ada4a@users.noreply.github.com>
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.

disallowed-methods auto-fixes are unreliable
4 participants