about summary refs log tree commit diff
path: root/tests/ui/lifetimes/temporary-lifetime-extension-tuple-ctor.rs
blob: bb537f855a4ab044864bc44548838e08acd51fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//@ edition:2024

fn temp() -> String {
    String::from("Hello")
}

#[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());
    let c = Option::Some::<&String>(&temp());
    use Option::Some as S;
    let d = S(&temp());
    let e = X(&temp());
    let f = Some(Ok::<_, ()>(std::borrow::Cow::Borrowed(if true {
        &temp()
    } else {
        panic!()
    })));
    let some = Some; // Turn the ctor into a regular function.
    let g = some(&temp()); //~ERROR temporary value dropped while borrowe
    println!("{a:?} {b:?} {c:?} {d:?} {e:?} {f:?} {g:?}");
}