]> git.proxmox.com Git - rustc.git/blob - tests/ui/issues/issue-21245.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / issues / issue-21245.rs
1 // check-pass
2 #![allow(dead_code)]
3 // Regression test for issue #21245. Check that we are able to infer
4 // the types in these examples correctly. It used to be that
5 // insufficient type propagation caused the type of the iterator to be
6 // incorrectly unified with the `*const` type to which it is coerced.
7
8 // pretty-expanded FIXME #23616
9
10 use std::ptr;
11
12 trait IntoIterator {
13 type Iter: Iterator;
14
15 fn into_iter2(self) -> Self::Iter;
16 }
17
18 impl<I> IntoIterator for I where I: Iterator {
19 type Iter = I;
20
21 fn into_iter2(self) -> I {
22 self
23 }
24 }
25
26 fn desugared_for_loop_bad<T>(v: Vec<T>) {
27 match IntoIterator::into_iter2(v.iter()) {
28 mut iter => {
29 loop {
30 match ::std::iter::Iterator::next(&mut iter) {
31 ::std::option::Option::Some(x) => {
32 unsafe { ptr::read(x); }
33 },
34 ::std::option::Option::None => break
35 }
36 }
37 }
38 }
39 }
40
41 fn desugared_for_loop_good<T>(v: Vec<T>) {
42 match v.iter().into_iter() {
43 mut iter => {
44 loop {
45 match ::std::iter::Iterator::next(&mut iter) {
46 ::std::option::Option::Some(x) => {
47 unsafe { ptr::read(x); }
48 },
49 ::std::option::Option::None => break
50 }
51 }
52 }
53 }
54 }
55
56 fn main() {}