about summary refs log tree commit diff
path: root/tests/ui/async-await/async-closures/not-lending.rs
blob: 7bf2d3ead522c76feb29c362d63d6863f38423ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//@ aux-build:block-on.rs
//@ edition:2021

extern crate block_on;

// Make sure that we can't make an async closure that evaluates to a self-borrow.
// i.e. that the generator may reference captures, but the future's return type can't.

fn main() {
    block_on::block_on(async {
        let s = String::new();
        let x = async move || -> &String { &s };
        //~^ ERROR lifetime may not live long enough

        let s = String::new();
        let x = async move || { &s };
        //~^ ERROR lifetime may not live long enough
    });
}