about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJad Ghalayini <jad.ghalayini@hotmail.com>2019-05-26 16:48:02 -0400
committerJad Ghalayini <jad.ghalayini@hotmail.com>2019-05-26 16:48:02 -0400
commit03cce1d81ea17639167681c42ae1afa4c67a2fd2 (patch)
tree330dcc2112a1b8fe34f595f4697731eb5a5520ce
parentdc6db14e1cd60012f25be4fd8d2eb96ea5b4bb68 (diff)
downloadrust-03cce1d81ea17639167681c42ae1afa4c67a2fd2.tar.gz
rust-03cce1d81ea17639167681c42ae1afa4c67a2fd2.zip
Added error message for E0284
-rw-r--r--src/librustc/error_codes.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs
index a1bfd417566..ef4d13096ba 100644
--- a/src/librustc/error_codes.rs
+++ b/src/librustc/error_codes.rs
@@ -1207,6 +1207,52 @@ fn main() {
 ```
 "##,
 
+E0284: r##"
+This error occurs when the compiler is unable to unambiguously infer the
+return type of a function or method which is generic on return type, such
+as the `collect` method for `Iterator`s.
+
+For example:
+
+```compile_fail,E0284
+fn foo() -> Result<bool, ()> {
+    let results = [Ok(true), Ok(false), Err(())].iter().cloned();
+    let v : Vec<bool> = results.collect()?;
+    // Do things with v...
+    Ok(true)
+}
+```
+
+Here we have an iterator `results` over `Result<bool, ()>`.
+Hence, `results.collect()` can return any type implementing
+`FromIterator<Result<bool, ()>>`. On the other hand, the
+`?` operator can accept any type implementing `Try`.
+
+The user of this code probably wants `collect()` to return a
+`Result<Vec<bool>, ()>`, but the compiler can't be sure
+that there isn't another type `T` implementing both `Try` and
+`FromIterator<Result<bool, ()>>` in scope such that
+`T::Ok == Vec<bool>`. Hence, this code is ambiguous and an error
+is returned.
+
+To resolve this error, use a concrete type for the intermediate expression:
+
+```
+fn foo() -> Result<bool, ()> {
+    let results = [Ok(true), Ok(false), Err(())].iter().cloned();
+    let v = {
+        let temp : Result<Vec<bool>, ()> = results.collect();
+        temp?
+    };
+    // Do things with v...
+    Ok(true)
+}
+```
+Note that the type of `v` can now be inferred from the type of `temp`
+
+
+"##,
+
 E0308: r##"
 This error occurs when the compiler was unable to infer the concrete type of a
 variable. It can occur for several cases, the most common of which is a
@@ -2158,7 +2204,6 @@ register_diagnostics! {
     E0278, // requirement is not satisfied
     E0279, // requirement is not satisfied
     E0280, // requirement is not satisfied
-    E0284, // cannot resolve type
 //  E0285, // overflow evaluation builtin bounds
 //  E0296, // replaced with a generic attribute input check
 //  E0300, // unexpanded macro