rust/compiler
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
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
rustc_arena Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_ast Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr 2025-04-25 12:27:16 +00:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr 2025-04-25 12:27:16 +00:00
rustc_ast_passes Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_ast_pretty Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau 2025-04-27 16:08:59 +02:00
rustc_attr_data_structures Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_attr_parsing Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr 2025-04-25 12:27:16 +00:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Rollup merge of #140257 - amandasystems:housecleaning, r=wesleywiser 2025-04-25 07:50:27 +02:00
rustc_builtin_macros Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_codegen_cranelift Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
rustc_codegen_gcc Merge commit '4f83a4258d' into subtree-update_cg_gcc_2025-04-25 2025-04-25 10:44:19 -04:00
rustc_codegen_llvm Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_codegen_ssa Rollup merge of #140086 - ChrisDenton:backoff, r=petrochenkov 2025-04-26 07:13:07 +02:00
rustc_const_eval Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_data_structures Update !DynSend and !DynSync platform impls 2025-04-21 21:23:32 -07:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_error_codes stabilize naked_functions 2025-04-20 11:18:38 +02:00
rustc_error_messages update cfgs 2025-04-09 12:29:59 +01:00
rustc_errors Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_expand Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_feature Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
rustc_fluent_macro Replace proc_macro::SourceFile by Span::{file, local_file}. 2025-04-11 15:07:08 +02:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_hir_analysis Auto merge of #139646 - lcnr:default-is-fully-concrete, r=BoxyUwU 2025-04-27 01:59:43 +00:00
rustc_hir_pretty Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau 2025-04-27 16:08:59 +02:00
rustc_hir_typeck remove unnecessary match 2025-04-26 02:05:31 +00:00
rustc_incremental Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
rustc_index Add copy_within to IndexSlice 2025-04-15 10:44:28 -04:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
rustc_interface session: Cleanup CanonicalizedPath::new 2025-04-26 18:42:15 +03:00
rustc_lexer Replace rustc_lexer/unescape with rustc-literal-escaper crate 2025-04-04 14:44:45 +02:00
rustc_lint Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
rustc_lint_defs Update lint-docs to default to Rust 2024 2025-04-26 14:08:58 -07:00
rustc_llvm Rollup merge of #140253 - SergioGasquez:feat/xtensa-asm-printer, r=cuviper 2025-04-26 07:13:08 +02:00
rustc_log Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_macros Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_metadata Rollup merge of #140086 - ChrisDenton:backoff, r=petrochenkov 2025-04-26 07:13:07 +02:00
rustc_middle Use search_for_cycle_permutation to look for variances_of 2025-04-27 09:38:18 +02:00
rustc_mir_build Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_mir_dataflow Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_mir_transform Auto merge of #140288 - Zalathar:new-executor, r=jieyouxu 2025-04-26 22:33:56 +00:00
rustc_monomorphize Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_next_trait_solver Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors 2025-04-26 16:12:33 +02:00
rustc_parse Rollup merge of #140272 - Kivooeo:new-fix-four, r=est31 2025-04-26 07:13:08 +02:00
rustc_parse_format Update rustc-literal-escaper version to 0.0.2 2025-04-04 22:26:10 +02:00
rustc_passes Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
rustc_pattern_analysis Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_privacy convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
rustc_query_impl Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_query_system Auto merge of #139756 - Zoxc:out-of-order-dep-graph, r=oli-obk 2025-04-25 15:38:58 +00:00
rustc_resolve Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_sanitizers Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_serialize Zero the buffer passed from write_with 2025-04-25 07:14:27 +02:00
rustc_session session: Cleanup CanonicalizedPath::new 2025-04-26 18:42:15 +03:00
rustc_smir convert some GenericArg to Term 2025-04-26 02:05:31 +00:00
rustc_span Auto merge of #123239 - Urgau:dangerous_implicit_autorefs, r=jdonszelmann,traviscross 2025-04-28 08:25:23 +00:00
rustc_symbol_mangling Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
rustc_target Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_trait_selection Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors 2025-04-26 16:12:33 +02:00
rustc_traits re-use sized fast path 2025-04-09 10:42:26 +00:00
rustc_transmute transmutability: Support char, NonZeroXxx 2025-04-25 12:55:50 -07:00
rustc_ty_utils Rollup merge of #140202 - est31:let_chains_feature_compiler, r=lcnr 2025-04-25 07:50:25 +02:00
rustc_type_ir Rollup merge of #140320 - lcnr:wf-use-term, r=compiler-errors 2025-04-26 16:12:33 +02:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00