mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
077fc26f0a
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. 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_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting) |
||
---|---|---|
.. | ||
diagnostics | ||
match | ||
migrations | ||
optimization | ||
run_pass | ||
array_subslice.rs | ||
array_subslice.stderr | ||
arrays-completely-captured.rs | ||
arrays-completely-captured.stderr | ||
bad-pattern.rs | ||
bad-pattern.stderr | ||
by_value.rs | ||
by_value.stderr | ||
capture-analysis-1.rs | ||
capture-analysis-1.stderr | ||
capture-analysis-2.rs | ||
capture-analysis-2.stderr | ||
capture-analysis-3.rs | ||
capture-analysis-3.stderr | ||
capture-analysis-4.rs | ||
capture-analysis-4.stderr | ||
capture-disjoint-field-struct.rs | ||
capture-disjoint-field-struct.stderr | ||
capture-disjoint-field-tuple.rs | ||
capture-disjoint-field-tuple.stderr | ||
capture-enum-field.rs | ||
capture-enums.rs | ||
capture-enums.stderr | ||
deep-multilevel-struct.rs | ||
deep-multilevel-struct.stderr | ||
deep-multilevel-tuple.rs | ||
deep-multilevel-tuple.stderr | ||
destructure_patterns.rs | ||
destructure_patterns.stderr | ||
feature-gate-capture_disjoint_fields.rs | ||
feature-gate-capture_disjoint_fields.stderr | ||
filter-on-struct-member.rs | ||
filter-on-struct-member.stderr | ||
issue_88118.rs | ||
issue-87378.rs | ||
issue-87378.stderr | ||
issue-87987.rs | ||
issue-87987.stderr | ||
issue-88118-2.rs | ||
issue-88118-2.stderr | ||
issue-88476.rs | ||
issue-88476.stderr | ||
issue-89606.rs | ||
issue-90465.fixed | ||
issue-90465.rs | ||
issue-90465.stderr | ||
issue-92724-needsdrop-query-cycle.rs | ||
move_closure.rs | ||
move_closure.stderr | ||
multilevel-path-1.rs | ||
multilevel-path-1.stderr | ||
multilevel-path-2.rs | ||
multilevel-path-2.stderr | ||
nested-closure.rs | ||
nested-closure.stderr | ||
path-with-array-access.rs | ||
path-with-array-access.stderr | ||
preserve_field_drop_order2.rs | ||
preserve_field_drop_order2.twenty_eighteen.run.stdout | ||
preserve_field_drop_order2.twenty_twentyone.run.stdout | ||
preserve_field_drop_order.rs | ||
preserve_field_drop_order.stderr | ||
repr_packed.rs | ||
repr_packed.stderr | ||
simple-struct-min-capture.rs | ||
simple-struct-min-capture.stderr | ||
unsafe_ptr.rs | ||
unsafe_ptr.stderr | ||
wild_patterns.rs | ||
wild_patterns.stderr |