Skip to content

Panics in destructors can cause the return value to be leaked #47949

@arielb1

Description

@arielb1

STR

struct NoisyDrop; impl Drop for NoisyDrop { fn drop(&mut self) { println!("dropping a NoisyDrop"); } } impl NoisyDrop { fn new() -> Self { println!("creating a NoisyDrop"); NoisyDrop } } struct PanickyDrop; impl Drop for PanickyDrop { fn drop(&mut self) { panic!() } } fn foo() -> NoisyDrop { let p = PanickyDrop; NoisyDrop::new() } fn main() { foo(); }

Expected Result

"creating a NoisyDrop" and "dropping a NoisyDrop" should appear the same number of times

Actual Result

creating a NoisyDrop thread 'main' panicked at 'explicit panic', src/main.rs:18:8 note: Run with `RUST_BACKTRACE=1` for a backtrace. 

The destructor is ignored.

Metadata

Metadata

Assignees

Labels

A-destructorsArea: Destructors (`Drop`, …)C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions