rust icon indicating copy to clipboard operation
rust copied to clipboard

can reach `pub` items within `priv mod`s

Open ben0x539 opened this issue 13 years ago • 8 comments

I'm not sure I entirely grok visibility rules, but the following seems to compile when I don't think it should.

priv mod foo {
    priv mod bar {
        pub fn f() {}
    }   
}   

fn main() {
    foo::bar::f();
}   

ben0x539 avatar Feb 27 '13 00:02 ben0x539

I don't think priv does anything on mod, it's just a parser flaw.

thestinger avatar Mar 02 '13 10:03 thestinger

Still reproducible.

ILyoan avatar Apr 30 '13 05:04 ILyoan

Was able to reproduce that this compiles, but also not sure if it is a bug. @pcwalton can you look at this?

toddaaro avatar Jul 03 '13 22:07 toddaaro

Nominating for well-defined.

I think that this is another case where it'd be awesome to have resolve rules actually written down somewhere. Currently it sounds like it's still "whatever resolve does".

alexcrichton avatar Jul 27 '13 01:07 alexcrichton

accepted for production-ready milestone

graydon avatar Aug 08 '13 17:08 graydon

Sub-bug of #6143

pnkfelix avatar Sep 04 '13 12:09 pnkfelix

Also, there is relevant short discussion on #8215 : namely, assuming we adopt the rule stated by @bblum as "pub items in a non-pub mod are visible to the rest of the crate, but not visible to users outside the crate", then the above code is not a bug, if I understand correctly.

(However, this example also demonstrates that bblum's rule is not compatible with the fifth condition listed by @alexcrichton: "Any local-crate path which goes outside the bounds of [conditions 3 and 4] will only resolve if each component of the path is pub. For example I could reach into a child's private mod's pub items, but not the child's private mod's non-pub items." Again, that's assuming I understand correctly.)

pnkfelix avatar Sep 04 '13 12:09 pnkfelix

I'm closing this in favor of #8215. This specific issue would be fixed by those rules, and otherwise the validity of this code will be determined by the decision on that bug.

alexcrichton avatar Sep 19 '13 18:09 alexcrichton