rust/library/core/src
bors 077fc26f0a Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwco
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)
2023-05-12 12:04:32 +00:00
..
alloc core is now compilable 2023-04-16 07:20:26 +00:00
array Add an example that depends on is_ascii in a const 2023-05-04 14:46:17 -07:00
ascii Add the basic ascii::Char type 2023-05-03 22:09:33 -07:00
async_iter
cell replace version placeholders 2023-04-28 08:47:55 -07:00
char Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushi 2023-05-04 19:18:21 +02:00
cmp Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
convert Add #[inline] to functions that are never called 2023-05-07 12:41:37 +01:00
ffi Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errors 2023-05-05 18:40:33 +05:30
fmt Limit lifetime of format_args!() with inlined args. 2023-05-09 16:08:40 +02:00
future Remove identity_future from stdlib 2023-05-07 10:52:01 +02:00
hash core is now compilable 2023-04-16 07:20:26 +00:00
intrinsics Auto merge of #110027 - nbdd0121:dieting, r=m-ou-se 2023-05-09 02:41:46 +00:00
iter Revert "Populate effective visibilities in rustc_privacy" 2023-05-08 21:47:44 +00:00
macros enable rust_2018_idioms for doctests 2023-05-07 00:12:29 +03:00
mem Allow the drop_copy lint in some library examples 2023-05-10 19:36:02 +02:00
net Inline SocketAddr methods 2023-05-03 11:56:55 +02:00
num Add #[inline] to functions that are never called 2023-05-07 12:41:37 +01:00
ops enable rust_2018_idioms for doctests 2023-05-07 00:12:29 +03:00
panic Rollup merge of #110110 - lukas-code:display-panic-info, r=JohnTitor 2023-04-14 21:11:12 +02:00
prelude Revert "Remove #[alloc_error_handler] from the compiler and library" 2023-04-25 00:08:35 +02:00
ptr Simplify the implementation of iterators over slices of ZSTs 2023-05-10 13:01:43 -07:00
slice Simplify the implementation of iterators over slices of ZSTs 2023-05-10 13:01:43 -07:00
str Constify [u8]::is_ascii (unstably) 2023-05-04 14:30:20 -07:00
sync replace version placeholders 2023-04-28 08:47:55 -07:00
task Remove useless drop of copy type 2023-05-10 19:36:01 +02:00
unicode Use hex literal for INDEX_MASK 2023-03-21 09:59:47 +01:00
any.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
arch.rs
ascii.rs Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushi 2023-05-04 19:18:21 +02:00
asserting.rs
bool.rs core is now compilable 2023-04-16 07:20:26 +00:00
borrow.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
cell.rs Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum 2023-05-08 04:50:28 +00:00
clone.rs core is now compilable 2023-04-16 07:20:26 +00:00
cmp.rs Add #[inline] to functions that are never called 2023-05-07 12:41:37 +01:00
default.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
error.md
error.rs Bump to latest beta 2023-03-15 08:55:22 -04:00
escape.rs a bit more usize::from 2023-04-30 15:40:54 +02:00
hint.rs Rollup merge of #108416 - pat-nel87:Issue-107957-black_box_docs, r=jyn514 2023-04-26 01:55:49 -05:00
internal_macros.rs rm const traits in libcore 2023-04-16 06:49:27 +00:00
intrinsics.rs Rollup merge of #111408 - TomMD:patch-1, r=workingjubilee 2023-05-10 06:12:15 +02:00
lib.rs Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-se 2023-05-09 20:49:30 +02:00
marker.rs Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum 2023-05-08 04:50:28 +00:00
option.rs Remove unneeded calls to mem::forget 2023-05-06 14:42:07 -07:00
panic.rs Replace libstd, libcore, liballoc in docs. 2022-12-30 14:00:40 +01:00
panicking.rs handle cfg(bootstrap) 2023-04-28 08:47:55 -07:00
pin.rs Beautify pin! docs 2023-03-16 18:03:23 +01:00
primitive_docs.rs Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum 2023-05-08 04:50:28 +00:00
primitive.rs
result.rs replace version placeholders 2023-04-28 08:47:55 -07:00
time.rs Use fmt::Alignment instead of fmt::rt::v1::Alignment. 2023-04-20 18:03:47 +02:00
tuple.rs clean up transmutes in core 2023-05-06 13:28:38 +02:00
unit.rs