2024-02-16 20:02:50 +00:00
|
|
|
//@ check-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2015-01-11 02:44:14 +00: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.
|
|
|
|
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ pretty-expanded FIXME #23616
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-01-11 02:44:14 +00:00
|
|
|
use std::ptr;
|
|
|
|
|
|
|
|
trait IntoIterator {
|
|
|
|
type Iter: Iterator;
|
|
|
|
|
2015-04-17 21:31:30 +00:00
|
|
|
fn into_iter2(self) -> Self::Iter;
|
2015-01-11 02:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<I> IntoIterator for I where I: Iterator {
|
|
|
|
type Iter = I;
|
|
|
|
|
2015-04-17 21:31:30 +00:00
|
|
|
fn into_iter2(self) -> I {
|
2015-01-11 02:44:14 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn desugared_for_loop_bad<T>(v: Vec<T>) {
|
2015-04-17 21:31:30 +00:00
|
|
|
match IntoIterator::into_iter2(v.iter()) {
|
2015-01-11 02:44:14 +00: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 14:39:53 +00:00
|
|
|
match v.iter().into_iter() {
|
2015-01-11 02:44:14 +00: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() {}
|