2017-12-04 04:40:43 -06:00
|
|
|
// 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)
|
2018-08-31 12:27:11 -05:00
|
|
|
//~^ ERROR the parameter type `T` may not live long enough
|
2017-12-04 04:40:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn outlives<'a, T>(x: Cell<&'a usize>, y: T)
|
|
|
|
where
|
|
|
|
T: 'a,
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|