mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +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) |
||
---|---|---|
.. | ||
coherence | ||
alias_eq_cant_be_furthur_normalized.rs | ||
alias_eq_dont_use_normalizes_to_if_substs_eq.rs | ||
alias_eq_dont_use_normalizes_to_if_substs_eq.stderr | ||
alias_eq_simple.rs | ||
alias_eq_substs_eq_not_intercrate.rs | ||
alias_eq_substs_eq_not_intercrate.stderr | ||
alias-bound-unsound.rs | ||
alias-bound-unsound.stderr | ||
alias-eq-in-canonical-response.rs | ||
alias-sub.rs | ||
async.fail.stderr | ||
async.rs | ||
auto-with-drop_tracking_mir.fail.stderr | ||
auto-with-drop_tracking_mir.rs | ||
borrowck-error.rs | ||
borrowck-error.stderr | ||
builtin-fn-must-return-sized.rs | ||
builtin-fn-must-return-sized.stderr | ||
canonical-int-var-eq-in-response.rs | ||
canonical-ty-var-eq-in-response.rs | ||
cast-checks-handling-projections.rs | ||
closure-inference-guidance.rs | ||
const-param-placeholder.fail.stderr | ||
const-param-placeholder.rs | ||
deduce-ty-from-object.rs | ||
destruct.rs | ||
dont-elaborate-for-projections.rs | ||
elaborate-item-bounds.rs | ||
equating-projection-cyclically.rs | ||
equating-projection-cyclically.stderr | ||
exponential-trait-goals.rs | ||
exponential-trait-goals.stderr | ||
float-canonical.rs | ||
fn-trait-closure.rs | ||
fn-trait.rs | ||
fn-trait.stderr | ||
generator.fail.stderr | ||
generator.rs | ||
higher-ranked-dyn-bounds.rs | ||
int-var-alias-eq.rs | ||
int-var-is-send.rs | ||
iter-filter-projection.rs | ||
lazy-nested-obligations-1.rs | ||
lazy-nested-obligations-2.rs | ||
lazy-nested-obligations-3.rs | ||
more-object-bound.rs | ||
more-object-bound.stderr | ||
negative-coherence-bounds.rs | ||
negative-coherence-bounds.stderr | ||
nested-alias-bound.rs | ||
nested-obligations-with-bound-vars-gat.rs | ||
normalize-param-env-1.rs | ||
normalize-param-env-2.rs | ||
normalize-param-env-3.rs | ||
normalizes_to_ignores_unnormalizable_candidate.rs | ||
normalizes_to_ignores_unnormalizable_candidate.self_infer.stderr | ||
object-unsafety.rs | ||
object-unsafety.stderr | ||
param-candidate-doesnt-shadow-project.rs | ||
param-discr-kind.rs | ||
pointee.rs | ||
pointer-like.rs | ||
pointer-like.stderr | ||
prefer-candidate-no-constraints.rs | ||
prefer-param-env-on-ambiguity.rs | ||
projection-discr-kind.rs | ||
projection-discr-kind.stderr | ||
provisional-result-done.rs | ||
recursive-self-normalization-2.rs | ||
recursive-self-normalization-2.stderr | ||
recursive-self-normalization.rs | ||
recursive-self-normalization.stderr | ||
runaway-impl-candidate-selection.rs | ||
runaway-impl-candidate-selection.stderr | ||
specialization-transmute.rs | ||
specialization-transmute.stderr | ||
specialization-unconstrained.rs | ||
specialization-unconstrained.stderr | ||
stall-num-var-auto-trait.fallback.stderr | ||
stall-num-var-auto-trait.rs | ||
temporary-ambiguity.rs | ||
try-example.rs | ||
two-projection-param-candidates-are-ambiguous.rs | ||
two-projection-param-candidates-are-ambiguous.stderr | ||
unsafe-auto-trait-impl.rs | ||
unsize-good.rs | ||
upcast-right-substs.rs | ||
upcast-wrong-substs.rs | ||
upcast-wrong-substs.stderr |