-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor: organize loops file into loops module #6693
Conversation
r? @phansch (rust-highfive has picked a reviewer for you, use r? to override) |
r? @flip1995 |
dd007fe
to
bb52d89
Compare
☔ The latest upstream changes (presumably #6698) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
About styles.
@Y-Nak @nahuakang @magurotuna Thanks for your work and cross reviews. I'll do a final check of your PRs once this PR is ready. 👍 |
@Y-Nak @magurotuna @flip1995 Thanks for all the feedback. I've incorporated your comments as much as I can. This branch has also been updated with |
Could you use |
…ck_manual_flatten
…plicit counter to explicit counter loop
…lints to each file
85826ea
to
fee0c89
Compare
☔ The latest upstream changes (presumably #6789) made this pull request unmergeable. Please resolve the merge conflicts. |
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 👍 (except for the conflict)
use rustc_hir::{Block, Expr}; | ||
use rustc_lint::LateContext; | ||
|
||
pub(super) fn check_empty_loop(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) { |
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 think it would be great to unify the name of the main entry functions of all modules to check
.
if is_ref_iterable_type(cx, &args[0]) { | ||
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name); | ||
} |
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 think check_for_loop_arg
should only decide which function to be called according to the method name. The current implementation of check_for_loop_arg
seems to do too many works.
And is_ref_iterable_type
should be called inside lint_iter_method
because it's a quite detailed implementation of explicit_iter_loop
.
if is_ref_iterable_type(cx, &args[0]) { | |
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name); | |
} | |
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name); |
let receiver_ty = cx.typeck_results().expr_ty(&args[0]); | ||
let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]); | ||
if TyS::same_type(receiver_ty, receiver_ty_adjusted) { | ||
explicit_into_iter_loop::check_explicit_into_iter_loop(cx, args, arg); | ||
} else { | ||
let ref_receiver_ty = cx.tcx.mk_ref( | ||
cx.tcx.lifetimes.re_erased, | ||
ty::TypeAndMut { | ||
ty: receiver_ty, | ||
mutbl: Mutability::Not, | ||
}, | ||
); | ||
if TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) { | ||
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name) | ||
} |
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.
ditto.
The implemetation of methods/mod.rs
would be great help to grab the idea.
let receiver_ty = cx.typeck_results().expr_ty(&args[0]); | |
let receiver_ty_adjusted = cx.typeck_results().expr_ty_adjusted(&args[0]); | |
if TyS::same_type(receiver_ty, receiver_ty_adjusted) { | |
explicit_into_iter_loop::check_explicit_into_iter_loop(cx, args, arg); | |
} else { | |
let ref_receiver_ty = cx.tcx.mk_ref( | |
cx.tcx.lifetimes.re_erased, | |
ty::TypeAndMut { | |
ty: receiver_ty, | |
mutbl: Mutability::Not, | |
}, | |
); | |
if TyS::same_type(receiver_ty_adjusted, ref_receiver_ty) { | |
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name) | |
} | |
explicit_into_iter_loop::check_explicit_into_iter_loop(cx, args, arg); | |
explicit_iter_loop::lint_iter_method(cx, args, arg, method_name); |
Thanks a lot for the additional comments, @Y-Nak. I'm unfortunately on sick leave and will not work for the next 3-4 days. If you have time until then, could you please help address the comments? Otherwise I'll address them after :) Cheers. |
Closing in favor of #6824 |
Refactor: organize loops file into loops module (Delegated) `@flip1995` `@nahuakang` closes #6693 r? `@flip1995` As we talked about in the PM of Zulip, this PR is a delegated PR from `@nahuakang.` Changes from the last commit of #6693: 1. Unify the name of the main entries of all modules to check, that was pointed out [here](#6693 (comment)) 2. Simplify ` check_for_loop_arg`, that was pointed out [here](#6693 (comment)) and [here](#6693 (comment)) 3. Resolve conflicts changelog: Refactor `loops.rs` file into `loops` module.
This WIP PR is an attempt to refactor files with many lints into a more accessible structure.
Notes:
declare_clippy_lint!
for lints andimpl LintPass
will reside in theloops/mod.rs
.loops
module will be moved intoloops/utils.rs
and then reexported for the module inmod.rs
.This way,
loops.rs
will be re-arrange into the following structure underclippy_lints/src
:.stderr
file)cargo test
passes locallycargo dev update_lints
cargo dev fmt
Please write a short comment explaining your change (or "none" for internal only changes)
changelog:
Refactor
loops.rs
file intoloops
module.