Skip to content

Commit 4d089a4

Browse files
committed
Test array into_iter with more wrapper types
1 parent 25f02b2 commit 4d089a4

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/test/ui/iterators/into-iter-on-arrays-2018.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// edition:2018
33

44
use std::array::IntoIter;
5+
use std::ops::Deref;
6+
use std::rc::Rc;
57
use std::slice::Iter;
68

79
fn main() {
@@ -17,6 +19,21 @@ fn main() {
1719
//~^ WARNING this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter`
1820
//~| WARNING this was previously accepted by the compiler but is being phased out
1921

22+
// The `array_into_iter` lint doesn't cover other wrappers that deref to an array.
23+
let _: Iter<'_, i32> = Rc::new(array).into_iter();
24+
let _: Iter<'_, i32> = Array(array).into_iter();
25+
2026
// But you can always use the trait method explicitly as an array.
2127
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
2228
}
29+
30+
/// User type that dereferences to an array.
31+
struct Array([i32; 10]);
32+
33+
impl Deref for Array {
34+
type Target = [i32; 10];
35+
36+
fn deref(&self) -> &Self::Target {
37+
&self.0
38+
}
39+
}

src/test/ui/iterators/into-iter-on-arrays-2018.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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.
2-
--> $DIR/into-iter-on-arrays-2018.rs:12:34
2+
--> $DIR/into-iter-on-arrays-2018.rs:14:34
33
|
44
LL | let _: Iter<'_, i32> = array.into_iter();
55
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -9,7 +9,7 @@ LL | let _: Iter<'_, i32> = array.into_iter();
99
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
1010

1111
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.
12-
--> $DIR/into-iter-on-arrays-2018.rs:16:44
12+
--> $DIR/into-iter-on-arrays-2018.rs:18:44
1313
|
1414
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
1515
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -21,7 +21,7 @@ warning: 2 warnings emitted
2121

2222
Future incompatibility report: Future breakage date: None, diagnostic:
2323
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.
24-
--> $DIR/into-iter-on-arrays-2018.rs:12:34
24+
--> $DIR/into-iter-on-arrays-2018.rs:14:34
2525
|
2626
LL | let _: Iter<'_, i32> = array.into_iter();
2727
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
@@ -32,7 +32,7 @@ LL | let _: Iter<'_, i32> = array.into_iter();
3232

3333
Future breakage date: None, diagnostic:
3434
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.
35-
--> $DIR/into-iter-on-arrays-2018.rs:16:44
35+
--> $DIR/into-iter-on-arrays-2018.rs:18:44
3636
|
3737
LL | let _: Iter<'_, i32> = Box::new(array).into_iter();
3838
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`

src/test/ui/iterators/into-iter-on-arrays-2021.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// compile-flags: -Zunstable-options
44

55
use std::array::IntoIter;
6+
use std::ops::Deref;
7+
use std::rc::Rc;
68

79
fn main() {
810
let array = [0; 10];
@@ -11,6 +13,21 @@ fn main() {
1113
let _: IntoIter<i32, 10> = array.into_iter();
1214
let _: IntoIter<i32, 10> = Box::new(array).into_iter();
1315

14-
// And you can always use the trait method explicitly as an array.
16+
// The `array_into_iter` lint doesn't cover other wrappers that deref to an array.
17+
let _: IntoIter<i32, 10> = Rc::new(array).into_iter();
18+
let _: IntoIter<i32, 10> = Array(array).into_iter();
19+
20+
// You can always use the trait method explicitly as an array.
1521
let _: IntoIter<i32, 10> = IntoIterator::into_iter(array);
1622
}
23+
24+
/// User type that dereferences to an array.
25+
struct Array([i32; 10]);
26+
27+
impl Deref for Array {
28+
type Target = [i32; 10];
29+
30+
fn deref(&self) -> &Self::Target {
31+
&self.0
32+
}
33+
}

0 commit comments

Comments
 (0)