Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @llogiq (or someone else) some time within the next two weeks. 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 (
Why was this reviewer chosen?The reviewer was selected based on:
|
3e17354 to
fb1530b
Compare
|
Lintcheck changes for 9193dc8
This comment will be updated if you push new changes |
fb1530b to
cf78d0d
Compare
This comment has been minimized.
This comment has been minimized.
cf78d0d to
aa82ebb
Compare
I think that for now I do ignore all expansions from macros (though that probably only involves locally expanded span from macros). However, I would be happy to add some testcases for external macros - tho maybe I would need some direction (example) somewhere to see how it's supposed to be done |
This comment has been minimized.
This comment has been minimized.
d9b58f5 to
6ceb8de
Compare
This comment has been minimized.
This comment has been minimized.
|
After a longer time off, I will try to fixup this PR and see if tests pass properly, then hopefully can finish off remaining suggestions |
6ceb8de to
01e0753
Compare
This comment has been minimized.
This comment has been minimized.
3838565 to
ca049d0
Compare
|
I want to rebase all the commits again later just so there are not 13 of them, but I wanted to ask for a re-review now that some time has passed. Would it be OK if we kept the lint smaller-scoped for now, and I could focus on extending it later? Do you think the scope is sufficient for it to be useful? Thanks a bunch! cc @blyxyas just for the info, I would love as many opinions as I can get :> |
This comment has been minimized.
This comment has been minimized.
e7b8e4a to
8be86f9
Compare
This comment has been minimized.
This comment has been minimized.
8be86f9 to
32e80ba
Compare
| ControlFlow::<(), Descend>::Continue(Descend::No) | ||
| }, | ||
| rustc_hir::ExprKind::MethodCall(method_name, receiver, args, span) | ||
| if method_name.ident.as_str() == "clone" |
There was a problem hiding this comment.
rustc_hir::ExprKind::MethodCall(name, receiver, args, span)
if args.is_empty()
&& let rustc_hir::ExprKind::Path(qpath) = receiver.kind
&& let Some(hir_id) = qpath.res_local_id()
&& clippy_utils::is_lang_item_or_ctor(cx, hir_id.owner.to_def_id(), LangItem::Clone) =>I also tried this:
if args.is_empty()
&& let rustc_hir::ExprKind::Path(qpath) = receiver.kind
&& let Some(hir_id) = qpath.res_local_id()
&& let def_id = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id))
&& clippy_utils::is_lang_item_or_ctor(cx, def_id.def_id().to_def_id(), LangItem::Clone) =>I tried something like this (experimented with name.hir_id.owner, and more... however I am not able quite pinpoint the approach, even from examples in other lints. May I ask for some extra direction?
There was a problem hiding this comment.
What I'm talking about is, this code would turn out true with the following code:
#[derive(Clone)]
struct A;
struct B;
trait MyClone {
fn clone(&self) -> Self;
}
impl MyClone for B {
// ...
}
pub fn foo(item: &A) { // <- We save &A as candidate
let x: B = B;
x.clone(); // <- Technically called "clone"
}Now, if I'm reading the emit lint function correctly, seems that if the HirId of the clone call does not refer to item, this does not actually lint. We should move that check upwards
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
74d7fe9 to
22b05ac
Compare
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com> # Conflicts: # clippy_lints/src/lib.rs
Signed-off-by: medzernik <medzernik@medzernik.dev>
Signed-off-by: medzernik <medzernik@medzernik.dev>
Signed-off-by: medzernik <medzernik@medzernik.dev>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Co-authored-by: Alejandra González <blyxyas@goose.love>
Co-authored-by: Alejandra González <blyxyas@goose.love>
Co-authored-by: Alejandra González <blyxyas@goose.love>
Co-authored-by: Alejandra González <blyxyas@goose.love>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
9bd5be7 to
742a577
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Signed-off-by: medzernik <medzernik@medzernik.dev>
Signed-off-by: medzernik <medzernik@medzernik.dev>
3e17a70 to
b4c5cc6
Compare
Signed-off-by: medzernik <medzernik@medzernik.dev>
675007f to
c710e47
Compare
Signed-off-by: medzernik <medzernik@medzernik.dev>
c710e47 to
9193dc8
Compare
View all comments
Co-Authored by: @matej-almasi almasi.mato@gmail.com
changelog: [
fn_param_ref_cloned]: added a lint. Fixes #2074This is a partial WIP PR - We need some feedback (this is also our first contribution).
Added a lint to check whether you are not cloning a reference when passed into a function. Per best practices the caller should decide whether to clone data, and not hide the operation within a function.