about summary refs log tree commit diff
path: root/tests/ui/lifetimes/temporary-lifetime-extension-tuple-ctor.rs
blob: 7de786dff3b774982989d3edfaeb42ba8a701075 (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
//@ reference: destructors.scope.lifetime-extension.exprs

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 std::option::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 borrowed
    println!("{a:?} {b:?} {c:?} {d:?} {e:?} {f:?} {g:?}");
}