@@ -16,23 +16,37 @@ struct S;
16
16
mod method {
17
17
trait A {
18
18
fn a ( & self ) { }
19
- const A : u8 = 0 ;
20
19
}
21
20
22
21
pub trait B {
23
22
fn b ( & self ) { }
24
- const B : u8 = 0 ;
25
23
}
26
24
27
25
pub trait C : A + B {
28
26
fn c ( & self ) { }
29
- const C : u8 = 0 ;
30
27
}
31
28
32
29
impl A for :: S { }
33
30
impl B for :: S { }
34
31
impl C for :: S { }
32
+ }
33
+
34
+ mod assoc_const {
35
+ trait A {
36
+ const A : u8 = 0 ;
37
+ }
38
+
39
+ pub trait B {
40
+ const B : u8 = 0 ;
41
+ }
42
+
43
+ pub trait C : A + B {
44
+ const C : u8 = 0 ;
45
+ }
35
46
47
+ impl A for :: S { }
48
+ impl B for :: S { }
49
+ impl C for :: S { }
36
50
}
37
51
38
52
mod assoc_ty {
@@ -51,27 +65,9 @@ mod assoc_ty {
51
65
impl A for :: S { }
52
66
impl B for :: S { }
53
67
impl C for :: S { }
54
-
55
- }
56
-
57
- fn check_assoc_ty < T : assoc_ty:: C > ( ) {
58
- // A is private
59
- // B is pub, not in scope
60
- // C : A + B is pub, in scope
61
- use assoc_ty:: C ;
62
-
63
- // Associated types
64
- // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
65
- let _: S :: A ; //~ ERROR ambiguous associated type
66
- let _: S :: B ; //~ ERROR ambiguous associated type
67
- let _: S :: C ; //~ ERROR ambiguous associated type
68
- // A, B, C are resolved as inherent items, their traits don't need to be in scope
69
- let _: T :: A ; //~ ERROR associated type `A` is private
70
- let _: T :: B ; // OK
71
- let _: T :: C ; // OK
72
68
}
73
69
74
- fn main ( ) {
70
+ fn check_method ( ) {
75
71
// A is private
76
72
// B is pub, not in scope
77
73
// C : A + B is pub, in scope
@@ -97,6 +93,13 @@ fn main() {
97
93
C :: a ( & S ) ; //~ ERROR method `a` is private
98
94
C :: b ( & S ) ; // OK
99
95
C :: c ( & S ) ; // OK
96
+ }
97
+
98
+ fn check_assoc_const ( ) {
99
+ // A is private
100
+ // B is pub, not in scope
101
+ // C : A + B is pub, in scope
102
+ use assoc_const:: C ;
100
103
101
104
// Associated constants
102
105
// A, B, C are resolved as trait items, their traits need to be in scope
@@ -105,6 +108,28 @@ fn main() {
105
108
S :: C ; // OK
106
109
// A, B, C are resolved as inherent items, their traits don't need to be in scope
107
110
C :: A ; //~ ERROR associated constant `A` is private
108
- C :: B ; // OK
111
+ //~^ ERROR the trait `assoc_const::C` cannot be made into an object
112
+ //~| ERROR the trait bound `assoc_const::C: assoc_const::A` is not satisfied
113
+ C :: B ; // ERROR the trait `assoc_const::C` cannot be made into an object
114
+ //~^ ERROR the trait bound `assoc_const::C: assoc_const::B` is not satisfied
109
115
C :: C ; // OK
110
116
}
117
+
118
+ fn check_assoc_ty < T : assoc_ty:: C > ( ) {
119
+ // A is private
120
+ // B is pub, not in scope
121
+ // C : A + B is pub, in scope
122
+ use assoc_ty:: C ;
123
+
124
+ // Associated types
125
+ // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
126
+ let _: S :: A ; //~ ERROR ambiguous associated type
127
+ let _: S :: B ; //~ ERROR ambiguous associated type
128
+ let _: S :: C ; //~ ERROR ambiguous associated type
129
+ // A, B, C are resolved as inherent items, their traits don't need to be in scope
130
+ let _: T :: A ; //~ ERROR associated type `A` is private
131
+ let _: T :: B ; // OK
132
+ let _: T :: C ; // OK
133
+ }
134
+
135
+ fn main ( ) { }
0 commit comments