]> git.lizzy.rs Git - rust.git/blob - src/librustc_error_codes/error_codes/E0436.md
Auto merge of #66396 - smmalis37:pythontest, r=alexcrichton
[rust.git] / src / librustc_error_codes / error_codes / E0436.md
1 The functional record update syntax is only allowed for structs. (Struct-like
2 enum variants don't qualify, for example.)
3
4 Erroneous code example:
5
6 ```compile_fail,E0436
7 enum PublicationFrequency {
8     Weekly,
9     SemiMonthly { days: (u8, u8), annual_special: bool },
10 }
11
12 fn one_up_competitor(competitor_frequency: PublicationFrequency)
13                      -> PublicationFrequency {
14     match competitor_frequency {
15         PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
16             days: (1, 15), annual_special: false
17         },
18         c @ PublicationFrequency::SemiMonthly{ .. } =>
19             PublicationFrequency::SemiMonthly {
20                 annual_special: true, ..c // error: functional record update
21                                           //        syntax requires a struct
22         }
23     }
24 }
25 ```
26
27 Rewrite the expression without functional record update syntax:
28
29 ```
30 enum PublicationFrequency {
31     Weekly,
32     SemiMonthly { days: (u8, u8), annual_special: bool },
33 }
34
35 fn one_up_competitor(competitor_frequency: PublicationFrequency)
36                      -> PublicationFrequency {
37     match competitor_frequency {
38         PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
39             days: (1, 15), annual_special: false
40         },
41         PublicationFrequency::SemiMonthly{ days, .. } =>
42             PublicationFrequency::SemiMonthly {
43                 days, annual_special: true // ok!
44         }
45     }
46 }
47 ```