summaryrefslogtreecommitdiffstats
path: root/tests/ui/object-safety/object-safety-by-value-self.rs
blob: c74a4d1cbbbfc53df44e7447c62c2ffca17309be (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
// Check that a trait with by-value self is considered object-safe.

// build-pass (FIXME(62277): could be check-pass?)
#![allow(dead_code)]
#![allow(trivial_casts)]

trait Bar {
    fn bar(self);
}

trait Baz {
    fn baz(self: Self);
}

trait Quux {
    // Legal because of the where clause:
    fn baz(self: Self) where Self : Sized;
}

fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    t // legal
}

fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
    t as &dyn Bar // legal
}

fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
    t // legal
}

fn make_baz_explicit<T:Baz>(t: &T) -> &dyn Baz {
    t as &dyn Baz // legal
}

fn make_quux<T:Quux>(t: &T) -> &dyn Quux {
    t
}

fn make_quux_explicit<T:Quux>(t: &T) -> &dyn Quux {
    t as &dyn Quux
}


fn main() {
}