Fix redundant_closure_for_method_calls suggesting an ambiguous method path - #17750
Itz-Agasta wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. |
|
btw i tried the turbofish route first ( doing it right means writing a scope-aware type printer ig, which basically duplicates rustc internals. Too much churn for this patch in my opinion :( now idk maybe that will be a better way to handel as this pr is somewhat patch type. |
path `get_path_to_ty` discarded the generic arguments of an inherent impl's self type, so a method defined by several impls differing only in those arguments was suggested as a bare `Adt::method` path. Applying the suggestion fails with E0034 because a path carries no receiver to disambiguate. Detect that case and make no suggestion. Names defined by a single inherent impl are unaffected.
4cc5fa7 to
5e397df
Compare
|
Lintcheck changes for 5e397df
This comment will be updated if you push new changes |
|
thanks @CommanderStorm both applied and squashed, pls have a look btw yk something is bothering me a bit with the design of "don't suggest when ambiguous"....like lets say user has this fn f(x: Option<Option<&i32>>) -> Option<Option<i32>> {
x.map(|o| o.copied())
}they won't get any complaint, but the closure is really redundant imo. i personally feel clippy should suggest the cleaner version: x.map(Option::<&i32>::copied)i tried generating the turbofish automatically but its kinda hard.... the generic args need to be nameable from the call site, and so im kinda confused.... what y think? ps: hey frank, i was in this year's gsoc with osm, working on the geocoder nominatim. saw u there as a mentor, nice to see u here too :) |
So the general preference is that bad suggestions are less good than false positives than false negatives. We don't need to do this this way though as you noted.
I would need to look into this. I am like 60% sure that that should already exist somewhere. But the good thing is that those are also not required. (assuming this is actually not done yet) We don't need to be docs:
|
Thank you for your work! ❤️ (For the others, here is the blog post: https://nominatim.org/2026/09/01/gsoc-2026-nominatim-categories.html ) |
copied is defined by an inherent impl on both
Option<&T>&Option<&mut T>, so the suggested Option::copied path has nothing to pick between them and fails with E0034. It reduces to:The cause is in
get_path_to_ty, where the Adt arm dropped the impl's generic arguments while the Ref/Slice/Tuple/Dynamic arms next to it instantiate theirs, so impl<T: Copy> Option<&T> printed as plain Option....I checked it, It isn't option specific: any type with two inherent impls differing in the shape of a generic argument hits it, i mean Option::cloned, Result::copied and Result::cloned all do.fixes #17730
changelog: Fix [
redundant_closure_for_method_calls] suggesting a method path that does not resolve