`&raw const` can sometimes do temporary lifetime extension
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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: https://github.com/rust-lang/rust/blob/4eedad312695d773b6e2e17a4f8082660470c101/compiler/rustc_hir_typeck/src/expr.rs#L735-L737
@rustbot labels +T-lang +T-compiler +A-raw-pointers
Meta
Reproducible on the playground with version 1.91.0-nightly (2025-08-23 69b76df90c7ea63b5350)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example on the Rust Playground using the reported nightly version and inspect the comment in compiler/rustc_hir_typeck/src/expr.rs around lines 735-737. Determine whether the temporary lifetime behavior or the compiler comment is incorrect, then align the relevant compiler behavior or documentation and add coverage for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100