title: Private inner module returning private item gives "private type in public interface" error
body: <p>In the below example, the module <code>outer</code> has a private type <code>Private</code> and a private inner module <code>inner</code>. <code>inner</code> is able to access <code>Private</code> (because <strong>child modules can access their parent's private items</strong>, even if they are not parked as public).</p>
  
  <p><code>inner</code> defines a function <code>not_really_public_interface()</code>. While it is marked as public, <strong>it is really only available to <code>outer</code></strong> because <code>inner</code> itself is not public.</p>
  
  <p><em>outer.rs</em></p>
  
  <pre><code>struct Private;
  mod inner {
    use super::Private;
    pub fn not_really_public_interface() -&gt; Private {
      Private
    }
  }
  </code></pre>
  
  <p>This compiles without any problems.</p>
  
  <p><code>outer</code> should be able to use <code>inner::not_really_public_interface()</code> to obtain <code>Private</code>, as long as it makes sure not to export it. So let's do that:</p>
  
  <pre><code>pub fn main() {
    let _ = self::inner::not_really_public_interface();
  }
  </code></pre>
  
  <p>Right?</p>
  
  <p><em>stderr</em></p>
  
  <pre><code>error[E0446]: private type `Private` in public interface
   --&gt; src/outer.rs:4:3
    |
  4 | /   pub fn not_really_public_interface() -&gt; Private {
  5 | |     Private
  6 | |   }
    | |___^ can't leak private type
  </code></pre>
  
  <p><strong>Wat.</strong> This is counter-intuitive to me for several reasons:</p>
  
  <ul>
  <li>The former code produces no error even though it defines a function with an interface Rust considers to "leak". The error only occurs when the <code>outer</code> attempt to <em>use</em> this function.</li>
  <li>The only place <code>inner</code> could possibly "leak" <code>Private</code> is to <em>the module that defined it</em>.</li>
  </ul>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>What exactly is going on here that causes Rust to conclude that any part of this interface leaks? It seems like it treats <code>Private</code> as if it were defined in <code>inner</code>.</li>
  <li>Is there a context in which this makes perfect sense? My first thought was that this was a bug in the compiler or oversight in the privacy design, but I doubt that's the case.</li>
  <li>Is there a way to work around this without creating another module? I believe I can create a wrapper module and then just make <code>Private</code> public within <code>outer</code> and <code>inner</code>, but I'd prefer not to do that.</li>
  </ul>