Skip to content

Commit 6f14ff1

Browse files
committed
add extended info for E0436 functional record update syntax needs struct
This example focuses on struct-like enum variants, because it's not immediately obvious in what other context we can get E0436 alone, without any other, more serious, errors. (Triggering E0436 with a union also emits a separate "union expressions should have exactly one field" error.) (One might argue that we ought to accept the functional record update syntax for struct-like enums, but that is beyond the scope of this error-index-comprehensiveness commit.)
1 parent 477e9f0 commit 6f14ff1

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

Diff for: src/librustc_typeck/diagnostics.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -3457,6 +3457,56 @@ impl Foo for i32 {
34573457
```
34583458
"##,
34593459

3460+
E0436: r##"
3461+
The functional record update syntax is only allowed for structs. (Struct-like
3462+
enum variants don't qualify, for example.)
3463+
3464+
Erroneous code example:
3465+
3466+
```compile_fail,E0436
3467+
enum PublicationFrequency {
3468+
Weekly,
3469+
SemiMonthly { days: (u8, u8), annual_special: bool },
3470+
}
3471+
3472+
fn one_up_competitor(competitor_frequency: PublicationFrequency)
3473+
-> PublicationFrequency {
3474+
match competitor_frequency {
3475+
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3476+
days: (1, 15), annual_special: false
3477+
},
3478+
c @ PublicationFrequency::SemiMonthly{ .. } =>
3479+
PublicationFrequency::SemiMonthly {
3480+
annual_special: true, ..c // error: functional record update
3481+
// syntax requires a struct
3482+
}
3483+
}
3484+
}
3485+
```
3486+
3487+
Rewrite the expression without functional record update syntax:
3488+
3489+
```
3490+
enum PublicationFrequency {
3491+
Weekly,
3492+
SemiMonthly { days: (u8, u8), annual_special: bool },
3493+
}
3494+
3495+
fn one_up_competitor(competitor_frequency: PublicationFrequency)
3496+
-> PublicationFrequency {
3497+
match competitor_frequency {
3498+
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
3499+
days: (1, 15), annual_special: false
3500+
},
3501+
PublicationFrequency::SemiMonthly{ days, .. } =>
3502+
PublicationFrequency::SemiMonthly {
3503+
days, annual_special: true // ok!
3504+
}
3505+
}
3506+
}
3507+
```
3508+
"##,
3509+
34603510
E0439: r##"
34613511
The length of the platform-intrinsic function `simd_shuffle`
34623512
wasn't specified. Erroneous code example:
@@ -4655,7 +4705,6 @@ register_diagnostics! {
46554705
// E0372, // coherence not object safe
46564706
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
46574707
// between structures with the same definition
4658-
E0436, // functional record update requires a struct
46594708
E0521, // redundant default implementations of trait
46604709
E0533, // `{}` does not name a unit variant, unit struct or a constant
46614710
E0563, // cannot determine a type for this `impl Trait`: {}

0 commit comments

Comments
 (0)