Test Box::new(array).into_iter()

This commit is contained in:
Josh Stone 2021-04-13 12:37:19 -07:00
parent 3dab4e22d4
commit 25f02b276f
3 changed files with 29 additions and 4 deletions

View File

@ -1,4 +1,5 @@
// check-pass
// edition:2018
use std::array::IntoIter;
use std::slice::Iter;
@ -6,12 +7,16 @@ use std::slice::Iter;
fn main() {
let array = [0; 10];
// Before 2021, the method dispatched to `IntoIterator for &[T]`,
// Before 2021, the method dispatched to `IntoIterator for &[T; N]`,
// 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
let _: Iter<'_, i32> = Box::new(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);
}

View File

@ -1,5 +1,5 @@
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
--> $DIR/into-iter-on-arrays-2018.rs:12:34
|
LL | let _: Iter<'_, i32> = array.into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@ -8,11 +8,20 @@ LL | let _: Iter<'_, i32> = array.into_iter();
= 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
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:16:44
|
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
= 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: 2 warnings 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
--> $DIR/into-iter-on-arrays-2018.rs:12:34
|
LL | let _: Iter<'_, i32> = array.into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@ -21,3 +30,13 @@ LL | let _: Iter<'_, i32> = array.into_iter();
= 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>
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:16:44
|
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
= 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>

View File

@ -9,6 +9,7 @@ fn main() {
// In 2021, the method dispatches to `IntoIterator for [T; N]`.
let _: IntoIter<i32, 10> = array.into_iter();
let _: IntoIter<i32, 10> = Box::new(array).into_iter();
// And you can always use the trait method explicitly as an array.
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);