Skip to content

Commit 638d9c3

Browse files
committed
let-else: test for issue 93951 / temporary lifetimes
1 parent c5c610a commit 638d9c3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
//
3+
// from issue #93951, where borrowck complained the temporary that `foo(&x)` was stored in was to
4+
// be dropped sometime after `x` was. It then suggested adding a semicolon that was already there.
5+
6+
#![feature(let_else)]
7+
use std::fmt::Debug;
8+
9+
fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> {
10+
Ok(x)
11+
}
12+
13+
fn let_else() {
14+
let x = String::from("Hey");
15+
let Ok(s) = foo(&x) else { return };
16+
}
17+
18+
fn if_let() {
19+
let x = String::from("Hey");
20+
let s = if let Ok(s) = foo(&x) { s } else { return };
21+
}
22+
23+
fn main() {
24+
let_else();
25+
if_let();
26+
}

0 commit comments

Comments
 (0)