]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/diagnostics.rs
Stabilize match_default_bindings
[rust.git] / src / librustc / diagnostics.rs
index f95c355012a213354dc64f1493767cee611b9d6b..c74ae2343b866b0833154d97fb3457e4a7464276 100644 (file)
@@ -887,65 +887,6 @@ fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
 // therefore the type-checker complains with this error code.
 ```
 
-Here is a more subtle instance of the same problem, that can
-arise with for-loops in Rust:
-
-```compile_fail
-let vs: Vec<i32> = vec![1, 2, 3, 4];
-for v in &vs {
-    match v {
-        1 => {},
-        _ => {},
-    }
-}
-```
-
-The above fails because of an analogous type mismatch,
-though may be harder to see. Again, here are some
-explanatory comments for the same example:
-
-```compile_fail
-{
-    let vs = vec![1, 2, 3, 4];
-
-    // `for`-loops use a protocol based on the `Iterator`
-    // trait. Each item yielded in a `for` loop has the
-    // type `Iterator::Item` -- that is, `Item` is the
-    // associated type of the concrete iterator impl.
-    for v in &vs {
-//      ~    ~~~
-//      |     |
-//      |    We borrow `vs`, iterating over a sequence of
-//      |    *references* of type `&Elem` (where `Elem` is
-//      |    vector's element type). Thus, the associated
-//      |    type `Item` must be a reference `&`-type ...
-//      |
-//  ... and `v` has the type `Iterator::Item`, as dictated by
-//  the `for`-loop protocol ...
-
-        match v {
-            1 => {}
-//          ~
-//          |
-// ... but *here*, `v` is forced to have some integral type;
-// only types like `u8`,`i8`,`u16`,`i16`, et cetera can
-// match the pattern `1` ...
-
-            _ => {}
-        }
-
-// ... therefore, the compiler complains, because it sees
-// an attempt to solve the equations
-// `some integral-type` = type-of-`v`
-//                      = `Iterator::Item`
-//                      = `&Elem` (i.e. `some reference type`)
-//
-// which cannot possibly all be true.
-
-    }
-}
-```
-
 To avoid those issues, you have to make the types match correctly.
 So we can fix the previous examples like this: