about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-01-17 15:23:19 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-01-18 10:58:01 -0800
commitd37e2f79cc049331a6fbde3ae5cc75a8e08ecb08 (patch)
tree508d66c283967128844e70388a0b0ee76799c20d /src
parentaa67e13498936c42581f70daaf3b6d028426dde6 (diff)
downloadrust-d37e2f79cc049331a6fbde3ae5cc75a8e08ecb08.tar.gz
rust-d37e2f79cc049331a6fbde3ae5cc75a8e08ecb08.zip
Disallow implementation of cross-crate priv traits
Turns out we were just forgetting to encode the privacy for trais, and
everything without privacy defaults to public!

Closes #11593
Diffstat (limited to 'src')
-rw-r--r--src/librustc/metadata/encoder.rs1
-rw-r--r--src/test/auxiliary/cci_impl_lib.rs2
-rw-r--r--src/test/auxiliary/issue_3979_traits.rs4
-rw-r--r--src/test/auxiliary/private_trait_xc.rs11
-rw-r--r--src/test/auxiliary/trait_default_method_xc_aux.rs2
-rw-r--r--src/test/auxiliary/trait_inheritance_auto_xc_aux.rs8
-rw-r--r--src/test/compile-fail/issue-11593.rs21
7 files changed, 41 insertions, 8 deletions
diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs
index b015638435b..656e4c45443 100644
--- a/src/librustc/metadata/encoder.rs
+++ b/src/librustc/metadata/encoder.rs
@@ -1196,6 +1196,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
         encode_trait_ref(ebml_w, ecx, trait_def.trait_ref, tag_item_trait_ref);
         encode_name(ecx, ebml_w, item.ident);
         encode_attributes(ebml_w, item.attrs);
+        encode_visibility(ebml_w, vis);
         for &method_def_id in ty::trait_method_def_ids(tcx, def_id).iter() {
             ebml_w.start_tag(tag_item_trait_method);
             encode_def_id(ebml_w, method_def_id);
diff --git a/src/test/auxiliary/cci_impl_lib.rs b/src/test/auxiliary/cci_impl_lib.rs
index 28c0c3062f3..6301158714a 100644
--- a/src/test/auxiliary/cci_impl_lib.rs
+++ b/src/test/auxiliary/cci_impl_lib.rs
@@ -10,7 +10,7 @@
 
 #[crate_id="cci_impl_lib"];
 
-trait uint_helpers {
+pub trait uint_helpers {
     fn to(&self, v: uint, f: |uint|);
 }
 
diff --git a/src/test/auxiliary/issue_3979_traits.rs b/src/test/auxiliary/issue_3979_traits.rs
index 75bdad7c95e..7b8d7e0d4d9 100644
--- a/src/test/auxiliary/issue_3979_traits.rs
+++ b/src/test/auxiliary/issue_3979_traits.rs
@@ -12,12 +12,12 @@
 
 #[crate_type = "lib"];
 
-trait Positioned {
+pub trait Positioned {
   fn SetX(&mut self, int);
   fn X(&self) -> int;
 }
 
-trait Movable: Positioned {
+pub trait Movable: Positioned {
   fn translate(&mut self, dx: int) {
     let x = self.X() + dx;
     self.SetX(x);
diff --git a/src/test/auxiliary/private_trait_xc.rs b/src/test/auxiliary/private_trait_xc.rs
new file mode 100644
index 00000000000..37ee10c8d37
--- /dev/null
+++ b/src/test/auxiliary/private_trait_xc.rs
@@ -0,0 +1,11 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo {}
diff --git a/src/test/auxiliary/trait_default_method_xc_aux.rs b/src/test/auxiliary/trait_default_method_xc_aux.rs
index 9ed45da9e17..0012d3e36c6 100644
--- a/src/test/auxiliary/trait_default_method_xc_aux.rs
+++ b/src/test/auxiliary/trait_default_method_xc_aux.rs
@@ -18,7 +18,7 @@ impl A for Something {
     fn f(&self) -> int { 10 }
 }
 
-trait B<T> {
+pub trait B<T> {
     fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
     fn staticthing<U>(_z: &Self, x: T, y: U) -> (T, U) { (x, y) }
 }
diff --git a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs
index d5949d1ce09..59fdaed744e 100644
--- a/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs
+++ b/src/test/auxiliary/trait_inheritance_auto_xc_aux.rs
@@ -8,10 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-trait Foo { fn f(&self) -> int; }
-trait Bar { fn g(&self) -> int; }
-trait Baz { fn h(&self) -> int; }
+pub trait Foo { fn f(&self) -> int; }
+pub trait Bar { fn g(&self) -> int; }
+pub trait Baz { fn h(&self) -> int; }
 
-trait Quux: Foo + Bar + Baz { }
+pub trait Quux: Foo + Bar + Baz { }
 
 impl<T:Foo + Bar + Baz> Quux for T { }
diff --git a/src/test/compile-fail/issue-11593.rs b/src/test/compile-fail/issue-11593.rs
new file mode 100644
index 00000000000..9ca91f067ba
--- /dev/null
+++ b/src/test/compile-fail/issue-11593.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:private_trait_xc.rs
+
+extern mod private_trait_xc;
+
+struct Bar;
+
+impl private_trait_xc::Foo for Bar {}
+//~^ ERROR: trait `Foo` is private
+
+fn main() {}
+