]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0436.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0436.md
CommitLineData
ba9703b0 1The functional record update syntax was used on something other than a struct.
60c5eb7d
XL
2
3Erroneous code example:
4
5```compile_fail,E0436
6enum PublicationFrequency {
7 Weekly,
8 SemiMonthly { days: (u8, u8), annual_special: bool },
9}
10
11fn one_up_competitor(competitor_frequency: PublicationFrequency)
12 -> PublicationFrequency {
13 match competitor_frequency {
14 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
15 days: (1, 15), annual_special: false
16 },
17 c @ PublicationFrequency::SemiMonthly{ .. } =>
18 PublicationFrequency::SemiMonthly {
19 annual_special: true, ..c // error: functional record update
20 // syntax requires a struct
21 }
22 }
23}
24```
25
ba9703b0
XL
26The functional record update syntax is only allowed for structs (struct-like
27enum variants don't qualify, for example). To fix the previous code, rewrite the
28expression without functional record update syntax:
60c5eb7d
XL
29
30```
31enum PublicationFrequency {
32 Weekly,
33 SemiMonthly { days: (u8, u8), annual_special: bool },
34}
35
36fn one_up_competitor(competitor_frequency: PublicationFrequency)
37 -> PublicationFrequency {
38 match competitor_frequency {
39 PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
40 days: (1, 15), annual_special: false
41 },
42 PublicationFrequency::SemiMonthly{ days, .. } =>
43 PublicationFrequency::SemiMonthly {
44 days, annual_special: true // ok!
45 }
46 }
47}
48```