2 // compile-flags: -Zvalidate-mir
6 use std::sync::atomic::{AtomicU8, Ordering};
8 static TRACKER: AtomicU8 = AtomicU8::new(0);
15 impl Drop for Droppy {
17 TRACKER.store(1, Ordering::Release);
18 println!("I've been dropped");
22 fn foo<'a>(x: &'a str) -> Result<impl Display + 'a, ()> {
27 assert_eq!(TRACKER.load(Ordering::Acquire), 0);
28 let 0 = Droppy::default().inner else { return };
29 assert_eq!(TRACKER.load(Ordering::Acquire), 1);
30 println!("Should have dropped 👆");
33 // cf. https://github.com/rust-lang/rust/pull/99518#issuecomment-1191520030
34 struct Foo<'a>(&'a mut u32);
36 impl<'a> Drop for Foo<'a> {
42 let Foo(0) = Foo(&mut foo) else {
48 let x = String::from("Hey");
50 let Ok(s) = foo(&x) else { panic!() };
51 assert_eq!(s.to_string(), x);
54 // test let-else drops temps after statement
56 let 0 = *rc.clone() else { unreachable!() };
57 Rc::try_unwrap(rc).unwrap();
60 let mut rc = Rc::new(0);
66 let 1 = *rc.clone() else {
67 if let Ok(v) = Rc::try_unwrap(rc) {
80 let &None = &Some(Rc::clone(&rc)) else {
81 Rc::try_unwrap(rc).unwrap();
89 // test let-else drops temps before else block
90 // NOTE: this test has to be the last block in the `main`
93 let 1 = *rc.clone() else {
94 Rc::try_unwrap(rc).unwrap();