Visibility modifier: multiple modules for "in" keyword

Can I do something like this?

No, that's not possible. You can write an RFC for this (how to do this is explained here) if you want.

In this case, I would just write pub(crate).

AFAIK, pub (in ...) can only refer to an ancestor of self anyways. So just pick the higher one of two ancestors.

To elaborate, what I mean is: If wouldn’t make much sense to specify multiple in locations unless the restriction to ancestors-only was lifted. (That restriction however is probably in place for a reason.)

4 Likes

Just providing some feedback regarding posting: it's much easier to read (and quote/reply) if you post actual text rather than a screenshot of text. Like this:

pub mod sub1 {}

pub mod sub2 {
    pub(in crate::test, crate::sub1) fn world() {
        print!("World!");
    }
}
8 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.