diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-01-18 20:07:05 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-01-18 20:33:15 +0000 |
| commit | deef3ebaec2ff0ff818161f3b9b86a42bed5fe36 (patch) | |
| tree | 29becbbad6d9a19783b3a25dfbcc54e3b5318c80 /tests/ui/structs/default-field-values/visibility.rs | |
| parent | bbcf26fc33afb4695014aff22fa77dcb7d9eb715 (diff) | |
| download | rust-deef3ebaec2ff0ff818161f3b9b86a42bed5fe36.tar.gz rust-deef3ebaec2ff0ff818161f3b9b86a42bed5fe36.zip | |
Emit a single privacy error for multiple fields on the same struct expression
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
```
Diffstat (limited to 'tests/ui/structs/default-field-values/visibility.rs')
| -rw-r--r-- | tests/ui/structs/default-field-values/visibility.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/ui/structs/default-field-values/visibility.rs b/tests/ui/structs/default-field-values/visibility.rs index e1f76a5fe24..ff1245551b0 100644 --- a/tests/ui/structs/default-field-values/visibility.rs +++ b/tests/ui/structs/default-field-values/visibility.rs @@ -1,5 +1,6 @@ #![feature(default_field_values)] pub mod foo { + #[derive(Default)] pub struct Alpha { beta: u8 = 42, gamma: bool = true, @@ -7,10 +8,22 @@ pub mod foo { } mod bar { + use crate::foo::Alpha; fn baz() { - let x = crate::foo::Alpha { .. }; - //~^ ERROR field `beta` of struct `Alpha` is private - //~| ERROR field `gamma` of struct `Alpha` is private + 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 } } @@ -20,10 +33,10 @@ pub mod baz { } } fn main() { - let a = baz::S { + let _a = baz::S { .. //~ ERROR field `x` of struct `S` is private }; - let b = baz::S { + let _b = baz::S { x: 0, //~ ERROR field `x` of struct `S` is private }; } |
