Closed
Description
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d65d484826fe6e0d2d490ee1fa63052e
Given the following code:
mod lib {
#[derive(Default)]
pub struct Xyz { x: f32, y: f32, z: f32 }
#[derive(Default)]
pub struct Vec3(Xyz);
}
fn main() {
let a: lib::Vec3 = Default::default();
println!("{}", a.x);
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[E0609]: no field `x` on type `Vec3`
--> src/main.rs:10:22
|
10 | println!("{}", a.x);
| ^
|
help: one of the expressions' fields has a field of the same name
|
10 | println!("{}", a.0.x);
| ^^
help: a field with a similar name exists
|
10 | println!("{}", a.0);
| ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0609`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
The suggested fixes, a.0
and a.0.x
both refer to a private field, so they do not compile..
Given the following code, having implemented the suggested change:
mod lib {
#[derive(Default)]
pub struct Xyz { x: f32, y: f32, z: f32 }
#[derive(Default)]
pub struct Vec3(Xyz);
}
fn main() {
let a: lib::Vec3 = Default::default();
println!("{}", a.0.x);
}
The output is, correctly:
Compiling playground v0.0.1 (/playground)
error[E0616]: field `0` of struct `Vec3` is private
--> src/main.rs:10:22
|
10 | println!("{}", a.0.x);
| ^ private field
error[E0616]: field `x` of struct `Xyz` is private
--> src/main.rs:10:24
|
10 | println!("{}", a.0.x);
| ^ private field
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0616`.
error: could not compile `playground`
To learn more, run the command again with --verbose.