2019-11-03 18:00:00 -06:00
|
|
|
// check-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(dead_code)]
|
2015-01-10 20:44:14 -06:00
|
|
|
// Regression test for issue #21245. Check that we are able to infer
|
|
|
|
// the types in these examples correctly. It used to be that
|
|
|
|
// insufficient type propagation caused the type of the iterator to be
|
|
|
|
// incorrectly unified with the `*const` type to which it is coerced.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-01-10 20:44:14 -06:00
|
|
|
use std::ptr;
|
|
|
|
|
|
|
|
trait IntoIterator {
|
|
|
|
type Iter: Iterator;
|
|
|
|
|
2015-04-17 16:31:30 -05:00
|
|
|
fn into_iter2(self) -> Self::Iter;
|
2015-01-10 20:44:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<I> IntoIterator for I where I: Iterator {
|
|
|
|
type Iter = I;
|
|
|
|
|
2015-04-17 16:31:30 -05:00
|
|
|
fn into_iter2(self) -> I {
|
2015-01-10 20:44:14 -06:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn desugared_for_loop_bad<T>(v: Vec<T>) {
|
2015-04-17 16:31:30 -05:00
|
|
|
match IntoIterator::into_iter2(v.iter()) {
|
2015-01-10 20:44:14 -06:00
|
|
|
mut iter => {
|
|
|
|
loop {
|
|
|
|
match ::std::iter::Iterator::next(&mut iter) {
|
|
|
|
::std::option::Option::Some(x) => {
|
|
|
|
unsafe { ptr::read(x); }
|
|
|
|
},
|
|
|
|
::std::option::Option::None => break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn desugared_for_loop_good<T>(v: Vec<T>) {
|
2015-01-27 08:39:53 -06:00
|
|
|
match v.iter().into_iter() {
|
2015-01-10 20:44:14 -06:00
|
|
|
mut iter => {
|
|
|
|
loop {
|
|
|
|
match ::std::iter::Iterator::next(&mut iter) {
|
|
|
|
::std::option::Option::Some(x) => {
|
|
|
|
unsafe { ptr::read(x); }
|
|
|
|
},
|
|
|
|
::std::option::Option::None => break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|