Skip to content

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

Open
@nyurik

Description

@nyurik

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-visibilityArea: Visibility / privacyT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions