]>
Commit | Line | Data |
---|---|---|
ba9703b0 | 1 | The functional record update syntax was used on something other than a struct. |
60c5eb7d XL |
2 | |
3 | Erroneous code example: | |
4 | ||
5 | ```compile_fail,E0436 | |
6 | enum PublicationFrequency { | |
7 | Weekly, | |
8 | SemiMonthly { days: (u8, u8), annual_special: bool }, | |
9 | } | |
10 | ||
11 | fn 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 |
26 | The functional record update syntax is only allowed for structs (struct-like |
27 | enum variants don't qualify, for example). To fix the previous code, rewrite the | |
28 | expression without functional record update syntax: | |
60c5eb7d XL |
29 | |
30 | ``` | |
31 | enum PublicationFrequency { | |
32 | Weekly, | |
33 | SemiMonthly { days: (u8, u8), annual_special: bool }, | |
34 | } | |
35 | ||
36 | fn 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 | ``` |