provide a test for #93951

This commit is contained in:
Ding Xiang Fei 2022-07-21 23:39:01 +08:00
parent 9b56640106
commit baf9a7cb57
No known key found for this signature in database
GPG Key ID: 3CD748647EEF6359

View File

@ -1,6 +1,7 @@
// run-pass // run-pass
#![feature(let_else)] #![feature(let_else)]
use std::fmt::Display;
use std::rc::Rc; use std::rc::Rc;
use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::atomic::{AtomicU8, Ordering};
@ -18,12 +19,22 @@ impl Drop for Droppy {
} }
} }
fn foo<'a>(x: &'a str) -> Result<impl Display + 'a, ()> {
Ok(x)
}
fn main() { fn main() {
assert_eq!(TRACKER.load(Ordering::Acquire), 0); assert_eq!(TRACKER.load(Ordering::Acquire), 0);
let 0 = Droppy::default().inner else { return }; let 0 = Droppy::default().inner else { return };
assert_eq!(TRACKER.load(Ordering::Acquire), 1); assert_eq!(TRACKER.load(Ordering::Acquire), 1);
println!("Should have dropped 👆"); println!("Should have dropped 👆");
{
let x = String::from("Hey");
let Ok(s) = foo(&x) else { panic!() };
assert_eq!(s.to_string(), x);
}
{ {
// test let-else drops temps after statement // test let-else drops temps after statement
let rc = Rc::new(0); let rc = Rc::new(0);