]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-safety/object-safety-by-value-self.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[rust.git] / src / test / ui / object-safety / object-safety-by-value-self.rs
1 // Check that a trait with by-value self is considered object-safe.
2
3 // compile-pass
4 #![allow(dead_code)]
5 #![allow(trivial_casts)]
6
7 trait Bar {
8     fn bar(self);
9 }
10
11 trait Baz {
12     fn baz(self: Self);
13 }
14
15 trait Quux {
16     // Legal because of the where clause:
17     fn baz(self: Self) where Self : Sized;
18 }
19
20 fn make_bar<T:Bar>(t: &T) -> &Bar {
21     t // legal
22 }
23
24 fn make_bar_explicit<T:Bar>(t: &T) -> &Bar {
25     t as &Bar // legal
26 }
27
28 fn make_baz<T:Baz>(t: &T) -> &Baz {
29     t // legal
30 }
31
32 fn make_baz_explicit<T:Baz>(t: &T) -> &Baz {
33     t as &Baz // legal
34 }
35
36 fn make_quux<T:Quux>(t: &T) -> &Quux {
37     t
38 }
39
40 fn make_quux_explicit<T:Quux>(t: &T) -> &Quux {
41     t as &Quux
42 }
43
44
45 fn main() {
46 }