mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
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.)
This commit is contained in:
@@ -3457,6 +3457,56 @@ fn bar(&self) {} // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
E0436: r##"
|
||||
The functional record update syntax is only allowed for structs. (Struct-like
|
||||
enum variants don't qualify, for example.)
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0436
|
||||
enum PublicationFrequency {
|
||||
Weekly,
|
||||
SemiMonthly { days: (u8, u8), annual_special: bool },
|
||||
}
|
||||
|
||||
fn one_up_competitor(competitor_frequency: PublicationFrequency)
|
||||
-> PublicationFrequency {
|
||||
match competitor_frequency {
|
||||
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
|
||||
days: (1, 15), annual_special: false
|
||||
},
|
||||
c @ PublicationFrequency::SemiMonthly{ .. } =>
|
||||
PublicationFrequency::SemiMonthly {
|
||||
annual_special: true, ..c // error: functional record update
|
||||
// syntax requires a struct
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Rewrite the expression without functional record update syntax:
|
||||
|
||||
```
|
||||
enum PublicationFrequency {
|
||||
Weekly,
|
||||
SemiMonthly { days: (u8, u8), annual_special: bool },
|
||||
}
|
||||
|
||||
fn one_up_competitor(competitor_frequency: PublicationFrequency)
|
||||
-> PublicationFrequency {
|
||||
match competitor_frequency {
|
||||
PublicationFrequency::Weekly => PublicationFrequency::SemiMonthly {
|
||||
days: (1, 15), annual_special: false
|
||||
},
|
||||
PublicationFrequency::SemiMonthly{ days, .. } =>
|
||||
PublicationFrequency::SemiMonthly {
|
||||
days, annual_special: true // ok!
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0439: r##"
|
||||
The length of the platform-intrinsic function `simd_shuffle`
|
||||
wasn't specified. Erroneous code example:
|
||||
@@ -4655,7 +4705,6 @@ fn i_am_a_function() {}
|
||||
// E0372, // coherence not object safe
|
||||
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
|
||||
// between structures with the same definition
|
||||
E0436, // functional record update requires a struct
|
||||
E0521, // redundant default implementations of trait
|
||||
E0533, // `{}` does not name a unit variant, unit struct or a constant
|
||||
E0563, // cannot determine a type for this `impl Trait`: {}
|
||||
|
||||
Reference in New Issue
Block a user