Skip into_iter() for arrays before 2021
This commit is contained in:
parent
35b1590223
commit
3dab4e22d4
5 changed files with 60 additions and 0 deletions
17
src/test/ui/iterators/into-iter-on-arrays-2018.rs
Normal file
17
src/test/ui/iterators/into-iter-on-arrays-2018.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// check-pass
|
||||
|
||||
use std::array::IntoIter;
|
||||
use std::slice::Iter;
|
||||
|
||||
fn main() {
|
||||
let array = [0; 10];
|
||||
|
||||
// Before 2021, the method dispatched to `IntoIterator for &[T]`,
|
||||
// which we continue to support for compatibility.
|
||||
let _: Iter<'_, i32> = array.into_iter();
|
||||
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
|
||||
//~| WARNING this was previously accepted by the compiler but is being phased out
|
||||
|
||||
// But you can always use the trait method explicitly as an array.
|
||||
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
|
||||
}
|
||||
23
src/test/ui/iterators/into-iter-on-arrays-2018.stderr
Normal file
23
src/test/ui/iterators/into-iter-on-arrays-2018.stderr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
|
||||
--> $DIR/into-iter-on-arrays-2018.rs:11:34
|
||||
|
|
||||
LL | let _: Iter<'_, i32> = array.into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
|
||||
= note: `#[warn(array_into_iter)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
Future incompatibility report: Future breakage date: None, diagnostic:
|
||||
warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
|
||||
--> $DIR/into-iter-on-arrays-2018.rs:11:34
|
||||
|
|
||||
LL | let _: Iter<'_, i32> = array.into_iter();
|
||||
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
||||
|
|
||||
= note: `#[warn(array_into_iter)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
|
||||
|
||||
15
src/test/ui/iterators/into-iter-on-arrays-2021.rs
Normal file
15
src/test/ui/iterators/into-iter-on-arrays-2021.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// check-pass
|
||||
// edition:2021
|
||||
// compile-flags: -Zunstable-options
|
||||
|
||||
use std::array::IntoIter;
|
||||
|
||||
fn main() {
|
||||
let array = [0; 10];
|
||||
|
||||
// In 2021, the method dispatches to `IntoIterator for [T; N]`.
|
||||
let _: IntoIter<i32, 10> = array.into_iter();
|
||||
|
||||
// And you can always use the trait method explicitly as an array.
|
||||
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue