Closed
Description
Hello!
We found a case where it's possible to leak a private type through the use of pub use
. Consider this crate with a single file buffer.rs
:
mod buffer {
pub struct EnumeratePixels;
pub struct ImageBuffer;
impl ImageBuffer {
pub fn enumerate_pixels(&self) -> EnumeratePixels {
EnumeratePixels
}
}
}
pub use buffer::ImageBuffer;
Rust allows it to compile, even though EnumeratePixels
is not publicly exposed from root:
% rustc --crate-type lib buffer.rs
%
It's possible to then use this crate like so:
extern crate buffer;
fn main() {
let buffer = buffer::ImageBuffer;
let _pixels = buffer.enumerate_pixels();
}
Rust 1.16 allows this to compile:
% rustc -L . bug.rs
%
However, it's impossible to name the type of enumerate_pixels()
:
extern crate buffer;
fn main() {
let buffer = buffer::ImageBuffer;
let _pixels: buffer::buffer::EnumeratePixels = buffer.enumerate_pixels();
}
This produces:
% rustc -L . bug.rs
error: module `buffer` is private
--> bug.rs:5:18
|
5 | let _pixels: buffer::buffer::EnumeratePixels = buffer.enumerate_pixels();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
I suspect this bug may have been reported in a few other tickets: #33077, #39437, #38844, #39437