From 60be2de8b7b8a1c4eee7e065b8cef38ea629a6a3 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Fri, 22 Jul 2022 18:13:17 +0800 Subject: [PATCH] include a demo that more programs can be compiled --- .../ui/let-else/let-else-temporary-lifetime.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/ui/let-else/let-else-temporary-lifetime.rs b/src/test/ui/let-else/let-else-temporary-lifetime.rs index 064f28b4d9408..9c86901b97f03 100644 --- a/src/test/ui/let-else/let-else-temporary-lifetime.rs +++ b/src/test/ui/let-else/let-else-temporary-lifetime.rs @@ -29,6 +29,21 @@ fn main() { assert_eq!(TRACKER.load(Ordering::Acquire), 1); println!("Should have dropped 👆"); + { + // cf. https://github.com/rust-lang/rust/pull/99518#issuecomment-1191520030 + struct Foo<'a>(&'a mut u32); + + impl<'a> Drop for Foo<'a> { + fn drop(&mut self) { + *self.0 = 0; + } + } + let mut foo = 0; + let Foo(0) = Foo(&mut foo) else { + *&mut foo = 1; + todo!() + }; + } { let x = String::from("Hey"); @@ -61,6 +76,8 @@ fn main() { } { // test let-else drops temps before else block + // NOTE: this test has to be the last block in the `main` + // body. let rc = Rc::new(0); let 1 = *rc.clone() else { Rc::try_unwrap(rc).unwrap();