]> git.proxmox.com Git - rustc.git/blame - src/test/ui/traits/trait-upcasting/type-checking-test-2.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / traits / trait-upcasting / type-checking-test-2.rs
CommitLineData
94222f64 1#![feature(trait_upcasting)]
94222f64
XL
2
3trait Foo<T>: Bar<i32> + Bar<T> {}
4trait Bar<T> {
5 fn bar(&self) -> Option<T> {
6 None
7 }
8}
9
10fn test_specific(x: &dyn Foo<i32>) {
11 let _ = x as &dyn Bar<i32>; // OK
12}
13
14fn test_specific2(x: &dyn Foo<u32>) {
15 let _ = x as &dyn Bar<i32>; // OK
16}
17
18fn test_specific3(x: &dyn Foo<i32>) {
19 let _ = x as &dyn Bar<u32>; // Error
20 //~^ ERROR non-primitive cast
21 //~^^ ERROR the trait bound `&dyn Foo<i32>: Bar<u32>` is not satisfied
22}
23
24fn test_infer_arg(x: &dyn Foo<u32>) {
25 let a = x as &dyn Bar<_>; // Ambiguous
26 //~^ ERROR non-primitive cast
27 //~^^ ERROR the trait bound `&dyn Foo<u32>: Bar<_>` is not satisfied
28 let _ = a.bar();
29}
30
31fn main() {}