Add test for temporary lifetime extension in Self() syntax.

This commit is contained in:
Mara Bos 2025-05-07 14:29:23 +02:00
parent 578fa8e945
commit 855ea48ccc
2 changed files with 12 additions and 1 deletions

View file

@ -7,6 +7,17 @@ fn temp() -> String {
#[derive(Debug)]
struct X<'a>(&'a String);
trait T<'a> {
const A: X<'a>;
const B: X<'a>;
}
impl<'a> T<'a> for X<'a> {
// Check both Self() and X() syntax:
const A: X<'a> = Self(&String::new());
const B: X<'a> = X(&String::new());
}
fn main() {
let a = &temp();
let b = Some(&temp());

View file

@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:23:19
--> $DIR/temporary-lifetime-extension-tuple-ctor.rs:34:19
|
LL | let g = some(&temp());
| ^^^^^^ - temporary value is freed at the end of this statement