-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
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
Clarify error messages caused by re-exporting pub(crate)
visibility to outside
#90628
Clarify error messages caused by re-exporting pub(crate)
visibility to outside
#90628
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
pub(crate)
visibility to outsidepub(crate)
visibility to outside
.emit(); | ||
let error_msg = if crate_private_reexport { | ||
format!( | ||
"`{}` is only public to inside of the crate, and cannot be re-exported outside", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a wording nit: "is only public within the crate", then this lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk
Thank you for your review! I've updated it :)
@bors r+ rollup |
📌 Commit 33ab512 has been approved by |
…aused-by-reexporting-pub-crate-visibility-to-outside, r=oli-obk Clarify error messages caused by re-exporting `pub(crate)` visibility to outside This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate. Here is a small example ([Rust Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e2cd0bd4422d4f20e6522dcbad167d3b)): ```rust mod m { pub(crate) enum E {} } pub use m::E; fn main() {} ``` This code is compiled to: ``` error[E0365]: `E` is private, and cannot be re-exported --> prog.rs:4:9 | 4 | pub use m::E; | ^^^^ re-export of private `E` | = note: consider declaring type or module `E` with `pub` error: aborting due to previous error For more information about this error, try `rustc --explain E0365`. ``` However, enum `E` is actually public to the crate, not private totally—nevertheless, rustc treats `pub(crate)` and private visibility as the same on the error messages. They are not clear and should be segmented distinctly. By applying changes in this PR, the error message below will be the following message that would be clearer: ``` error[E0365]: `E` is only public to inside of the crate, and cannot be re-exported outside --> prog.rs:4:9 | 4 | pub use m::E; | ^^^^ re-export of crate public `E` | = note: consider declaring type or module `E` with `pub` error: aborting due to previous error For more information about this error, try `rustc --explain E0365`. ```
…askrgr Rollup of 5 pull requests Successful merges: - rust-lang#90575 (Improve suggestions for compatible variants on type mismatch.) - rust-lang#90628 (Clarify error messages caused by re-exporting `pub(crate)` visibility to outside) - rust-lang#90930 (Fix `non-constant value` ICE (rust-lang#90878)) - rust-lang#90983 (Make scrollbar in the sidebar always visible for visual consistency) - rust-lang#91021 (Elaborate `Future::Output` when printing opaque `impl Future` type) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate.
Here is a small example (Rust Playground):
This code is compiled to:
However, enum
E
is actually public to the crate, not private totally—nevertheless, rustc treatspub(crate)
and private visibility as the same on the error messages. They are not clear and should be segmented distinctly.By applying changes in this PR, the error message below will be the following message that would be clearer: