@@ -3405,6 +3405,52 @@ parameters. You can read more about it in the API documentation:
3405
3405
https://doc.rust-lang.org/std/marker/struct.PhantomData.html
3406
3406
"## ,
3407
3407
3408
+ E0436 : r##"
3409
+ A struct can include `..` to indicate that you want to use a copy of some other
3410
+ struct for some of the values. This functional update syntax can only be used
3411
+ on struct types. It is an error to use it on other types, such as enums.
3412
+
3413
+ Example of erroneous code:
3414
+
3415
+ ```compile_fail
3416
+ enum Foo {
3417
+ A { x: u32, y: u32 }
3418
+ }
3419
+
3420
+ fn bar() {
3421
+ baz(Foo::A { x: 5, y: 10 });
3422
+ }
3423
+
3424
+ fn baz(Foo f) -> Foo {
3425
+ Foo::A { x: 6, ..f } // error: functional record update syntax requires
3426
+ // a struct
3427
+ }
3428
+ ```
3429
+
3430
+ To fix this, you need to manually initialize the value. For enums, you should
3431
+ match on the variants and copy the values to the new enum value:
3432
+
3433
+ ```
3434
+ enum Foo {
3435
+ A { x: u32, y: u32 }
3436
+ }
3437
+
3438
+ fn bar() {
3439
+ baz(Foo::A { x: 5, y: 10 });
3440
+ }
3441
+
3442
+ fn baz(Foo f) -> Foo {
3443
+ match f {
3444
+ // Match each variant of the enum and bind each field to a name.
3445
+ Foo::A { y: y, .. } =>
3446
+ // Create a new value of the same enum type, set the field you
3447
+ // want to update and the other fields that were bound.
3448
+ Foo::A { x: 6, y: y },
3449
+ }
3450
+ }
3451
+ ```
3452
+ "## ,
3453
+
3408
3454
E0439 : r##"
3409
3455
The length of the platform-intrinsic function `simd_shuffle`
3410
3456
wasn't specified. Erroneous code example:
@@ -3759,7 +3805,6 @@ register_diagnostics! {
3759
3805
// type because its default value `{}` references the type `Self`"
3760
3806
E0399 , // trait items need to be implemented because the associated
3761
3807
// type `{}` was overridden
3762
- E0436 , // functional record update requires a struct
3763
3808
E0513 , // no type for local variable ..
3764
3809
E0521 // redundant default implementations of trait
3765
3810
}
0 commit comments