rust/library/alloc/src
许杰友 Jieyou Xu (Joe) 7112951caa
Rollup merge of #138303 - DiuDiu777:rc-fix, r=Mark-Simulacrum
Fix Ptr inconsistency in {Rc,Arc}

### PR Description
This pr aims to address the problem discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Inconsistency.20in.20.7BRc.2CArc.7D's.20ptr.20requirements/with/504259637).

### Problem Clarification
As this post presents, the `{Rc, Arc}::{in/de-crement_strong_count_/in}` do not limit the layout of the memory that `ptr` points to, while internally `Rc::from_raw_in` is called directly.

UB doesn't just appear when the strong count is decremented to zero. Miri also detects the UB of `out-of-bounds pointer use` when increment strong count is called on a pointer with an incorrect layout(shown as below).

```rust
use std::rc::Rc;
#[repr(align(8))]
struct Aligned8(u64);

#[repr(align(16))]
struct Aligned16(u64);

fn main() {
    let rc: Rc<Aligned8> = Rc::new(Aligned8(42));
    let raw_ptr = Rc::into_raw(rc);

    unsafe {
        Rc::increment_strong_count(raw_ptr as *const Aligned16);
    }
}
```

Miri output:
```
error: Undefined Behavior: out-of-bounds pointer use: expected a pointer to 32 bytes of memory, but got alloc954 which is only 24 bytes from the end of the allocation
```
2025-03-16 09:40:06 +08:00
..
boxed library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
collections Rollup merge of #138161 - HeroicKatora:heap-peek-mut-refresh, r=dtolnay 2025-03-12 08:06:46 +01:00
ffi Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
raw_vec Add comments 2025-03-07 19:11:13 +00:00
vec Stabilize const_vec_string_slice 2025-03-08 17:03:52 +01:00
alloc.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
borrow.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
boxed.rs intrinsics: remove unnecessary leading underscore from argument names 2025-03-12 08:04:09 +01:00
bstr.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
fmt.rs Added struct fmt::FormattingOptions 2024-12-05 21:48:01 +01:00
lib.miri.rs add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
lib.rs Rollup merge of #136642 - bjorn3:separate_alloctest_crate, r=cuviper 2025-03-08 01:27:20 -05:00
macros.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
rc.rs fix copy typo 2025-03-10 16:46:18 +08:00
slice.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
str.rs Fully test the alloc crate through alloctests 2025-03-07 19:11:13 +00:00
string.rs Stabilize const_vec_string_slice 2025-03-08 17:03:52 +01:00
sync.rs fix copy typo 2025-03-10 16:46:18 +08:00
task.rs Stabilize noop_waker 2024-12-05 14:14:17 -08:00