]> git.lizzy.rs Git - rust.git/commitdiff
Fix object safety violations in the test
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 25 Apr 2017 19:38:21 +0000 (22:38 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 25 Apr 2017 19:38:39 +0000 (22:38 +0300)
src/test/compile-fail/trait-item-privacy.rs

index 4e8f8d6760a75ee3e593e8b28688c5aebd58b214..721d7583230a7f7cfb0751f571e571edfec1777b 100644 (file)
 mod method {
     trait A {
         fn a(&self) { }
-        const A: u8 = 0;
     }
 
     pub trait B {
         fn b(&self) { }
-        const B: u8 = 0;
     }
 
     pub trait C: A + B {
         fn c(&self) { }
-        const C: u8 = 0;
     }
 
     impl A for ::S {}
     impl B for ::S {}
     impl C for ::S {}
+}
+
+mod assoc_const {
+    trait A {
+        const A: u8 = 0;
+    }
+
+    pub trait B {
+        const B: u8 = 0;
+    }
+
+    pub trait C: A + B {
+        const C: u8 = 0;
+    }
 
+    impl A for ::S {}
+    impl B for ::S {}
+    impl C for ::S {}
 }
 
 mod assoc_ty {
@@ -51,27 +65,9 @@ pub trait C: A + B {
     impl A for ::S {}
     impl B for ::S {}
     impl C for ::S {}
-
-}
-
-fn check_assoc_ty<T: assoc_ty::C>() {
-    // A is private
-    // B is pub, not in scope
-    // C : A + B is pub, in scope
-    use assoc_ty::C;
-
-    // Associated types
-    // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
-    let _: S::A; //~ ERROR ambiguous associated type
-    let _: S::B; //~ ERROR ambiguous associated type
-    let _: S::C; //~ ERROR ambiguous associated type
-    // A, B, C are resolved as inherent items, their traits don't need to be in scope
-    let _: T::A; //~ ERROR associated type `A` is private
-    let _: T::B; // OK
-    let _: T::C; // OK
 }
 
-fn main() {
+fn check_method() {
     // A is private
     // B is pub, not in scope
     // C : A + B is pub, in scope
@@ -97,6 +93,13 @@ fn main() {
     C::a(&S); //~ ERROR method `a` is private
     C::b(&S); // OK
     C::c(&S); // OK
+}
+
+fn check_assoc_const() {
+    // A is private
+    // B is pub, not in scope
+    // C : A + B is pub, in scope
+    use assoc_const::C;
 
     // Associated constants
     // A, B, C are resolved as trait items, their traits need to be in scope
@@ -105,6 +108,28 @@ fn main() {
     S::C; // OK
     // A, B, C are resolved as inherent items, their traits don't need to be in scope
     C::A; //~ ERROR associated constant `A` is private
-    C::B; // OK
+          //~^ ERROR the trait `assoc_const::C` cannot be made into an object
+          //~| ERROR the trait bound `assoc_const::C: assoc_const::A` is not satisfied
+    C::B; // ERROR the trait `assoc_const::C` cannot be made into an object
+          //~^ ERROR the trait bound `assoc_const::C: assoc_const::B` is not satisfied
     C::C; // OK
 }
+
+fn check_assoc_ty<T: assoc_ty::C>() {
+    // A is private
+    // B is pub, not in scope
+    // C : A + B is pub, in scope
+    use assoc_ty::C;
+
+    // Associated types
+    // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
+    let _: S::A; //~ ERROR ambiguous associated type
+    let _: S::B; //~ ERROR ambiguous associated type
+    let _: S::C; //~ ERROR ambiguous associated type
+    // A, B, C are resolved as inherent items, their traits don't need to be in scope
+    let _: T::A; //~ ERROR associated type `A` is private
+    let _: T::B; // OK
+    let _: T::C; // OK
+}
+
+fn main() {}