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

Private type in public interface (error E0446) #15

Closed
regexident opened this issue May 14, 2023 · 3 comments
Closed

Private type in public interface (error E0446) #15

regexident opened this issue May 14, 2023 · 3 comments

Comments

@regexident
Copy link
Contributor

When using non-pub types in ascent macros the generated code emits a "private type in public interface (error E0446)" warning that will turn into an error in future versions of Rust.

To reproduce compile this code:

fn main() {
    #[derive(Hash, Eq, PartialEq, Clone)]
    struct PrivateType;

    #[allow(clippy::all)]
    let _ = ascent::ascent_run! {
        // struct Program;

        relation dummy(PrivateType);
    };
}
warning: private type `PrivateType` in public interface (error E0446)
  --> src/main.rs:6:13
   |
6  |       let _ = ascent::ascent_run! {
   |  _____________^
7  | |         // struct Program;
8  | |
9  | |         relation dummy(PrivateType);
10 | |     };
   | |_____^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
   = note: `#[warn(private_in_public)]` on by default
   = note: this warning originates in the macro `ascent::ascent_run` (in Nightly builds, run with -Z macro-backtrace for more info)

Un-commenting the // struct Program; silences the warning.

I'm not sure if there's a good solution for this (which doesn't get in the way of scenarios for public types), but it might be a good idea to add a note in the docs for this, since the fix might not be obvious immediately?

@s-arash
Copy link
Owner

s-arash commented Jul 15, 2023

As you pointed out, the solution already exists: a struct declaration at the top of the Ascent program. I'll add a hint to the documentation on silencing this warning.

@regexident
Copy link
Contributor Author

Alternatively the struct <PROGRAM_NAME>; pattern could be mandatory, which would then allow for specifying the visibility by use of pub struct <PROGRAM_NAME>;, pub(crate) struct <PROGRAM_NAME>;, or whatever other level is required.

This way future changes in the compiler turning the warning into an error won't break any existing ascent-using projects.

@s-arash
Copy link
Owner

s-arash commented Aug 5, 2023

I added a note to README.MD about this warning. I think it's good enough.

@s-arash s-arash closed this as completed Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants