about summary refs log tree commit diff
path: root/tests/ui/sized-hierarchy/default-bound.rs
blob: bbb2c6d96baa8aa65e911a27c16687a5bd09481b (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
//@ check-fail
#![feature(extern_types, sized_hierarchy)]

use std::marker::{MetaSized, PointeeSized};

fn bare<T>() {}


fn sized<T: Sized>() {}

fn neg_sized<T: ?Sized>() {}


fn metasized<T: MetaSized>() {}

fn neg_metasized<T: ?MetaSized>() {}
//~^ ERROR bound modifier `?` can only be applied to `Sized`


fn pointeesized<T: PointeeSized>() { }

fn neg_pointeesized<T: ?PointeeSized>() { }
//~^ ERROR bound modifier `?` can only be applied to `Sized`


fn main() {
    // Functions which should have a `T: Sized` bound - check for an error given a non-Sized type:

    bare::<[u8]>();
    //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
    sized::<[u8]>();
    //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
    metasized::<[u8]>();
    pointeesized::<[u8]>();

    // Functions which should have a `T: MetaSized` bound - check for an error given a
    // non-MetaSized type:
    unsafe extern "C" {
        type Foo;
    }

    bare::<Foo>();
    //~^ ERROR the size for values of type `main::Foo` cannot be known
    sized::<Foo>();
    //~^ ERROR the size for values of type `main::Foo` cannot be known
    metasized::<Foo>();
    //~^ ERROR the size for values of type `main::Foo` cannot be known
    pointeesized::<Foo>();
}