about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorstrom-und-spiele <53340143+strom-und-spiele@users.noreply.github.com>2020-07-24 14:15:21 +0200
committerbboger <bastianboger@posteo.de>2020-08-08 11:01:34 +0200
commit7e68b7d10a7ce505fd41ebc99bd77276ab093a16 (patch)
tree4a549faaaac13c9138df2b2b96bbfcab6c10abda /src/librustc_error_codes/error_codes
parent0820e54a8ad7795d7b555b37994f43cfe62356d4 (diff)
downloadrust-7e68b7d10a7ce505fd41ebc99bd77276ab093a16.tar.gz
rust-7e68b7d10a7ce505fd41ebc99bd77276ab093a16.zip
Update E0271.md
remove references to non existing code,
expand solution suggestions
remove unneeded code in solution
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0271.md43
1 files changed, 13 insertions, 30 deletions
diff --git a/src/librustc_error_codes/error_codes/E0271.md b/src/librustc_error_codes/error_codes/E0271.md
index 31334069ed8..ddd245b1a2b 100644
--- a/src/librustc_error_codes/error_codes/E0271.md
+++ b/src/librustc_error_codes/error_codes/E0271.md
@@ -6,25 +6,6 @@ Erroneous code example:
 trait Trait { type AssociatedType; }
 
 fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
-    println!("in foo");
-}
-
-impl Trait for i8 { type AssociatedType = &'static str; }
-
-foo(3_i8);
-```
-
-This is because of a type mismatch between the associated type of some
-trait (e.g., `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
-and another type `U` that is required to be equal to `T::Bar`, but is not.
-Examples follow.
-
-Here is that same example again, with some explanatory comments:
-
-```compile_fail,E0271
-trait Trait { type AssociatedType; }
-
-fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
 //                    ~~~~~~~~ ~~~~~~~~~~~~~~~~~~
 //                        |            |
 //         This says `foo` can         |
@@ -56,11 +37,9 @@ foo(3_i8);
 // therefore the type-checker complains with this error code.
 ```
 
-To avoid those issues, you have to make the types match correctly.
-So we can fix the previous examples like this:
-
+The issue can be resolved by changing the associated type:
+1) in the `foo` implementation:
 ```
-// Basic Example:
 trait Trait { type AssociatedType; }
 
 fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
@@ -70,13 +49,17 @@ fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
 impl Trait for i8 { type AssociatedType = &'static str; }
 
 foo(3_i8);
+```
 
-// For-Loop Example:
-let vs = vec![1, 2, 3, 4];
-for v in &vs {
-    match v {
-        &1 => {}
-        _ => {}
-    }
+2) in the `Trait` implementation for `i8`:
+```
+trait Trait { type AssociatedType; }
+
+fn foo<T>(t: T) where T: Trait<AssociatedType = u32> {
+    println!("in foo");
 }
+
+impl Trait for i8 { type AssociatedType = u32; }
+
+foo(3_i8);
 ```