]> git.lizzy.rs Git - rust.git/blob - tests/ui/object-safety/object-safety-mentions-Self.rs
Move /src/test to /tests
[rust.git] / tests / ui / object-safety / object-safety-mentions-Self.rs
1 // Check that we correctly prevent users from making trait objects
2 // form traits that make use of `Self` in an argument or return
3 // position, unless `where Self : Sized` is present..
4 //
5 // revisions: curr object_safe_for_dispatch
6
7 #![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
8
9
10 trait Bar {
11     fn bar(&self, x: &Self);
12 }
13
14 trait Baz {
15     fn baz(&self) -> Self;
16 }
17
18 trait Quux {
19     fn quux(&self, s: &Self) -> Self where Self : Sized;
20 }
21
22 fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
23     //[curr]~^ ERROR E0038
24     t
25     //[object_safe_for_dispatch]~^ ERROR E0038
26 }
27
28 fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
29     //[curr]~^ ERROR E0038
30     t
31     //[object_safe_for_dispatch]~^ ERROR E0038
32 }
33
34 fn make_quux<T:Quux>(t: &T) -> &dyn Quux {
35     t
36 }
37
38 fn make_quux_explicit<T:Quux>(t: &T) -> &dyn Quux {
39     t as &dyn Quux
40 }
41
42 fn main() {}