Skip to content

Commit 855ea48

Browse files
committed
Add test for temporary lifetime extension in Self() syntax.
1 parent 578fa8e commit 855ea48

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/ui/lifetimes/temporary-lifetime-extension-tuple-ctor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ fn temp() -> String {
77
#[derive(Debug)]
88
struct X<'a>(&'a String);
99

10+
trait T<'a> {
11+
const A: X<'a>;
12+
const B: X<'a>;
13+
}
14+
15+
impl<'a> T<'a> for X<'a> {
16+
// Check both Self() and X() syntax:
17+
const A: X<'a> = Self(&String::new());
18+
const B: X<'a> = X(&String::new());
19+
}
20+
1021
fn main() {
1122
let a = &temp();
1223
let b = Some(&temp());

tests/ui/lifetimes/temporary-lifetime-extension-tuple-ctor.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:23:19
2+
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:34:19
33
|
44
LL | let g = some(&temp());
55
| ^^^^^^ - temporary value is freed at the end of this statement

0 commit comments

Comments
 (0)