Working rfc1422 visibility example?

I’m cutting and pasting example code from rfc 1422:

but each seems to give errors in nightly. For example:

is something broken? or am I grossly misreading something.

If anyone has a working example that restricts access to a function to a specific module that’d be great.

looks like the doc’s have some examples that work (is it expected that rfc code is gives parse errors)?

Adapting the example in the doc’s, I still can’t get something like this to work:

    pub mod outer_mod {
        use super::b_mod;
        // error[E0578]: cannot find module `b_mod` in the crate root
        //   [no --explain for E0578]
        pub(in b_mod) fn b_visible_fn() {}

        // but this works!
        pub fn a() { b_mod::b(); }
    pub mod b_mod {
            pub fn b() {}

    fn main() { }

You missing the date is from 2015. RFCs are just drafts.
The visibility restriction is stable now. Think syntax was in (at least) some release notes.
First example just add in in front of a.

In embedded code. If you move the mod above you will see

error: visibilities can only be restricted to ancestor modules

I don’t think this will work because b_mod isn’t a parent module of outer_mod (it’s a sibling)

1 Like