diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2017-07-27 14:22:49 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2017-07-30 11:08:41 -0700 |
| commit | 6f14ff105f58672476e79bf3eff88d0673bbf0b2 (patch) | |
| tree | dd93998577a635fd75e1f0415400c17f536e3728 | |
| parent | 477e9f01714b6dffa1fb75e95b890d7abc2fcc52 (diff) | |
| download | rust-6f14ff105f58672476e79bf3eff88d0673bbf0b2.tar.gz rust-6f14ff105f58672476e79bf3eff88d0673bbf0b2.zip | |
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.)
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 60f32408abb..a1ac89051c8 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3457,6 +3457,56 @@ impl Foo for i32 { ``` "##, +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 @@ register_diagnostics! { // 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`: {} |
