rust/src
bors b85026b15b Auto merge of #18252 - ShoyuVanilla:issue-15799, r=Veykril
fix: Do not consider mutable usage of deref to `*mut T` as deref_mut

Fixes #15799

We are doing some heuristics for deciding whether the given deref is deref or deref_mut here;

5982d9c420/crates/hir-ty/src/infer/mutability.rs (L182-L200)

But this heuristic is erroneous if we are dereferencing to a mut ptr and normally those cases are filtered out here as builtin;

5982d9c420/crates/hir-ty/src/mir/lower/as_place.rs (L165-L177)

Howerver, this works not so well if the given dereferencing is double dereferencings like the case in the #15799.

```rust
struct WrapPtr(*mut u32);

impl core::ops::Deref for WrapPtr {
    type Target = *mut u32;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn main() {
    let mut x = 0u32;
    let wrap = WrapPtr(&mut x);
    unsafe {
        **wrap = 6;
    }
}
```

Here are two - outer and inner - dereferences here, and the outer dereference is marked as deref_mut because there is an assignment operation.
And this deref_mut marking is propagated into the inner dereferencing.
In the later MIR lowering, the outer dereference is filtered out as it's expr type is `*mut u32`, but the expr type in the inner dereference is an ADT, so this false-mutablility is not filtered out.

This PR cuts propagation of this false mutablilty chain if the expr type is mut ptr.
Since this happens before the resolve_all, it may have some limitations when the expr type is determined as mut ptr at the very end of inferencing, but I couldn't find simple fix for it 🤔
2024-10-14 12:07:31 +00:00
..
bootstrap Rollup merge of #131351 - jieyouxu:yeet-the-valgrind, r=Kobzol 2024-10-07 11:10:54 -07:00
ci Rollup merge of #131230 - GuillaumeGomez:no-sandbox, r=notriddle 2024-10-04 15:42:55 +02:00
doc Update books 2024-10-07 13:01:01 -04:00
etc bootstrap: Consolidate editor LSP setup 2024-10-03 15:22:44 +01:00
gcc@fd3498bff0 Update GCC version 2024-09-06 16:01:46 +02:00
librustdoc Add comment to describe camelcase line break 2024-10-07 13:27:50 -07:00
llvm-project@dd46457da7 Update to LLVM 19.1.1 2024-10-05 21:10:04 +08:00
rustdoc-json-types rustdoc: update ProcMacro docs section on helper attributes 2024-09-27 14:34:48 -04:00
tools Auto merge of #18252 - ShoyuVanilla:issue-15799, r=Veykril 2024-10-14 12:07:31 +00:00
README.md
stage0 Bump stage0 2024-09-22 19:04:19 -04:00
version Bump to 1.83 2024-08-30 19:58:04 +01:00

This directory contains some source code for the Rust project, including:

  • The bootstrapping build system
  • Various submodules for tools, like cargo, tidy, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.