From 6f14ff105f58672476e79bf3eff88d0673bbf0b2 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 27 Jul 2017 14:22:49 -0700 Subject: [PATCH 1/3] 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.) --- src/librustc_typeck/diagnostics.rs | 51 +++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) 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`: {} From 5605d58fc79e1cdacfbf01266a2d46b76df53ede Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 27 Jul 2017 15:08:29 -0700 Subject: [PATCH 2/3] move extended info for E0569 to numerical-order location in file We want the error explanations to appear in numerical order so that they're easy to find. (Also, any other order would be arbitrary and thus not constitute a Schelling point.) Bizarrely, the extended information for E0569 was placed between E0244 and E0318 in librustc_typeck/diagnostics.rs (when the code was introduced in 9a649c32). This commit moves it to be between E0562 and E0570, where it belongs. (Also, at reviewer request, say "Erroneous code example", the standard verbiage that it has been decided that we say everywhere.) --- src/librustc_typeck/diagnostics.rs | 42 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a1ac89051c8..3037e8d4a16 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2631,26 +2631,6 @@ struct Bar { x: Foo } ``` "##, -E0569: r##" -If an impl has a generic parameter with the `#[may_dangle]` attribute, then -that impl must be declared as an `unsafe impl. For example: - -```compile_fail,E0569 -#![feature(generic_param_attrs)] -#![feature(dropck_eyepatch)] - -struct Foo(X); -impl<#[may_dangle] X> Drop for Foo { - fn drop(&mut self) { } -} -``` - -In this example, we are asserting that the destructor for `Foo` will not -access any data of type `X`, and require this assertion to be true for -overall safety in our program. The compiler does not currently attempt to -verify this assertion; therefore we must tag this `impl` as unsafe. -"##, - E0318: r##" Default impls for a trait must be located in the same crate where the trait was defined. For more information see the [opt-in builtin traits RFC][RFC 19]. @@ -3976,6 +3956,28 @@ See [RFC 1522] for more details. [RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md "##, +E0569: r##" +If an impl has a generic parameter with the `#[may_dangle]` attribute, then +that impl must be declared as an `unsafe impl. + +Erroneous code example: + +```compile_fail,E0569 +#![feature(generic_param_attrs)] +#![feature(dropck_eyepatch)] + +struct Foo(X); +impl<#[may_dangle] X> Drop for Foo { + fn drop(&mut self) { } +} +``` + +In this example, we are asserting that the destructor for `Foo` will not +access any data of type `X`, and require this assertion to be true for +overall safety in our program. The compiler does not currently attempt to +verify this assertion; therefore we must tag this `impl` as unsafe. +"##, + E0570: r##" The requested ABI is unsupported by the current target. From 7dab9812c4f76aac6e442ff053c34c076b76643d Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 27 Jul 2017 21:42:03 -0700 Subject: [PATCH 3/3] extended info for E0595 closure cannot mutate immutable local variable --- src/librustc_borrowck/diagnostics.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 38dcc731236..fea9d0d6f13 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -1132,6 +1132,24 @@ fn main() { ``` "##, +E0595: r##" +Closures cannot mutate immutable captured variables. + +Erroneous code example: + +```compile_fail,E0595 +let x = 3; // error: closure cannot assign to immutable local variable `x` +let mut c = || { x += 1 }; +``` + +Make the variable binding mutable: + +``` +let mut x = 3; // ok! +let mut c = || { x += 1 }; +``` +"##, + E0596: r##" This error occurs because you tried to mutably borrow a non-mutable variable. @@ -1189,6 +1207,5 @@ register_diagnostics! { // E0385, // {} in an aliasable location E0524, // two closures require unique access to `..` at the same time E0594, // cannot assign to {} - E0595, // closure cannot assign to {} E0598, // lifetime of {} is too short to guarantee its contents can be... }