Inner function visibility usage

Hello,

rust-analyser allows the pub visibility for inner function:

pub fn outer() {
        pub fn inner() {}
    }

But what is the usage?
I tried outer::inner or outer()::inner to get access from outside, but it seems impossible to access the inner function.

Thank you in advance for your answers.

inner can be called within outer, like this:

pub fn outer() {
        pub fn inner() {}
        inner();
    }
    
fn main()
{
    outer();
}

There is no way to call inner except within outer. The pub keyword does nothing here, and perhaps there should be a lint to warn about it.

Currently, all sorts of items are allowed inside function bodies, even ones that don’t really make sense to put inside a function. In some cases this is useful for macros that generate such items, if the macro might be called either inside or outside of a function.

RFC 3373 will add a new warning for some slightly-related cases, but not for this example.

3 Likes