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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Thinkofname commentedon Mar 26, 2017
This seems to be intended according to #34537 which documents using private modules to leak private types.
petrochenkov commentedon Mar 26, 2017
@Thinkofname is right, this is the intended behavior.
retep998 commentedon Mar 26, 2017
The fact that this is intended behavior is why I'm so opposed to the current private in public rules.