-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
I'm not sure if this is a bug or not.
struct LoudDrop;
impl Drop for LoudDrop {
fn drop(&mut self) {
println!("drop");
}
}
fn main() {
let _ptr = &raw const Box::new((LoudDrop,)).0;
println!("after let");
}
This code compiles, and prints after let
, then prints drop
. This contradicts the following comment in the compiler, which says that the above code creates an immediately-dangling pointer:
rust/compiler/rustc_hir_typeck/src/expr.rs
Lines 735 to 737 in 4eedad3
// This is maybe too permissive, since it allows | |
// `let u = &raw const Box::new((1,)).0`, which creates an | |
// immediately dangling raw pointer. |
@rustbot labels +T-lang +T-compiler +A-raw-pointers
Meta
Reproducible on the playground with version 1.91.0-nightly (2025-08-23 69b76df90c7ea63b5350)
Metadata
Metadata
Assignees
Labels
A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-temporary-lifetime-extensionArea: temporary lifetime extensionArea: temporary lifetime extensionC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team