about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0282.md25
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0283.md46
2 files changed, 59 insertions, 12 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0282.md b/compiler/rustc_error_codes/src/error_codes/E0282.md
index 49d2205f92c..5de43982e8b 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0282.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0282.md
@@ -3,7 +3,7 @@ The compiler could not infer a type and asked for a type annotation.
 Erroneous code example:
 
 ```compile_fail,E0282
-let x = "hello".chars().rev().collect();
+let x = Vec::new();
 ```
 
 This error indicates that type inference did not result in one unique possible
@@ -11,21 +11,24 @@ type, and extra information is required. In most cases this can be provided
 by adding a type annotation. Sometimes you need to specify a generic type
 parameter manually.
 
-A common example is the `collect` method on `Iterator`. It has a generic type
-parameter with a `FromIterator` bound, which for a `char` iterator is
-implemented by `Vec` and `String` among others. Consider the following snippet
-that reverses the characters of a string:
+In the example above, type `Vec` has a type parameter `T`. When calling
+`Vec::new`, barring any other later usage of the variable `x` that allows the
+compiler to infer what type `T` is, the compiler needs to be told what it is.
 
-In the first code example, the compiler cannot infer what the type of `x` should
-be: `Vec<char>` and `String` are both suitable candidates. To specify which type
-to use, you can use a type annotation on `x`:
+The type can be specified on the variable:
 
 ```
-let x: Vec<char> = "hello".chars().rev().collect();
+let x: Vec<i32> = Vec::new();
 ```
 
-It is not necessary to annotate the full type. Once the ambiguity is resolved,
-the compiler can infer the rest:
+The type can also be specified in the path of the expression:
+
+```
+let x = Vec::<i32>::new();
+```
+
+In cases with more complex types, it is not necessary to annotate the full
+type. Once the ambiguity is resolved, the compiler can infer the rest:
 
 ```
 let x: Vec<_> = "hello".chars().rev().collect();
diff --git a/compiler/rustc_error_codes/src/error_codes/E0283.md b/compiler/rustc_error_codes/src/error_codes/E0283.md
index 79d2c8204f9..b2f0ede6a0b 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0283.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0283.md
@@ -1,8 +1,52 @@
-An implementation cannot be chosen unambiguously because of lack of information.
+The compiler could not infer a type and asked for a type annotation.
 
 Erroneous code example:
 
 ```compile_fail,E0283
+let x = "hello".chars().rev().collect();
+```
+
+This error indicates that type inference did not result in one unique possible
+type, and extra information is required. In most cases this can be provided
+by adding a type annotation. Sometimes you need to specify a generic type
+parameter manually.
+
+A common example is the `collect` method on `Iterator`. It has a generic type
+parameter with a `FromIterator` bound, which for a `char` iterator is
+implemented by `Vec` and `String` among others. Consider the following snippet
+that reverses the characters of a string:
+
+In the first code example, the compiler cannot infer what the type of `x` should
+be: `Vec<char>` and `String` are both suitable candidates. To specify which type
+to use, you can use a type annotation on `x`:
+
+```
+let x: Vec<char> = "hello".chars().rev().collect();
+```
+
+It is not necessary to annotate the full type. Once the ambiguity is resolved,
+the compiler can infer the rest:
+
+```
+let x: Vec<_> = "hello".chars().rev().collect();
+```
+
+Another way to provide the compiler with enough information, is to specify the
+generic type parameter:
+
+```
+let x = "hello".chars().rev().collect::<Vec<char>>();
+```
+
+Again, you need not specify the full type if the compiler can infer it:
+
+```
+let x = "hello".chars().rev().collect::<Vec<_>>();
+```
+
+We can see a self-contained example below:
+
+```compile_fail,E0283
 struct Foo;
 
 impl Into<u32> for Foo {