]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/diagnostics.rs
Stabilize match_default_bindings
[rust.git] / src / librustc / diagnostics.rs
index 2fd875c3447677b4d841b320535abbfe543b6917..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:
 
@@ -1764,12 +1705,12 @@ fn main() {
 Erroneous code example:
 
 ```compile_fail,E0580
-fn main() -> i32 { // error: main function has wrong type
-    0
+fn main(x: i32) { // error: main function has wrong type
+    println!("{}", x);
 }
 ```
 
-The `main` function prototype should never take arguments or return type.
+The `main` function prototype should never take arguments.
 Example:
 
 ```
@@ -1789,8 +1730,6 @@ fn main() {
 Erroneous code example:
 
 ```compile_fail,E0562
-#![feature(conservative_impl_trait)]
-
 fn main() {
     let count_to_ten: impl Iterator<Item=usize> = 0..10;
     // error: `impl Trait` not allowed outside of function and inherent method
@@ -1804,8 +1743,6 @@ fn main() {
 Make sure `impl Trait` only appears in return-type position.
 
 ```
-#![feature(conservative_impl_trait)]
-
 fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
     0..n
 }
@@ -2081,8 +2018,6 @@ struct Foo {
 Erroneous code example:
 
 ```compile-fail,E0909
-#![feature(conservative_impl_trait)]
-
 use std::cell::Cell;
 
 trait Trait<'a> { }
@@ -2109,8 +2044,6 @@ fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
 would work:
 
 ```
-#![feature(conservative_impl_trait)]
-
 use std::cell::Cell;
 
 trait Trait<'a> { }