rust/library/std/src/sys
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
..
alloc use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
anonymous_pipe Mv os-specific trait impl of Pipe* into std::os::* 2025-03-14 01:03:56 +11:00
args use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
env use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
fd Rollup merge of #139667 - 1c3t3a:remove-no-sanitize, r=m-ou-se 2025-04-17 00:16:21 +02:00
fs use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
io Trusty: Implement write_vectored for stdio 2025-03-27 16:49:30 -07:00
net use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
os_str Specialize OsString::push for strings 2025-02-28 13:42:31 -08:00
pal Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
path Use with_native_path for Windows 2025-04-11 18:02:03 +00:00
personality Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboet 2025-03-17 05:47:49 -04:00
process use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
random use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
stdio Rollup merge of #139517 - Ayush1325:uefi-cmd-stdin-null, r=joboet 2025-04-15 15:47:25 +10:00
sync use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
thread_local use generic Atomic type where possible 2025-04-27 02:18:08 +03:00
backtrace.rs Improve comments for the default backtrace printer 2024-12-04 20:54:37 -05:00
cmath.rs std: make cmath functions safe 2025-03-29 13:08:18 +01:00
env_consts.rs Move zkVM constants into sys::env_consts 2025-04-21 21:05:04 -07:00
exit_guard.rs Attempt to fix CI 2024-07-08 09:19:25 -05:00
mod.rs Move sys::pal::os::Env into sys::env 2025-04-21 20:56:43 -07:00