Skip to content

Commit

Permalink
add extended info for E0436 functional record update syntax needs struct
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
zackmdavis committed Jul 30, 2017
1 parent 477e9f0 commit 6f14ff1
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Expand Up @@ -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:
Expand Down Expand Up @@ -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`: {}
Expand Down

0 comments on commit 6f14ff1

Please sign in to comment.