-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New lint: borrow_mutable_copy
#13984
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
base: master
Are you sure you want to change the base?
Conversation
a881f75
to
1ac5de7
Compare
1ac5de7
to
f521ce9
Compare
Rebased |
f521ce9
to
9e3a25e
Compare
Rebased |
r? @Clippy |
9e3a25e
to
5a08c09
Compare
Rebased |
5a08c09
to
0de459a
Compare
Rebased |
0de459a
to
7b849af
Compare
@flip1995 Anything else needs to be done? |
I guess the FCP on Zulip. Feel free to start that :) |
410fe93
to
b0e27cc
Compare
eac9c71
to
5309578
Compare
This comment has been minimized.
This comment has been minimized.
5309578
to
bcbd91a
Compare
Rebased |
Any blocker for this one? |
bcbd91a
to
b94323a
Compare
Rebased and updated the Clippy version to 1.88. |
b94323a
to
75b3087
Compare
Rebased and updated the Clippy version to 1.89. |
This comment has been minimized.
This comment has been minimized.
75b3087
to
c6a7a33
Compare
clippy_config/src/conf.rs
Outdated
/// Whether to search for mutable borrows of freshly copied data in tests. | ||
#[lints(copy_then_borrow_mut)] | ||
check_copy_then_borrow_mut_in_tests: bool = true, |
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.
Not quite sure how much I agree with a config option on the premise of it being used without examples to show for it.
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 have the impression that we don't have any example showing how to set a boolean configuration option to true
or false
. Or is that not what you mean?
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'm talking about llogiq's reasoning for this config option.
/// }; | ||
/// ``` | ||
#[clippy::version = "1.89.0"] | ||
pub COPY_THEN_BORROW_MUT, |
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 find the name to be very general despite only operating on a very specific case. I don't know what to do here, but it just feels off to me. WDYT? Leave it as-is or nah? Are there any cases this could be expanded to lint in the future?
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 don't have a better idea, and no better name has been suggested during the FCP. Do you have an idea for a better name?
I'm not sure this lint can be expanded, it is quite specific.
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.
Maybe mutable_borrow_of_copy
? This flows well with #[allow(mutable_borrow_of_copy)]
.
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.
That sounds pretty good imo?
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.
Done
expr.span, | ||
"mutable borrow of a value which was just copied", | ||
|diag| { | ||
diag.multipart_suggestion( |
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 feel like if we're making a suggestion with the idea this is never what the user intended, then this should be deny
-by-default, no? WDYT?
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.
Ok, let's aim for correctness
then. We'll see if questions arise during the next beta cycle.
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.
After thinking more about it, I'd tend to make it suspicious
. What if the copied value is used as a template?
I'll have to think more about it.
@rustbot author
I'll do two successive pushes: one to rebase on |
03e6eac
to
ec135bc
Compare
copy_then_borrow_mut
borrow_mutable_copy
Reminder, once the PR becomes ready for a review, use |
ec135bc
to
db0bb45
Compare
I've put it back into suspicious, with |
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
db0bb45
to
82bb1de
Compare
Rebased |
This detects when the result of a block, with a
Copy
type, is borrowed mutably. The user might not be aware that using a block will borrow a copy instead of the value expression itself.changelog: [
borrow_mutable_copy
]: new lintClose #13967