Closed
Description
This was fun one for isolating the parameters where it does and does not occur.
The code (a.rs
):
mod a {
#[cfg(hide_payload)] struct S;
#[cfg(not(hide_payload))] struct S { p: () }
#[cfg(not(hide_impl))] impl S { }
}
struct Expose;
impl Expose {
#[cfg(not(hide_payload))] pub fn expose(&self) -> a::S { a::S { p: () } }
#[cfg(hide_payload)] pub fn expose(&self) -> a::S { a::S }
}
fn main() {
let _s = Expose.expose();
}
So, S
is not pub
in a
, so it should not be possible to access it from main
.
But, out of the box, the above compiles and runs:
% rustc --version
/Users/fklock/opt/rust-dbg/bin/rustc 0.9-pre (4dded43 2013-11-17 23:41:25 -0800)
host: x86_64-apple-darwin
% rustc a.rs
%
If you remove either the payload or the impl, the privacy checker will flag an error:
% rustc --cfg hide_payload a.rs
a.rs:11:61: 11:65 error: struct `S` is inaccessible
a.rs:11 #[cfg(hide_payload)] pub fn expose(&self) -> a::S { a::S }
^~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/librustc/lib.rs:396
% rustc --cfg hide_impl a.rs
a.rs:10:54: 10:58 error: type `S` is private
a.rs:10 #[cfg(not(hide_payload))] pub fn expose(&self) -> a::S { a::S { p: () } }
^~~~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/libsyntax/diagnostic.rs:101
task '<main>' failed at 'explicit failure', /Users/fklock/Dev/Mozilla/rust.git/src/librustc/lib.rs:396