summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/ty-outlives/ty-param-fn-body.rs
blob: 98239f41609c090cef42bac19865f98e05b3b704 (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
// Test that we assume that universal types like `T` outlive the
// function body.

#![allow(warnings)]

use std::cell::Cell;

// No errors here, because `'a` is local to the body.
fn region_within_body<T>(t: T) {
    let some_int = 22;
    let cell = Cell::new(&some_int);
    outlives(cell, t)
}

// Error here, because T: 'a is not satisfied.
fn region_static<'a, T>(cell: Cell<&'a usize>, t: T) {
    outlives(cell, t)
    //~^ ERROR the parameter type `T` may not live long enough
}

fn outlives<'a, T>(x: Cell<&'a usize>, y: T)
where
    T: 'a,
{
}

fn main() {}