summaryrefslogtreecommitdiffstats
path: root/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.rs
blob: c1885af4e5e1f833ef134ecf717828b2d52dfa28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#![feature(return_position_impl_trait_in_trait)]

trait Extend {
    fn extend(_: &str) -> (impl Sized + '_, &'static str);
}

impl Extend for () {
    fn extend(s: &str) -> (Option<&'static &'_ ()>, &'static str) {
        //~^ ERROR in type `&'static &()`, reference has a longer lifetime than the data it references
        (None, s)
    }
}

// This indirection is not necessary for reproduction,
// but it makes this test future-proof against #114936.
fn extend<T: Extend>(s: &str) -> &'static str {
    <T as Extend>::extend(s).1
}

fn main() {
    let use_after_free = extend::<()>(&String::from("temporary"));
    println!("{}", use_after_free);
}