rust/library/core/src/slice
bors a932eb36f8 Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross
Implement a lint for implicit autoref of raw pointer dereference - take 2

*[t-lang nomination comment](https://github.com/rust-lang/rust/pull/123239#issuecomment-2727551097)*

This PR aims at implementing a lint for implicit autoref of raw pointer dereference, it is based on #103735 with suggestion and improvements from https://github.com/rust-lang/rust/pull/103735#issuecomment-1370420305.

The goal is to catch cases like this, where the user probably doesn't realise it just created a reference.

```rust
pub struct Test {
    data: [u8],
}

pub fn test_len(t: *const Test) -> usize {
    unsafe { (*t).data.len() }  // this calls <[T]>::len(&self)
}
```

Since #103735 already went 2 times through T-lang, where they T-lang ended-up asking for a more restricted version (which is what this PR does), I would prefer this PR to be reviewed first before re-nominating it for T-lang.

----

Compared to the PR it is as based on, this PR adds 3 restrictions on the outer most expression, which must either be:
   1. A deref followed by any non-deref place projection (that intermediate deref will typically be auto-inserted)
   2. A method call annotated with `#[rustc_no_implicit_refs]`.
   3. A deref followed by a `addr_of!` or `addr_of_mut!`. See bottom of post for details.

There are several points that are not 100% clear to me when implementing the modifications:
 - ~~"4. Any number of automatically inserted deref/derefmut calls." I as never able to trigger this. Am I missing something?~~ Fixed
 - Are "index" and "field" enough?

----

cc `@JakobDegen` `@WaffleLapkin`
r? `@RalfJung`

try-job: dist-various-1
try-job: dist-various-2
2025-04-28 08:25:23 +00:00
..
iter rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
sort Move select_unpredictable to the hint module 2025-04-13 01:34:25 +01:00
ascii.rs Remove #[cfg(not(test))] gates in core 2025-03-06 13:21:59 -08:00
cmp.rs Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
index.rs add const_eval_select macro to reduce redundancy 2024-11-05 09:26:08 +01:00
iter.rs Optimize setting the slice to empty in slice Iter 2025-04-04 15:57:41 +01:00
memchr.rs library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
mod.rs Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
raw.rs library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
rotate.rs library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
specialize.rs Remove size_of == 1 case from fill specialization. 2021-08-09 19:25:28 +02:00