Skip to content

Commit 4bd417e

Browse files
committed
Fix object safety violations in the test
1 parent 1883b8d commit 4bd417e

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

src/test/compile-fail/trait-item-privacy.rs

+48-23
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,37 @@ struct S;
1616
mod method {
1717
trait A {
1818
fn a(&self) { }
19-
const A: u8 = 0;
2019
}
2120

2221
pub trait B {
2322
fn b(&self) { }
24-
const B: u8 = 0;
2523
}
2624

2725
pub trait C: A + B {
2826
fn c(&self) { }
29-
const C: u8 = 0;
3027
}
3128

3229
impl A for ::S {}
3330
impl B for ::S {}
3431
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+
}
3546

47+
impl A for ::S {}
48+
impl B for ::S {}
49+
impl C for ::S {}
3650
}
3751

3852
mod assoc_ty {
@@ -51,27 +65,9 @@ mod assoc_ty {
5165
impl A for ::S {}
5266
impl B for ::S {}
5367
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
7268
}
7369

74-
fn main() {
70+
fn check_method() {
7571
// A is private
7672
// B is pub, not in scope
7773
// C : A + B is pub, in scope
@@ -97,6 +93,13 @@ fn main() {
9793
C::a(&S); //~ ERROR method `a` is private
9894
C::b(&S); // OK
9995
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;
100103

101104
// Associated constants
102105
// A, B, C are resolved as trait items, their traits need to be in scope
@@ -105,6 +108,28 @@ fn main() {
105108
S::C; // OK
106109
// A, B, C are resolved as inherent items, their traits don't need to be in scope
107110
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
109115
C::C; // OK
110116
}
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

Comments
 (0)