]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-21245.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[rust.git] / src / test / run-pass / issue-21245.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Regression test for issue #21245. Check that we are able to infer
12 // the types in these examples correctly. It used to be that
13 // insufficient type propagation caused the type of the iterator to be
14 // incorrectly unified with the `*const` type to which it is coerced.
15
16 // pretty-expanded FIXME #23616
17
18 use std::ptr;
19
20 trait IntoIterator {
21     type Iter: Iterator;
22
23     fn into_iter(self) -> Self::Iter;
24 }
25
26 impl<I> IntoIterator for I where I: Iterator {
27     type Iter = I;
28
29     fn into_iter(self) -> I {
30         self
31     }
32 }
33
34 fn desugared_for_loop_bad<T>(v: Vec<T>) {
35     match IntoIterator::into_iter(v.iter()) {
36         mut iter => {
37             loop {
38                 match ::std::iter::Iterator::next(&mut iter) {
39                     ::std::option::Option::Some(x) => {
40                         unsafe { ptr::read(x); }
41                     },
42                     ::std::option::Option::None => break
43                 }
44             }
45         }
46     }
47 }
48
49 fn desugared_for_loop_good<T>(v: Vec<T>) {
50     match v.iter().into_iter() {
51         mut iter => {
52             loop {
53                 match ::std::iter::Iterator::next(&mut iter) {
54                     ::std::option::Option::Some(x) => {
55                         unsafe { ptr::read(x); }
56                     },
57                     ::std::option::Option::None => break
58                 }
59             }
60         }
61     }
62 }
63
64 fn main() {}