]> git.lizzy.rs Git - rust.git/blob - src/test/ui/on-unimplemented/multiple-impls.rs
Merge commit '266e96785ab71834b917bf474f130a6d8fdecd4b' into sync_cg_clif-2022-10-23
[rust.git] / src / test / ui / on-unimplemented / multiple-impls.rs
1 // Test if the on_unimplemented message override works
2
3 #![feature(rustc_attrs)]
4
5
6 struct Foo<T>(T);
7 struct Bar<T>(T);
8
9 #[rustc_on_unimplemented = "trait message"]
10 trait Index<Idx: ?Sized> {
11     type Output: ?Sized;
12     fn index(&self, index: Idx) -> &Self::Output;
13 }
14
15 #[rustc_on_unimplemented = "on impl for Foo"]
16 impl Index<Foo<usize>> for [i32] {
17     type Output = i32;
18     fn index(&self, _index: Foo<usize>) -> &i32 {
19         loop {}
20     }
21 }
22
23 #[rustc_on_unimplemented = "on impl for Bar"]
24 impl Index<Bar<usize>> for [i32] {
25     type Output = i32;
26     fn index(&self, _index: Bar<usize>) -> &i32 {
27         loop {}
28     }
29 }
30
31
32 fn main() {
33     Index::index(&[] as &[i32], 2u32);
34     //~^ ERROR E0277
35     //~| ERROR E0277
36     //~| ERROR E0277
37     Index::index(&[] as &[i32], Foo(2u32));
38     //~^ ERROR E0277
39     //~| ERROR E0277
40     //~| ERROR E0277
41     Index::index(&[] as &[i32], Bar(2u32));
42     //~^ ERROR E0277
43     //~| ERROR E0277
44     //~| ERROR E0277
45 }