xref: /DragonOS/kernel/crates/intertrait/tests/ui/duplicate-flags.rs (revision bd70d2d1f490aabd570a5301b858bd5eb04149fa)
1*bd70d2d1SLoGin use intertrait::cast::*;
2*bd70d2d1SLoGin use intertrait::*;
3*bd70d2d1SLoGin use std::sync::Arc;
4*bd70d2d1SLoGin 
5*bd70d2d1SLoGin #[cast_to([sync, sync] Greet)]
6*bd70d2d1SLoGin struct Data;
7*bd70d2d1SLoGin 
8*bd70d2d1SLoGin trait Source: CastFromSync {}
9*bd70d2d1SLoGin 
10*bd70d2d1SLoGin trait Greet {
greet(&self)11*bd70d2d1SLoGin     fn greet(&self);
12*bd70d2d1SLoGin }
13*bd70d2d1SLoGin 
14*bd70d2d1SLoGin impl Greet for Data {
greet(&self)15*bd70d2d1SLoGin     fn greet(&self) {
16*bd70d2d1SLoGin         println!("Hello");
17*bd70d2d1SLoGin     }
18*bd70d2d1SLoGin }
19*bd70d2d1SLoGin 
20*bd70d2d1SLoGin impl Source for Data {}
21*bd70d2d1SLoGin 
main()22*bd70d2d1SLoGin fn main() {
23*bd70d2d1SLoGin     let data = Arc::new(Data);
24*bd70d2d1SLoGin     let source: Arc<dyn Source> = data;
25*bd70d2d1SLoGin     let greet = source.cast::<dyn Greet>();
26*bd70d2d1SLoGin     greet.unwrap_or_else(|_| panic!("can't happen")).greet();
27*bd70d2d1SLoGin }
28