mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 16:26:31 +00:00
27
kernel/crates/intertrait/tests/ui/duplicate-flags.rs
Normal file
27
kernel/crates/intertrait/tests/ui/duplicate-flags.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use intertrait::cast::*;
|
||||
use intertrait::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cast_to([sync, sync] Greet)]
|
||||
struct Data;
|
||||
|
||||
trait Source: CastFromSync {}
|
||||
|
||||
trait Greet {
|
||||
fn greet(&self);
|
||||
}
|
||||
|
||||
impl Greet for Data {
|
||||
fn greet(&self) {
|
||||
println!("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
impl Source for Data {}
|
||||
|
||||
fn main() {
|
||||
let data = Arc::new(Data);
|
||||
let source: Arc<dyn Source> = data;
|
||||
let greet = source.cast::<dyn Greet>();
|
||||
greet.unwrap_or_else(|_| panic!("can't happen")).greet();
|
||||
}
|
5
kernel/crates/intertrait/tests/ui/duplicate-flags.stderr
Normal file
5
kernel/crates/intertrait/tests/ui/duplicate-flags.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: Duplicated flag: sync
|
||||
--> $DIR/duplicate-flags.rs:5:18
|
||||
|
|
||||
5 | #[cast_to([sync, sync] Greet)]
|
||||
| ^^^^
|
31
kernel/crates/intertrait/tests/ui/on-generic-type.rs
Normal file
31
kernel/crates/intertrait/tests/ui/on-generic-type.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use intertrait::*;
|
||||
use intertrait::cast::*;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[cast_to(Greet)]
|
||||
struct Data<T: 'static> {
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
trait Source: CastFrom {}
|
||||
|
||||
trait Greet {
|
||||
fn greet(&self);
|
||||
}
|
||||
|
||||
impl<T: 'static> Greet for Data<T> {
|
||||
fn greet(&self) {
|
||||
println!("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> Source for Data<T> {}
|
||||
|
||||
fn main() {
|
||||
let data = Data::<i32> {
|
||||
phantom: PhantomData,
|
||||
};
|
||||
let source: &dyn Source = &data;
|
||||
let greet = source.cast::<dyn Greet>();
|
||||
greet.unwrap().greet();
|
||||
}
|
5
kernel/crates/intertrait/tests/ui/on-generic-type.stderr
Normal file
5
kernel/crates/intertrait/tests/ui/on-generic-type.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: #[cast_to(..)] can't be used on a generic type definition
|
||||
--> tests/ui/on-generic-type.rs:6:12
|
||||
|
|
||||
6 | struct Data<T: 'static> {
|
||||
| ^^^^^^^^^^^^
|
14
kernel/crates/intertrait/tests/ui/on-type-impl.rs
Normal file
14
kernel/crates/intertrait/tests/ui/on-type-impl.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use intertrait::*;
|
||||
|
||||
struct Data;
|
||||
|
||||
#[cast_to]
|
||||
impl Data {
|
||||
fn hello() {
|
||||
println!("hello!");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = Data;
|
||||
}
|
5
kernel/crates/intertrait/tests/ui/on-type-impl.stderr
Normal file
5
kernel/crates/intertrait/tests/ui/on-type-impl.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: #[cast_to] should only be on an impl of a trait
|
||||
--> $DIR/on-type-impl.rs:6:6
|
||||
|
|
||||
6 | impl Data {
|
||||
| ^^^^
|
27
kernel/crates/intertrait/tests/ui/unknown-flag.rs
Normal file
27
kernel/crates/intertrait/tests/ui/unknown-flag.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use intertrait::cast::*;
|
||||
use intertrait::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cast_to([sync, send] Greet)]
|
||||
struct Data;
|
||||
|
||||
trait Source: CastFromSync {}
|
||||
|
||||
trait Greet {
|
||||
fn greet(&self);
|
||||
}
|
||||
|
||||
impl Greet for Data {
|
||||
fn greet(&self) {
|
||||
println!("Hello");
|
||||
}
|
||||
}
|
||||
|
||||
impl Source for Data {}
|
||||
|
||||
fn main() {
|
||||
let data = Arc::new(Data);
|
||||
let source: Arc<dyn Source> = data;
|
||||
let greet = source.cast::<dyn Greet>();
|
||||
greet.unwrap_or_else(|_| panic!("can't happen")).greet();
|
||||
}
|
5
kernel/crates/intertrait/tests/ui/unknown-flag.stderr
Normal file
5
kernel/crates/intertrait/tests/ui/unknown-flag.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: Unknown flag: send
|
||||
--> $DIR/unknown-flag.rs:5:18
|
||||
|
|
||||
5 | #[cast_to([sync, send] Greet)]
|
||||
| ^^^^
|
Reference in New Issue
Block a user