rust/src/test/ui/let-else/let-else-temporary-lifetime.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
535 B
Rust
Raw Normal View History

2022-06-02 14:39:47 +00:00
// run-pass
#![feature(let_else)]
use std::sync::atomic::{AtomicU8, Ordering};
static TRACKER: AtomicU8 = AtomicU8::new(0);
#[derive(Default)]
struct Droppy {
inner: u32,
}
impl Drop for Droppy {
fn drop(&mut self) {
TRACKER.store(1, Ordering::Release);
println!("I've been dropped");
}
}
fn main() {
assert_eq!(TRACKER.load(Ordering::Acquire), 0);
let 0 = Droppy::default().inner else { return };
assert_eq!(TRACKER.load(Ordering::Acquire), 1);
println!("Should have dropped 👆");
}