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

Suggest code correction for E0446 - private type in public interface #112284

Open
nyurik opened this issue Jun 4, 2023 · 2 comments · May be fixed by #113983
Open

Suggest code correction for E0446 - private type in public interface #112284

nyurik opened this issue Jun 4, 2023 · 2 comments · May be fixed by #113983
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nyurik
Copy link
Contributor

nyurik commented Jun 4, 2023

Code

struct MyStruct;
pub fn my_test(_v: &MyStruct) {}
fn main() {}

Current output

error[E0446]: private type `MyStruct` in public interface
 --> src/bin/main.rs:2:1
  |
1 | struct MyStruct;
  | --------------- `MyStruct` declared as private
2 | pub fn my_test(_v: &MyStruct) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

Desired output

error[E0446]: private type `MyStruct` in public interface
 --> src/bin/main.rs:2:1
  |
1 | struct MyStruct;
  | --------------- `MyStruct` declared as private
2 | pub fn my_test(_v: &MyStruct) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type

Help:
* Either remove the `pub` in `pub fn my_test`
* Or add `pub` to `struct MyStruct;`

Rationale and extra context

Novice developers might be confused by the current wording of "leaking private type", and this seems like an easy help message fix.

Other cases

No response

Anything else?

No response

@nyurik nyurik added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 4, 2023
@aryan-debug
Copy link

@rustbot claim

@jyn514 jyn514 added A-visibility Area: Visibility / privacy. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Jun 11, 2023
@aryan-debug
Copy link

I am going to vacation for a month. So, if someone wants to work on it, feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants