Skip to content
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

Merged
merged 1 commit into from
Nov 20, 2021
Merged

Clarify error messages caused by re-exporting pub(crate) visibility to outside #90628

merged 1 commit into from
Nov 20, 2021

Conversation

ken-matsui
Copy link
Contributor

@ken-matsui ken-matsui commented Nov 5, 2021

This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate.

Here is a small example (Rust Playground):

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 within 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`.

@rust-highfive
Copy link
Collaborator

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 5, 2021
@rust-log-analyzer

This comment has been minimized.

@ken-matsui ken-matsui changed the title Suggest clarifying error messages caused by re-exporting pub(crate) visibility to outside Clarify error messages caused by re-exporting pub(crate) visibility to outside Nov 8, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 11, 2021
.emit();
let error_msg = if crate_private_reexport {
format!(
"`{}` is only public to inside of the crate, and cannot be re-exported outside",
Copy link
Contributor

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

Copy link
Contributor Author

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 :)

@oli-obk
Copy link
Contributor

oli-obk commented Nov 20, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 20, 2021

📌 Commit 33ab512 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 20, 2021
…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`.
```
This was referenced Nov 20, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2021
…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
@bors bors merged commit 81f3ae8 into rust-lang:master Nov 20, 2021
@rustbot rustbot added this to the 1.58.0 milestone Nov 20, 2021
@ken-matsui ken-matsui deleted the clarify-error-messages-caused-by-reexporting-pub-crate-visibility-to-outside branch November 20, 2021 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants