Skip to content

Commit

Permalink
provide a test for rust-lang#93951
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Jul 21, 2022
1 parent 9b56640 commit baf9a7c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/ui/let-else/let-else-temporary-lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// run-pass
#![feature(let_else)]

use std::fmt::Display;
use std::rc::Rc;
use std::sync::atomic::{AtomicU8, Ordering};

Expand All @@ -18,12 +19,22 @@ impl Drop for Droppy {
}
}

fn foo<'a>(x: &'a str) -> Result<impl Display + 'a, ()> {
Ok(x)
}

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 👆");

{
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
let rc = Rc::new(0);
Expand Down

0 comments on commit baf9a7c

Please sign in to comment.