rust/tests/ui/drop/issue-2735-2.rs
Jake Goulding 8fc1bed0c8 Reduce confusion of some drop order tests
In addition to adhering to normal Rust casing idioms, I ran `rustfmt`.
2025-06-06 08:30:47 -04:00

25 lines
397 B
Rust

//@ run-pass
use std::cell::Cell;
// This test should behave exactly like issue-2735-3
struct Defer<'a> {
b: &'a Cell<bool>,
}
impl<'a> Drop for Defer<'a> {
fn drop(&mut self) {
self.b.set(true);
}
}
fn defer(b: &Cell<bool>) -> Defer<'_> {
Defer { b }
}
pub fn main() {
let dtor_ran = &Cell::new(false);
let _ = defer(dtor_ran);
assert!(dtor_ran.get());
}