You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::u8;traitIntoIterator{typeIter:Iterator;fninto_iter(self) -> Self::Iter;}impl<I>IntoIteratorforIwhereI:Iterator{typeIter = I;fninto_iter(self) -> I{self}}fnold_for_loop(byte:u8) -> u8{letmut result = 0;for i inrange(0, u8::BITS){
result |= ((byte >> i)&1) << (u8::BITS - 1 - i);}
result
}fndesugared_for_loop_bad(byte:u8) -> u8{letmut result = 0;matchIntoIterator::into_iter(range(0, u8::BITS)){mut iter => {loop{match::std::iter::Iterator::next(&mut iter){::std::option::Option::Some(i) => {
result |= ((byte >> i)&1) << (u8::BITS - 1 - i);//~^ error: right-hand-side of a shift operation must have integral type, not `_`},::std::option::Option::None => break}}}}
result
}fndesugared_for_loop_good(byte:u8) -> u8{letmut result = 0;matchrange(0, u8::BITS).into_iter(){// NB method call instead of UFCSmut iter => {loop{match::std::iter::Iterator::next(&mut iter){::std::option::Option::Some(i) => {
result |= ((byte >> i)&1) << (u8::BITS - 1 - i);},::std::option::Option::None => break}}}}
result
}fnmain(){}
use std::ptr;traitIntoIterator{typeIter:Iterator;fninto_iter(self) -> Self::Iter;}impl<I>IntoIteratorforIwhereI:Iterator{typeIter = I;fninto_iter(self) -> I{self}}fnold_for_loop<T>(v:Vec<T>){for x in v.iter(){unsafe{ ptr::read(x);}}}fndesugared_for_loop_bad<T>(v:Vec<T>){matchIntoIterator::into_iter(v.iter()){mut iter => {loop{match::std::iter::Iterator::next(&mut iter){::std::option::Option::Some(x) => {unsafe{ ptr::read(x);}//~^ error: type mismatch resolving `<core::slice::Iter<'_, T> as core::iter::Iterator>::Item == *const _`: expected &-ptr, found *-ptr},::std::option::Option::None => break}}}}}fndesugared_for_loop_good<T>(v:Vec<T>){match v.iter().into_iter(){// NB method call instead of UFCSmut iter => {loop{match::std::iter::Iterator::next(&mut iter){::std::option::Option::Some(x) => {unsafe{ ptr::read(x);}},::std::option::Option::None => break}}}}}fnmain(){}
Type inference works fine with method calls (into_iter()), but fails with UFCS (IntoIterator::into_iter()).
STR
Type inference works fine with method calls (
into_iter()
), but fails with UFCS (IntoIterator::into_iter()
).Version
This is blocking migration to the new for loops (#20790).
cc @nikomatsakis
The text was updated successfully, but these errors were encountered: