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
[fix] [redundant_closure_for_method_calls
] Suggest relative paths for local modules
#11370
[fix] [redundant_closure_for_method_calls
] Suggest relative paths for local modules
#11370
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Centri3 (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Will review later, but can you extract |
@Centri3 Thanks for the suggestion! I moved |
clippy_utils/src/lib.rs
Outdated
// mod_a::sym :: :: | ||
// (looking at mod_c) | ||
EitherOrBoth::Right(r) => { | ||
if let DefPathData::TypeNs(_) = r.data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably be better as a guard instead (same with the above)
clippy_utils/src/lib.rs
Outdated
} | ||
// Otherwise ignore | ||
}, | ||
EitherOrBoth::Both(l, r) => match (l.data, r.data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaict, this can be simplified by pushing l
and r
if they're TypeNs
.
clippy_utils/src/lib.rs
Outdated
| rustc_ty::Dynamic(..) | ||
| rustc_ty::Never | ||
| rustc_ty::RawPtr(_) | ||
| rustc_ty::Ref(..) | ||
| rustc_ty::Slice(_) | ||
| rustc_ty::Tuple(_) => format!("<{}>", EarlyBinder::bind(ty).instantiate(tcx, args)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to handle these too, I'm pretty sure. This should recursively go through each nested type and get the relative path for each ADT.
Not an issue for the lint in question, but if somebody uses this on something like (super::A, super::super::B)
it'll still be broken afaik.
☔ The latest upstream changes (presumably #11398) made this pull request unmergeable. Please resolve the merge conflicts. |
Seeing as Catherine is pretty busy (judging from her GitHub contribution graph) so I'll take from now on some of her reviews. r? @blyxyas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good first iteration.
clippy_utils/src/lib.rs
Outdated
/// | ||
/// Returned path can be either absolute (for methods defined non-locally), or relative (for local | ||
/// methods). | ||
pub fn get_ufcs_type_name<'tcx>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could have a much more descriptive name.
pub fn get_ufcs_type_name<'tcx>( | |
pub fn path_from_caller_to_method_type<'tcx>( |
Or something like that.
tests/ui/eta.rs
Outdated
@@ -399,3 +399,56 @@ fn _closure_with_types() { | |||
let _ = f2(|x: u32| f(x)); | |||
let _ = f2(|x| -> u32 { f(x) }); | |||
} | |||
|
|||
// https://github.com/rust-lang/rust-clippy/issues/10854 | |||
mod redundant_closure_for_method_calls_resolve_suggested_paths_to_relative { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a module name so long, I think it would be best to name it issue_10854 and explain in a doc comment what it is supposed to test .
clippy_utils/src/lib.rs
Outdated
} | ||
|
||
repeat(String::from("super")).take(go_up_by).chain(path).join("::") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing the result, I think that we should maybe cap go_up_by
at like 2, AFAIK people prefer having crate::a::b
than super::super::super::super::b
in their codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this idea, implemented!
@modelflat Are you there? |
@blyxyas yep, hopefully I'll get some time to work on it in December |
@modelflat Would you like for other person to finish this contribution? |
0079622
to
7105961
Compare
@blyxyas Hi! Sorry I completely forgot about this one. I've got some spare time now so can work on it. Pls take a look at the newest changes when you have time, I resolved conflicts and addressed your comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Could you squash these commits? ฅ*•ω•*ฅ♡
dc4146e
to
0b7dd75
Compare
Fixes rust-lang#10854. Co-authored-by: Alejandra González <blyxyas@gmail.com>
0b7dd75
to
b3d5377
Compare
@bors r+ |
…-for-method-calls, r=blyxyas [fix] [`redundant_closure_for_method_calls`] Suggest relative paths for local modules Fixes #10854. Currently, `redundant_closure_for_method_calls` suggest incorrect paths when a method defined on a struct within inline mod is referenced (see the description in the aforementioned issue for an example; also see [this playground link](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=f7d3c5b2663c9bd3ab7abdb0bd38ee43) for the current-version output for the test cases added in this PR). It will now try to construct a relative path path to the module and suggest it instead. changelog: [`redundant_closure_for_method_calls`] Fix incorrect path suggestions for types within local modules
💔 Test failed - checks-action_test |
@bors retry |
…-for-method-calls, r=blyxyas [fix] [`redundant_closure_for_method_calls`] Suggest relative paths for local modules Fixes #10854. Currently, `redundant_closure_for_method_calls` suggest incorrect paths when a method defined on a struct within inline mod is referenced (see the description in the aforementioned issue for an example; also see [this playground link](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=f7d3c5b2663c9bd3ab7abdb0bd38ee43) for the current-version output for the test cases added in this PR). It will now try to construct a relative path path to the module and suggest it instead. changelog: [`redundant_closure_for_method_calls`] Fix incorrect path suggestions for types within local modules
💥 Test timed out |
@bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
1 similar comment
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request. |
Fixes #10854.
Currently,
redundant_closure_for_method_calls
suggest incorrect paths when a method defined on a struct within inline mod is referenced (see the description in the aforementioned issue for an example; also see this playground link for the current-version output for the test cases added in this PR). It will now try to construct a relative path path to the module and suggest it instead.changelog: [
redundant_closure_for_method_calls
] Fix incorrect path suggestions for types within local modules