about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-07-31 01:00:13 +0000
committerbors <bors@rust-lang.org>2017-07-31 01:00:13 +0000
commit2789db2720109ade328c87f3502dae7356bd825e (patch)
treedcd96d697617fcef58038d25c82ecba7ed0d63bd
parent15266f9a1bb72738901275e8ad9233a69a5bc54f (diff)
parent7dab9812c4f76aac6e442ff053c34c076b76643d (diff)
downloadrust-2789db2720109ade328c87f3502dae7356bd825e.tar.gz
rust-2789db2720109ade328c87f3502dae7356bd825e.zip
Auto merge of #43519 - zackmdavis:long_diagnostics_ever_after, r=GuillaumeGomez
a couple more error explanations for posterity

E0436, E0595, and moving E0569 to where it belongs in the file rather than being bizarrely out of numerical order

r? @GuillaumeGomez
-rw-r--r--src/librustc_borrowck/diagnostics.rs19
-rw-r--r--src/librustc_typeck/diagnostics.rs93
2 files changed, 90 insertions, 22 deletions
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...
 }
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 60f32408abb..3037e8d4a16 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -2631,26 +2631,6 @@ struct Bar<S, T> { x: Foo<S, T> }
 ```
 "##,
 
-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>(X);
-impl<#[may_dangle] X> Drop for Foo<X> {
-    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].
@@ -3457,6 +3437,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:
@@ -3926,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>(X);
+impl<#[may_dangle] X> Drop for Foo<X> {
+    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.
 
@@ -4655,7 +4707,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`: {}