From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_error_codes/src/error_codes/E0436.md | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0436.md (limited to 'compiler/rustc_error_codes/src/error_codes/E0436.md') diff --git a/compiler/rustc_error_codes/src/error_codes/E0436.md b/compiler/rustc_error_codes/src/error_codes/E0436.md new file mode 100644 index 000000000..48ecc49e9 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0436.md @@ -0,0 +1,48 @@ +The functional record update syntax was used on something other than a struct. + +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 + } + } +} +``` + +The functional record update syntax is only allowed for structs (struct-like +enum variants don't qualify, for example). To fix the previous code, 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! + } + } +} +``` -- cgit v1.2.3