Closed
Description
Consider this code:
mod a {
#[cfg(not(fixed))]
struct Foo;
#[cfg(fixed)]
pub struct Foo;
impl Foo {
pub fn new() -> Foo {
Foo
}
}
}
fn main() {
let foo = a::Foo::new();
println!("foo: {:?}", foo);
}
When I run rustc today:
% rustc --version
/Users/pnkfelix/opt/rust-dbg/bin/rustc 0.10-pre (d79fbba 2014-03-29 18:56:36 -0700)
host: x86_64-apple-darwin
% rustc /tmp/f.rs
/tmp/f.rs:15:15: 15:26 error: static method `new` is inaccessible
/tmp/f.rs:15 let foo = a::Foo::new();
^~~~~~~~~~~
error: aborting due to previous error
%
The reason that new
is inaccessible, AFAICT, is because Foo
is private. However, this is not really relayed in the error message; my first instinct is to look at the definition of new
itself, which has been declared pub
.
(I had thought there was a related bug filed somewhere about saying that if something is private due to an intermediate non-pub mod along a chain, we could do a better job of pointing the user at one or more of the non-pub mods that would need to be made pub
. Obviously that's not perfect since an item may be accessible via more than one path, and so any such suggestion coukd be misleading. But I could not find that related bug. Anyway, the situation today is not ideal.)
Metadata
Metadata
Assignees
Labels
No labels