Skip to content

unsafe core::ptr::read(p) shouldn't compile using #![deny(unsafe_code)] #158033

Description

@kevin-valerio

core::ptr::read(p), unsafe, shouldn't compile under #![deny(unsafe_code)]

#![feature(reborrow)]
#![deny(unsafe_code)]
#![allow(dead_code)]

use core::marker::Reborrow;

struct Thing<'a> { p: &'a mut i32 }
impl<'a> Reborrow for Thing<'a> {}

fn takes(_: Thing<'_>) {}

fn main() {
    let mut x = 0;
    let thing = Thing { p: &mut x };
    let y: i32 = 123;

    takes({
        let p: *const i32 = &y;
        core::hint::black_box(core::ptr::read(p));
        thing
    });
}

Compilation passes:

$ rustc +nightly-2026-05-10 --edition=2021 repro.rs -o repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-reborrow`#![feature(reborrow)]`; see #145612I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions