]>
Commit | Line | Data |
---|---|---|
7cac9316 XL |
1 | // Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
7cac9316 XL |
11 | #![feature(associated_type_defaults)] |
12 | ||
13 | struct S; | |
14 | ||
15 | mod method { | |
16 | trait A { | |
17 | fn a(&self) { } | |
18 | } | |
19 | ||
20 | pub trait B { | |
21 | fn b(&self) { } | |
22 | } | |
23 | ||
24 | pub trait C: A + B { | |
25 | fn c(&self) { } | |
26 | } | |
27 | ||
28 | impl A for ::S {} | |
29 | impl B for ::S {} | |
30 | impl C for ::S {} | |
31 | } | |
32 | ||
33 | mod assoc_const { | |
34 | trait A { | |
35 | const A: u8 = 0; | |
36 | } | |
37 | ||
38 | pub trait B { | |
39 | const B: u8 = 0; | |
40 | } | |
41 | ||
42 | pub trait C: A + B { | |
43 | const C: u8 = 0; | |
44 | } | |
45 | ||
46 | impl A for ::S {} | |
47 | impl B for ::S {} | |
48 | impl C for ::S {} | |
49 | } | |
50 | ||
51 | mod assoc_ty { | |
52 | trait A { | |
53 | type A = u8; | |
54 | } | |
55 | ||
56 | pub trait B { | |
57 | type B = u8; | |
58 | } | |
59 | ||
60 | pub trait C: A + B { | |
61 | type C = u8; | |
62 | } | |
63 | ||
64 | impl A for ::S {} | |
65 | impl B for ::S {} | |
66 | impl C for ::S {} | |
67 | } | |
68 | ||
69 | fn check_method() { | |
70 | // A is private | |
71 | // B is pub, not in scope | |
72 | // C : A + B is pub, in scope | |
73 | use method::C; | |
74 | ||
75 | // Methods, method call | |
76 | // a, b, c are resolved as trait items, their traits need to be in scope | |
77 | S.a(); //~ ERROR no method named `a` found for type `S` in the current scope | |
78 | S.b(); //~ ERROR no method named `b` found for type `S` in the current scope | |
79 | S.c(); // OK | |
80 | // a, b, c are resolved as inherent items, their traits don't need to be in scope | |
81 | let c = &S as &C; | |
82 | c.a(); //~ ERROR method `a` is private | |
83 | c.b(); // OK | |
84 | c.c(); // OK | |
85 | ||
86 | // Methods, UFCS | |
87 | // a, b, c are resolved as trait items, their traits need to be in scope | |
88 | S::a(&S); | |
89 | //~^ ERROR no function or associated item named `a` found for type `S` | |
90 | S::b(&S); | |
91 | //~^ ERROR no function or associated item named `b` found for type `S` | |
92 | S::c(&S); // OK | |
93 | // a, b, c are resolved as inherent items, their traits don't need to be in scope | |
94 | C::a(&S); //~ ERROR method `a` is private | |
95 | C::b(&S); // OK | |
96 | C::c(&S); // OK | |
97 | } | |
98 | ||
99 | fn check_assoc_const() { | |
100 | // A is private | |
101 | // B is pub, not in scope | |
102 | // C : A + B is pub, in scope | |
103 | use assoc_const::C; | |
104 | ||
105 | // Associated constants | |
106 | // A, B, C are resolved as trait items, their traits need to be in scope | |
107 | S::A; //~ ERROR no associated item named `A` found for type `S` in the current scope | |
108 | S::B; //~ ERROR no associated item named `B` found for type `S` in the current scope | |
109 | S::C; // OK | |
110 | // A, B, C are resolved as inherent items, their traits don't need to be in scope | |
111 | C::A; //~ ERROR associated constant `A` is private | |
112 | //~^ ERROR the trait `assoc_const::C` cannot be made into an object | |
113 | //~| ERROR the trait bound `assoc_const::C: assoc_const::A` is not satisfied | |
114 | C::B; // ERROR the trait `assoc_const::C` cannot be made into an object | |
115 | //~^ ERROR the trait bound `assoc_const::C: assoc_const::B` is not satisfied | |
116 | C::C; // OK | |
117 | } | |
118 | ||
119 | fn check_assoc_ty<T: assoc_ty::C>() { | |
120 | // A is private | |
121 | // B is pub, not in scope | |
122 | // C : A + B is pub, in scope | |
123 | use assoc_ty::C; | |
124 | ||
125 | // Associated types | |
126 | // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet | |
127 | let _: S::A; //~ ERROR ambiguous associated type | |
128 | let _: S::B; //~ ERROR ambiguous associated type | |
129 | let _: S::C; //~ ERROR ambiguous associated type | |
130 | // A, B, C are resolved as inherent items, their traits don't need to be in scope | |
131 | let _: T::A; //~ ERROR associated type `A` is private | |
132 | let _: T::B; // OK | |
133 | let _: T::C; // OK | |
ff7c6d11 XL |
134 | |
135 | // Associated types, bindings | |
136 | let _: assoc_ty::B< | |
137 | B = u8, // OK | |
138 | >; | |
139 | let _: C< | |
140 | A = u8, //~ ERROR associated type `A` is private | |
141 | B = u8, // OK | |
142 | C = u8, // OK | |
143 | >; | |
7cac9316 XL |
144 | } |
145 | ||
146 | fn main() {} |