-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve "private type in public interface" message #50430
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
Comments
Around the time of this issue report, the error message looked like this:
As part of #51866 (c2d44b2), the message was expanded to include the span of the definition of the private type:
What's happening internally is that we're looking up the visibility modifier on the HIR node corresponding to the definition of a type, and linting if it's less visible than its parent (in the sense that a return type is the child of a function signature in the relevant traversal). In this example, the problem is that if the @spacekookie In what way do you think the current error message could be improved? (I guess we could add two maybe-incorrect suggestions to either make the private type more visible, or make the function less visible??) cc @estebank |
I guess what I'm wondering is if this is a bug or at least something that should really be allowed. In case this is what's supposed to happen I'm not entirely sure how the message could be made any better though |
I believe that by default we should treat
Does this sound correct? Even if we don't change anything about the heuristics, we could extend @zackmdavis' PR to also suggest the appropriate visibility annotation that would make it compile. |
Also stumbled onto this problem. The error message is really confusing and initially I started creating bug report only to find out that this is the expected behaviour. I tried this code: #![deny(private_in_public)]
fn main() {
}
struct Inner;
mod A {
use super::*;
pub trait O {
fn K() -> Inner;
}
} I expected to see this happen: Compile. Module A is not crate public so trait A is not crate public. Instead, this happened: Compile error, private type in public interface |
There seems to be an issue with detecting the
pub
-ness of types on the current nightly (EDIT: and actually stable) branch. Consider the following code:main.rs
:hardware/mod.rs
:hardware/parser.rs
:There are no public types in the
hardware
module that are exposed in any way. Yet, I get this error from the compiler:Play Link
The text was updated successfully, but these errors were encountered: