Skip to content

Commit 432011d

Browse files
committed
Fallout in testing.
1 parent 170ccd6 commit 432011d

10 files changed

+29
-30
lines changed

src/doc/reference.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1961,16 +1961,18 @@ module through the rules above. It essentially allows public access into the
19611961
re-exported item. For example, this program is valid:
19621962

19631963
```
1964-
pub use self::implementation as api;
1964+
pub use self::implementation::api;
19651965
19661966
mod implementation {
1967-
pub fn f() {}
1967+
pub mod api {
1968+
pub fn f() {}
1969+
}
19681970
}
19691971
19701972
# fn main() {}
19711973
```
19721974

1973-
This means that any external crate referencing `implementation::f` would
1975+
This means that any external crate referencing `implementation::api::f` would
19741976
receive a privacy violation, while the path `api::f` would be allowed.
19751977

19761978
When re-exporting a private item, it can be thought of as allowing the "privacy

src/libsyntax/test.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
121121
debug!("current path: {}",
122122
ast_util::path_name_i(&self.cx.path));
123123

124-
if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
124+
let i = if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) {
125125
match i.node {
126126
ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _) => {
127127
let diag = self.cx.span_diagnostic;
128-
diag.span_fatal(i.span,
129-
"unsafe functions cannot be used for \
130-
tests");
128+
diag.span_fatal(i.span, "unsafe functions cannot be used for tests");
131129
}
132130
_ => {
133131
debug!("this is a test function");
@@ -142,9 +140,18 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
142140
self.tests.push(i.ident);
143141
// debug!("have {} test/bench functions",
144142
// cx.testfns.len());
143+
144+
// Make all tests public so we can call them from outside
145+
// the module (note that the tests are re-exported and must
146+
// be made public themselves to avoid privacy errors).
147+
let mut result = (*i).clone();
148+
result.vis = ast::Public;
149+
P(result)
145150
}
146151
}
147-
}
152+
} else {
153+
i
154+
};
148155

149156
// We don't want to recurse into anything other than mods, since
150157
// mods or tests inside of functions will break things

src/test/auxiliary/privacy_reexport.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
pub use foo as bar;
1212

13-
mod foo {
13+
pub mod foo {
1414
pub fn frob() {}
1515
}

src/test/compile-fail/lint-dead-code-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate libc;
1919

2020
pub use extern_foo as x;
2121
extern {
22-
fn extern_foo();
22+
pub fn extern_foo();
2323
}
2424

2525
struct Foo; //~ ERROR: struct is never used

src/test/compile-fail/privacy1.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ mod bar {
2727

2828
// can't publicly re-export private items
2929
pub use self::baz::{foo, bar};
30-
//~^ ERROR: function `bar` is private
31-
32-
pub use self::private::ppriv;
33-
//~^ ERROR: function `ppriv` is private
3430

3531
pub struct A;
3632
impl A {
@@ -61,10 +57,8 @@ mod bar {
6157
fn bar2(&self) {}
6258
}
6359

64-
// both of these are re-exported by `bar`, but only one should be
65-
// validly re-exported
6660
pub fn foo() {}
67-
fn bar() {}
61+
pub fn bar() {}
6862
}
6963

7064
extern {
@@ -92,10 +86,6 @@ mod bar {
9286
pub fn gpub() {}
9387
fn gpriv() {}
9488
}
95-
96-
mod private {
97-
fn ppriv() {}
98-
}
9989
}
10090

10191
pub fn gpub() {}
@@ -142,13 +132,13 @@ mod foo {
142132

143133
::bar::baz::foo(); //~ ERROR: function `foo` is inaccessible
144134
//~^ NOTE: module `baz` is private
145-
::bar::baz::bar(); //~ ERROR: function `bar` is private
135+
::bar::baz::bar(); //~ ERROR: function `bar` is inaccessible
146136
}
147137

148138
fn test2() {
149139
use bar::baz::{foo, bar};
150140
//~^ ERROR: function `foo` is inaccessible
151-
//~^^ ERROR: function `bar` is private
141+
//~^^ ERROR: function `bar` is inaccessible
152142
foo();
153143
bar();
154144
}

src/test/run-pass/issue-16597.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ mod test {
1515
use super::*;
1616

1717
#[test]
18-
fn test(){}
18+
pub fn test(){}
1919
}

src/test/run-pass/issue-20823.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
#![deny(unstable)]
1515

1616
#[test]
17-
fn foo() {}
17+
pub fn foo() {}

src/test/run-pass/issue-5950.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
pub use local as local_alias;
1313

14-
mod local { }
14+
pub mod local { }
1515

1616
pub fn main() {}

src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
extern crate test;
1414

1515
#[bench]
16-
fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
16+
pub fn bench_explicit_return_type(_: &mut ::test::Bencher) -> () {}
1717

1818
#[test]
19-
fn test_explicit_return_type() -> () {}
19+
pub fn test_explicit_return_type() -> () {}
2020

src/test/run-pass/test-should-fail-good-message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
#[test]
1515
#[should_panic(expected = "foo")]
16-
fn test_foo() {
16+
pub fn test_foo() {
1717
panic!("foo bar")
1818
}
1919

2020
#[test]
2121
#[should_panic(expected = "foo")]
22-
fn test_foo_dynamic() {
22+
pub fn test_foo_dynamic() {
2323
panic!("{} bar", "foo")
2424
}
2525

0 commit comments

Comments
 (0)