Files
rust/tests/ui
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
..
2025-04-23 11:08:14 +02:00
2025-03-03 08:52:07 +01:00
2025-04-24 03:20:19 +05:00
2025-04-25 19:13:41 +00:00
2025-02-27 10:26:33 +00:00
2024-12-12 23:36:27 +00:00
2025-03-11 20:26:10 -07:00
2025-02-24 18:48:40 +00:00
2025-04-03 21:41:58 +00:00
2024-12-12 23:36:27 +00:00
2025-04-25 20:50:57 +09:00
2025-04-25 20:50:57 +09:00
2025-01-28 19:35:51 +00:00
2025-04-25 17:02:59 +05:00
2025-04-15 11:14:23 +02:00
2025-04-21 16:16:38 +09:00
2025-02-27 20:02:25 +00:00
2025-04-25 20:50:57 +09:00
2025-04-25 17:02:59 +05:00
2025-03-30 01:32:21 +03:00
2025-04-04 09:44:19 +02:00
2025-03-11 20:26:10 -07:00
2025-04-14 10:36:13 +08:00
2025-01-29 15:45:13 +00:00
2025-03-27 14:11:11 +01:00
2025-04-25 20:50:57 +09:00
2025-02-27 10:26:33 +00:00
2025-04-03 21:41:58 +00:00
2025-02-04 21:42:43 +05:30
2025-04-03 21:41:58 +00:00
2025-04-04 16:32:18 +02:00