]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/object-one-type-two-traits.rs
Rollup merge of #99742 - sigaloid:master, r=thomcc
[rust.git] / src / test / ui / traits / object-one-type-two-traits.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Testing creating two vtables with the same self type, but different
5 // traits.
6
7 use std::any::Any;
8
9 trait Wrap {
10     fn get(&self) -> isize;
11     fn wrap(self: Box<Self>) -> Box<dyn Any+'static>;
12 }
13
14 impl Wrap for isize {
15     fn get(&self) -> isize {
16         *self
17     }
18     fn wrap(self: Box<isize>) -> Box<dyn Any+'static> {
19         self as Box<dyn Any+'static>
20     }
21 }
22
23 fn is<T:Any>(x: &dyn Any) -> bool {
24     x.is::<T>()
25 }
26
27 fn main() {
28     let x = Box::new(22isize) as Box<dyn Wrap>;
29     println!("x={}", x.get());
30     let y = x.wrap();
31 }