rust/compiler/rustc_span/src
Esteban Küber 9ac95c10c0 Introduce default_field_values feature
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681.

Support default fields in enum struct variant

Allow default values in an enum struct variant definition:

```rust
pub enum Bar {
    Foo {
        bar: S = S,
        baz: i32 = 42 + 3,
    }
}
```

Allow using `..` without a base on an enum struct variant

```rust
Bar::Foo { .. }
```

`#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants.

Support `#[derive(Default)]` on enum struct variants with all defaulted fields

```rust
pub enum Bar {
    #[default]
    Foo {
        bar: S = S,
        baz: i32 = 42 + 3,
    }
}
```

Check for missing fields in typeck instead of mir_build.

Expand test with `const` param case (needs `generic_const_exprs` enabled).

Properly instantiate MIR const

The following works:

```rust
struct S<A> {
    a: Vec<A> = Vec::new(),
}
S::<i32> { .. }
```

Add lint for default fields that will always fail const-eval

We *allow* this to happen for API writers that might want to rely on users'
getting a compile error when using the default field, different to the error
that they would get when the field isn't default. We could change this to
*always* error instead of being a lint, if we wanted.

This will *not* catch errors for partially evaluated consts, like when the
expression relies on a const parameter.

Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`:

 - Suggest adding a base expression if there are missing fields.
 - Suggest enabling the feature if all the missing fields have optional values.
 - Suggest removing `..` if there are no missing fields.
2024-12-09 21:55:01 +00:00
..
analyze_source_file Be more accurate about calculating display_col from a BytePos 2024-07-18 20:08:38 +00:00
edit_distance Add test for precise algorithm used 2023-02-19 22:59:22 +00:00
source_map Avoid another &Lrc<..> in a return value. 2024-10-07 13:59:50 +11:00
symbol Reformat use declarations. 2024-07-29 08:26:52 +10:00
analyze_source_file.rs Add warn(unreachable_pub) to rustc_span. 2024-09-03 08:49:54 +10:00
caching_source_map_view.rs fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
def_id.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
edit_distance.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
edition.rs Stabilize the 2024 edition 2024-11-22 11:12:15 -08:00
fatal_error.rs Auto merge of #117557 - Zoxc:panic-prio, r=petrochenkov 2023-11-09 00:39:02 +00:00
hygiene.rs rustc_span: Replace a HashMap<_, ()> with HashSet 2024-11-27 11:23:25 -08:00
lib.rs Remove all threading through of ErrorGuaranteed from the driver 2024-12-06 18:42:31 +00:00
profiling.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
source_map.rs Auto merge of #132791 - tyilo:big-file-fail-fast, r=compiler-errors 2024-11-24 07:37:32 +00:00
span_encoding.rs Rollup merge of #128197 - Alexendoo:span-ctxt, r=davidtwco 2024-11-14 20:45:12 +01:00
symbol.rs Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
tests.rs add unstable support for outputting file checksums for use in cargo 2024-10-01 21:23:20 -06:00