-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 handling of Deref
in assigning_clones
#12473
Conversation
assigning_clones
Hmmmm... What if instead of outright removing it, we could check for the |
I mostly wanted a hotfix so that this doesn't break so often for people, and my experience from writing IDE plugins is that this stuff around I will take a look at what you sent me, thanks. |
☔ The latest upstream changes (presumably #12511) made this pull request unmergeable. Please resolve the merge conflicts. |
It's a bit more complicated than I thought. This works fine: // #[derive(Clone)]
struct DerefWrapper(DerefInner);
impl Deref for DerefWrapper {
type Target = DerefInner;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for DerefWrapper {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Clone)]
struct DerefInner;
fn clone_into_deref_method(mut a: DerefWrapper, b: DerefInner) {
*a = b.clone();
a.clone_from(&b);
} But it doesn't work when we uncomment the Clone derive on |
So, some of the stuff works, but I'm having some trouble with recognizing if let ty = cx.typeck_results().expr_ty(ref_expr);
let impls_deref = cx.tcx.lang_items().deref_mut_trait().map_or(false, |id| implements_trait(cx, ty, id, &[])); also fires here: fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) {
*mut_thing = Clone::clone(ref_thing);
} because the LHS has type I tried using |
dd78584
to
fe54b5e
Compare
I pushed my code. The second commit shows that some unnecessary |
assigning_clones
Deref
in assigning_clones
Change applicability of `assigning_clones` to `Unspecified` Before we deal with #12473 and the borrow checker errors, I think that it would be better to downgrade this lint, since it can break code. changelog: Change the applicability of `assigning_clones` to `Unspecified` r? `@blyxyas`
Could we remove the special-case first, and then continue this PR to add it back later? Having clippy autofix working code to broken code (even on nightly) feels like a "revert first, improve later" situation to me (as a user). |
I agree, that's why I changed the applicability here. Therefore this lint should no longer autofix. |
☔ The latest upstream changes (presumably #12615) made this pull request unmergeable. Please resolve the merge conflicts. |
Well, it was waiting for a review :) I'll try to rebase it. |
Ahh okay, I guessed that but wasn't sure. Then let's pick a new reviewer: r? clippy |
r? clippy |
Hey @Alexendoo, rustbot has picked you as a new reviewer. If you don't have the time, you can give the PR to me. Just comment |
fe54b5e
to
419277a
Compare
Rebased. It's still WIP, but I'd appreciate some feedback on the approach that I have used here. |
419277a
to
542a228
Compare
542a228
to
e9852cc
Compare
Great, thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
The
assigning_clones
lint had a special case for producing a bit nicer code for mutable references:However, this could break when combined with
Deref
.This PR removes the special case, so that the generated code should work more generally. Later we can improve the detection of
Deref
and put the special case back in a way that does not break code.Fixes: #12437
r? @blyxyas
changelog: [
assigning_clones
]: change applicability toUnspecified
and fix a problem withDeref
.