about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2015-08-11 13:26:47 +0530
committerManish Goregaokar <manishsmail@gmail.com>2015-08-11 16:48:02 +0530
commit2fdfe092753a0b257510bdff53035f7ec14e545d (patch)
tree2e6de8a85f0df7b71fe7285aef4240c3bf075ad8 /src
parent93f8031303feef0fc53354e44d19a825440fcbd5 (diff)
parentd07a094fb07616345ff188da1a54986eabcbb9d8 (diff)
downloadrust-2fdfe092753a0b257510bdff53035f7ec14e545d.tar.gz
rust-2fdfe092753a0b257510bdff53035f7ec14e545d.zip
Rollup merge of #27617 - AlisdairO:diagnostics193, r=Manishearth
As title :-)
Part of #24407.

r? @Manishearth
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/diagnostics.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 343faf7e477..bd4e4fc3110 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -1803,6 +1803,43 @@ information see the [opt-in builtin traits RFC](https://github.com/rust-lang/
 rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
 "##,
 
+E0193: r##"
+`where` clauses must use generic type parameters: it does not make sense to use
+them otherwise.  An example causing this error:
+
+```
+trait Foo {
+    fn bar(&self);
+}
+
+#[derive(Copy,Clone)]
+struct Wrapper<T> {
+    Wrapped: T
+}
+
+impl Foo for Wrapper<u32> where Wrapper<u32>: Clone {
+    fn bar(&self) { }
+}
+```
+
+This use of a `where` clause is strange - a more common usage would look
+something like the following:
+
+```
+impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone {
+    fn bar(&self) { }
+}
+```
+
+Here, we're saying that the implementation exists on Wrapper only when the
+wrapped type `T` implements `Clone`. The `where` clause is important because
+some types will not implement `Clone`, and thus will not get this method.
+
+In our erroneous example, however, we're referencing a single concrete type.
+Since we know for certain that Wrapper<u32> implements Clone, there's no reason
+to also specify it in a `where` clause.
+"##,
+
 E0195: r##"
 Your method's lifetime parameters do not match the trait declaration.
 Erroneous code example:
@@ -2558,8 +2595,6 @@ register_diagnostics! {
     E0188, // can not cast a immutable reference to a mutable pointer
     E0189, // deprecated: can only cast a boxed pointer to a boxed object
     E0190, // deprecated: can only cast a &-pointer to an &-object
-    E0193, // cannot bound type where clause bounds may only be attached to types
-           // involving type parameters
     E0194,
     E0196, // cannot determine a type for this closure
     E0203, // type parameter has more than one relaxed default bound,