-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unhelpful error message constructing re-exported tuple struct with private fields #66067
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
Current output:
|
This is not fixed for me on the latest nightly (2020-03-18). The bad error message doesn't seem to appear when the modules are declared and used in a single file, which is what the playground link by @contrun does. |
Simple reproducer : pub use my_mod::MyStruct; // this pub use is causing the problem
mod my_mod {
#[derive(Debug)]
pub struct MyStruct(u32);
mod my_sub_mod {
use crate::MyStruct; // import the rexported struct
fn my_func() {
let s = MyStruct(42);
println!("MyStruct: {:?}", s);
}
}
} which when
PS: this is another issue -> #133343 |
I just stumbled upon this, too. |
I agree this is also confusing, but I'm not sure it's the same as the original bug. The original bug was about the error message not telling us about the private fields of the struct and instead suggesting the incorrect I've just tested the original code (the second case in the first post - the first case already had a good error message) on the latest nightly, and it actually seems to be fixed now:
|
I've made another issue so -> #133343 |
If a public tuple struct with private fields is declared in a public module, then instantiated elsewhere, the error message is helpful. For example, the code
causes the compiler to give the following useful error message:
This tells us exactly what the problem is - that we cannot construct
Triplet
because its fields are private.However, if the tuple struct is in a private module, but re-exported as public, the error message isn't helpful (it's even confusing). For example,
gives the compiler error
which confusingly suggests initialising the tuple with braces, instead of reporting that the fields are private.
Unsurprisingly, both versions work fine if the fields of
Triplet
are made public.The text was updated successfully, but these errors were encountered: