-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
E0609's "one of the expressions' fields has a field of the same name" suggestion does not consider privacy #84443
Comments
This may be related to #64684. The diagnostics currently seem to be largely privacy-unaware. |
Is this actually wrong? I still think this is a helpful diagnostic, it means you know you have the option of making the field public. |
|
5 | println!("{}", a.x);
| ^ unknown field
|
help: one of the expressions' fields has a field of the same name
|
5 | println!("{}", a.0.x);
| ^^ Almost the same error is emitted if the module is in another entire crate. |
The initial place I ran into this error was when the module was from another crate, yeah. |
I have this piece of code: use std::collections::{HashMap, HashSet};
pub struct A {
items: HashSet<u32>,
}
pub struct B {
a: A,
map: HashMap<u32, u32>,
}
impl B {
fn new() -> Self { todo!() }
}
fn main() {
B::new().items.contains("");
} which errors out with this error message:
e.g. it shows the internals of |
This regressed somewhere between 0e63af5...d4e3570 @rustbot modify labels: D-incorrect |
Current output:
It seems like this is now correctly handled. |
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d65d484826fe6e0d2d490ee1fa63052e
Given the following code:
The current output is:
The suggested fixes,
a.0
anda.0.x
both refer to a private field, so they do not compile..Given the following code, having implemented the suggested change:
The output is, correctly:
The text was updated successfully, but these errors were encountered: