]> git.lizzy.rs Git - rust.git/blob - tests/ui/traits/trait-upcasting/type-checking-test-1.rs
Rollup merge of #106701 - ibraheemdev:sync-sender-spin, r=Amanieu
[rust.git] / tests / ui / traits / trait-upcasting / type-checking-test-1.rs
1 #![feature(trait_upcasting)]
2
3 trait Foo: Bar<i32> + Bar<u32> {}
4 trait Bar<T> {
5     fn bar(&self) -> Option<T> {
6         None
7     }
8 }
9
10 fn test_specific(x: &dyn Foo) {
11     let _ = x as &dyn Bar<i32>; // OK
12     let _ = x as &dyn Bar<u32>; // OK
13 }
14
15 fn test_unknown_version(x: &dyn Foo) {
16     let _ = x as &dyn Bar<_>; // Ambiguous
17                               //~^ ERROR non-primitive cast
18                               //~^^ ERROR the trait bound `&dyn Foo: Bar<_>` is not satisfied
19 }
20
21 fn test_infer_version(x: &dyn Foo) {
22     let a = x as &dyn Bar<_>; // OK
23     let _: Option<u32> = a.bar();
24 }
25
26 fn main() {}