Skip to content

Commit

Permalink
Test array into_iter with more wrapper types
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Apr 16, 2021
1 parent 25f02b2 commit 4d089a4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/test/ui/iterators/into-iter-on-arrays-2018.rs
Expand Up @@ -2,6 +2,8 @@
// edition:2018

use std::array::IntoIter;
use std::ops::Deref;
use std::rc::Rc;
use std::slice::Iter;

fn main() {
Expand All @@ -17,6 +19,21 @@ fn main() {
//~^ 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

// The `array_into_iter` lint doesn't cover other wrappers that deref to an array.
let _: Iter<'_, i32> = Rc::new(array).into_iter();
let _: Iter<'_, i32> = Array(array).into_iter();

// But you can always use the trait method explicitly as an array.
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
}

/// User type that dereferences to an array.
struct Array([i32; 10]);

impl Deref for Array {
type Target = [i32; 10];

fn deref(&self) -> &Self::Target {
&self.0
}
}
8 changes: 4 additions & 4 deletions src/test/ui/iterators/into-iter-on-arrays-2018.stderr
@@ -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:12:34
--> $DIR/into-iter-on-arrays-2018.rs:14:34
|
LL | let _: Iter<'_, i32> = array.into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -9,7 +9,7 @@ LL | let _: Iter<'_, i32> = array.into_iter();
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>

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
--> $DIR/into-iter-on-arrays-2018.rs:18:44
|
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -21,7 +21,7 @@ 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:12:34
--> $DIR/into-iter-on-arrays-2018.rs:14:34
|
LL | let _: Iter<'_, i32> = array.into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand All @@ -32,7 +32,7 @@ LL | let _: Iter<'_, i32> = array.into_iter();

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
--> $DIR/into-iter-on-arrays-2018.rs:18:44
|
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
Expand Down
19 changes: 18 additions & 1 deletion src/test/ui/iterators/into-iter-on-arrays-2021.rs
Expand Up @@ -3,6 +3,8 @@
// compile-flags: -Zunstable-options

use std::array::IntoIter;
use std::ops::Deref;
use std::rc::Rc;

fn main() {
let array = [0; 10];
Expand All @@ -11,6 +13,21 @@ fn main() {
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.
// The `array_into_iter` lint doesn't cover other wrappers that deref to an array.
let _: IntoIter<i32, 10> = Rc::new(array).into_iter();
let _: IntoIter<i32, 10> = Array(array).into_iter();

// You can always use the trait method explicitly as an array.
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
}

/// User type that dereferences to an array.
struct Array([i32; 10]);

impl Deref for Array {
type Target = [i32; 10];

fn deref(&self) -> &Self::Target {
&self.0
}
}

0 comments on commit 4d089a4

Please sign in to comment.