mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-28 03:24:11 +00:00
Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field.
```
error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
--> $DIR/visibility.rs:18:13
|
LL | let _x = Alpha {
| ----- in this type
LL | beta: 0,
| ^^^^^^^ private field
LL | ..
| ^^ field `gamma` is private
```
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
#![feature(default_field_values)]
|
|
pub mod foo {
|
|
#[derive(Default)]
|
|
pub struct Alpha {
|
|
beta: u8 = 42,
|
|
gamma: bool = true,
|
|
}
|
|
}
|
|
|
|
mod bar {
|
|
use crate::foo::Alpha;
|
|
fn baz() {
|
|
let _x = Alpha { .. };
|
|
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
|
|
let _x = Alpha {
|
|
beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private
|
|
gamma: false,
|
|
};
|
|
let _x = Alpha {
|
|
beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private
|
|
..
|
|
};
|
|
let _x = Alpha { beta: 0, .. };
|
|
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
|
|
let _x = Alpha { beta: 0, ..Default::default() };
|
|
//~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
|
|
}
|
|
}
|
|
|
|
pub mod baz {
|
|
pub struct S {
|
|
x: i32 = 1,
|
|
}
|
|
}
|
|
fn main() {
|
|
let _a = baz::S {
|
|
.. //~ ERROR field `x` of struct `S` is private
|
|
};
|
|
let _b = baz::S {
|
|
x: 0, //~ ERROR field `x` of struct `S` is private
|
|
};
|
|
}
|