We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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:
pub use
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:
EnumeratePixels
% 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():
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
The text was updated successfully, but these errors were encountered:
This seems to be intended according to #34537 which documents using private modules to leak private types.
Sorry, something went wrong.
@Thinkofname is right, this is the intended behavior.
The fact that this is intended behavior is why I'm so opposed to the current private in public rules.
No branches or pull requests
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 filebuffer.rs
:Rust allows it to compile, even though
EnumeratePixels
is not publicly exposed from root:It's possible to then use this crate like so:
Rust 1.16 allows this to compile:
However, it's impossible to name the type of
enumerate_pixels()
:This produces:
I suspect this bug may have been reported in a few other tickets: #33077, #39437, #38844, #39437
The text was updated successfully, but these errors were encountered: