Uplift clippy::{drop,forget}_{ref,copy} lints#109732
Conversation
|
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
026278d to
5c6fed5
Compare
This comment has been minimized.
This comment has been minimized.
Noratrieb
left a comment
There was a problem hiding this comment.
some cases in rustc, fun (can't wait for clippy to finally work on rustc^^)
5c6fed5 to
e87ceee
Compare
This comment has been minimized.
This comment has been minimized.
d7ccffc to
88a9561
Compare
This comment has been minimized.
This comment has been minimized.
8183b99 to
c3edde2
Compare
c3edde2 to
fad236f
Compare
|
Nominating for T-lang approval, as it seems to be the norm. @rustbot label: +I-lang-nominated |
2e91980 to
7d43485
Compare
This comment has been minimized.
This comment has been minimized.
7d43485 to
e280df5
Compare
|
@jethrogb @raoulstrackx Any objection to landing this with I've confirm in an earlier CI build that the code at least compile. |
|
@raoulstrackx what do you think of this change (compared to master) diff --git a/library/std/src/sys/sgx/waitqueue/mod.rs b/library/std/src/sys/sgx/waitqueue/mod.rs
index 61bb11d9a6f..3e3caa0d00f 100644
--- a/library/std/src/sys/sgx/waitqueue/mod.rs
+++ b/library/std/src/sys/sgx/waitqueue/mod.rs
@@ -202,12 +202,18 @@ pub fn wait_timeout<T, F: FnOnce()>(
pub fn notify_one<T>(
mut guard: SpinMutexGuard<'_, WaitVariable<T>>,
) -> Result<WaitGuard<'_, T>, SpinMutexGuard<'_, WaitVariable<T>>> {
+ // SAFETY: lifetime of the pop() return value is limited to the map
+ // closure (The closure return value is 'static). The underlying
+ // stack frame won't be freed until after the WaitGuard created below
+ // is dropped.
unsafe {
- if let Some(entry) = guard.queue.inner.pop() {
+ let tcs = guard.queue.inner.pop().map(|entry| -> Tcs {
let mut entry_guard = entry.lock();
- let tcs = entry_guard.tcs;
entry_guard.wake = true;
- drop(entry);
+ entry_guard.tcs
+ });
+
+ if let Some(tcs) = tcs {
Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::Single(tcs) })
} else {
Err(guard)
@@ -223,6 +229,9 @@ pub fn notify_one<T>(
pub fn notify_all<T>(
mut guard: SpinMutexGuard<'_, WaitVariable<T>>,
) -> Result<WaitGuard<'_, T>, SpinMutexGuard<'_, WaitVariable<T>>> {
+ // SAFETY: lifetime of the pop() return values are limited to the
+ // while loop body. The underlying stack frames won't be freed until
+ // after the WaitGuard created below is dropped.
unsafe {
let mut count = 0;
while let Some(entry) = guard.queue.inner.pop() {
@@ -230,6 +239,7 @@ pub fn notify_all<T>(
let mut entry_guard = entry.lock();
entry_guard.wake = true;
}
+
if let Some(count) = NonZeroUsize::new(count) {
Ok(WaitGuard { mutex_guard: Some(guard), notified_tcs: NotifiedTcs::All { count } })
} else { |
|
Yes I think that's an improvement! |
Followed up of d36e390 See rust-lang#109732 (comment) for more details. Co-authored-by: Jethro Beekman <jethro@fortanix.com>
|
Alright, I've fixed two other compilation issues: a Redox one (just had to replace the @rustbot ready |
|
@bors r=davidtwco |
|
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
|
☀️ Test successful - checks-actions |
1 similar comment
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (077fc26): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 659.774s -> 659.596s (-0.03%) |
This PR aims at uplifting the
clippy::drop_ref,clippy::drop_copy,clippy::forget_refandclippy::forget_copylints.Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.
drop_refandforget_refThe
drop_refandforget_reflint checks for calls tostd::mem::droporstd::mem::forgetwith a reference instead of an owned value.Example
Explanation
Calling
droporforgeton a reference will only drop the reference itself, which is a no-op. It will not call thedroporforgetmethod on the underlying referenced value, which is likely what was intended.drop_copyandforget_copyThe
drop_copyandforget_copylint checks for calls tostd::mem::forgetorstd::mem::dropwith a value that derives the Copy trait.Example
Explanation
Calling
std::mem::forgetdoes nothing for types that implement Copy since the value will be copied and moved into the function on invocation.Followed the instructions for uplift a clippy describe here: #99696 (review)
cc @m-ou-se (as T-libs-api leader because the uplifting was discussed in a recent meeting)