rust/tests/ui/structs/default-field-values
Esteban Küber 464a6b1b4a Detect struct construction with private field in field with default
When trying to construct a struct that has a public field of a private type, suggest using `..` if that field has a default value.

```
error[E0603]: struct `Priv1` is private
  --> $DIR/non-exhaustive-ctor.rs:25:39
   |
LL |     let _ = S { field: (), field1: m::Priv1 {} };
   |                            ------     ^^^^^ private struct
   |                            |
   |                            while setting this field
   |
note: the struct `Priv1` is defined here
  --> $DIR/non-exhaustive-ctor.rs:14:4
   |
LL |    struct Priv1 {}
   |    ^^^^^^^^^^^^
help: the field `field1` you're trying to set has a default value, you can use `..` to use it
   |
LL |     let _ = S { field: (), .. };
   |                            ~~
```
2025-08-10 19:15:18 +00:00
..
auxiliary Detect struct construction with private field in field with default 2025-08-10 19:15:18 +00:00
const-trait-default-field-value.rs Add test for default_field_values and const_default 2025-07-17 19:26:45 +00:00
do-not-ice-on-invalid-lifetime.rs Do not recover missing lifetime with random in-scope lifetime 2025-03-03 05:57:55 +00:00
do-not-ice-on-invalid-lifetime.stderr Do not recover missing lifetime with random in-scope lifetime 2025-03-03 05:57:55 +00:00
empty-struct.rs Disallow A { .. } if A has no fields 2025-01-18 21:05:09 +00:00
empty-struct.stderr Disallow A { .. } if A has no fields 2025-01-18 21:05:09 +00:00
failures.rs Reject union default field values 2025-06-17 07:27:58 +08:00
failures.stderr Reject union default field values 2025-06-17 07:27:58 +08:00
field-references-param.rs Allow struct field default values to reference struct's generics 2025-03-04 01:00:55 +00:00
invalid-const.rs Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
invalid-const.stderr const-eval error: always say in which item the error occurred 2025-06-07 13:42:30 +02:00
non-exhaustive-ctor-2.rs Detect struct construction with private field in field with default 2025-08-10 19:15:18 +00:00
non-exhaustive-ctor-2.stderr Detect struct construction with private field in field with default 2025-08-10 19:15:18 +00:00
non-exhaustive-ctor.disabled.stderr More sophisticated span trimming 2025-02-21 00:41:17 +00:00
non-exhaustive-ctor.enabled.fixed Detect missing fields with default values and suggest .. 2025-01-21 21:26:37 +00:00
non-exhaustive-ctor.enabled.stderr More sophisticated span trimming 2025-02-21 00:41:17 +00:00
non-exhaustive-ctor.rs Detect missing fields with default values and suggest .. 2025-01-21 21:26:37 +00:00
post-mono.direct.stderr Clarify why we are talking about a failed const eval at a random place 2025-06-02 15:37:15 +00:00
post-mono.indirect.stderr Clarify why we are talking about a failed const eval at a random place 2025-06-02 15:37:15 +00:00
post-mono.rs Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
support.rs Move default-field-values tests into a subdirectory 2024-12-14 18:05:19 +00:00
use-normalized-ty-for-default-struct-value.rs Make sure to use normalized ty for unevaluated const for default struct value 2024-12-14 18:05:19 +00:00
visibility.rs Emit a single privacy error for multiple fields on the same struct expression 2025-01-18 20:33:15 +00:00
visibility.stderr Emit a single privacy error for multiple fields on the same struct expression 2025-01-18 20:33:15 +00:00