summaryrefslogtreecommitdiffstats
path: root/src/test/ui/regions/regions-bounded-by-trait-requiring-static.rs
blob: 7d02a46193ef7f9e3c05109f41b95a31f8adf75c (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Test which of the builtin types are considered sendable. The tests
// in this file all test region bound and lifetime violations that are
// detected during type check.

trait Dummy : 'static { }
fn assert_send<T:'static>() { }

// lifetime pointers with 'static lifetime are ok

fn static_lifime_ok<'a,T,U:Send>(_: &'a isize) {
    assert_send::<&'static isize>();
    assert_send::<&'static str>();
    assert_send::<&'static [isize]>();

    // whether or not they are mutable
    assert_send::<&'static mut isize>();
}

// otherwise lifetime pointers are not ok

fn param_not_ok<'a>(x: &'a isize) {
    assert_send::<&'a isize>();
    //~^ ERROR lifetime may not live long enough
}

fn param_not_ok1<'a>(_: &'a isize) {
    assert_send::<&'a str>();
    //~^ ERROR lifetime may not live long enough
}

fn param_not_ok2<'a>(_: &'a isize) {
    assert_send::<&'a [isize]>();
    //~^ ERROR lifetime may not live long enough
}

// boxes are ok

fn box_ok() {
    assert_send::<Box<isize>>();
    assert_send::<String>();
    assert_send::<Vec<isize>>();
}

// but not if they own a bad thing

fn box_with_region_not_ok<'a>() {
    assert_send::<Box<&'a isize>>();
    //~^ ERROR lifetime may not live long enough
}

// raw pointers are ok unless they point at unsendable things

fn unsafe_ok1<'a>(_: &'a isize) {
    assert_send::<*const isize>();
    assert_send::<*mut isize>();
}

fn unsafe_ok2<'a>(_: &'a isize) {
    assert_send::<*const &'a isize>();
    //~^ ERROR lifetime may not live long enough
}

fn unsafe_ok3<'a>(_: &'a isize) {
    assert_send::<*mut &'a isize>();
    //~^ ERROR lifetime may not live long enough
}

fn main() {
}