diff options
| author | Josh Stone <jistone@redhat.com> | 2021-04-14 12:05:24 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2021-04-16 11:12:01 -0700 |
| commit | 4d089a41b1faec8b9d4f2a6cc3efcef72eb2d6fe (patch) | |
| tree | f4fd1ba488168064f7d344fec032684109cd0199 /src | |
| parent | 25f02b276f9fb290318beb364c4d0c9e7079071f (diff) | |
| download | rust-4d089a41b1faec8b9d4f2a6cc3efcef72eb2d6fe.tar.gz rust-4d089a41b1faec8b9d4f2a6cc3efcef72eb2d6fe.zip | |
Test array into_iter with more wrapper types
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/iterators/into-iter-on-arrays-2018.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/iterators/into-iter-on-arrays-2018.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/iterators/into-iter-on-arrays-2021.rs | 19 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.rs b/src/test/ui/iterators/into-iter-on-arrays-2018.rs index 75e0a58039f..5661397b3c1 100644 --- a/src/test/ui/iterators/into-iter-on-arrays-2018.rs +++ b/src/test/ui/iterators/into-iter-on-arrays-2018.rs @@ -2,6 +2,8 @@ // edition:2018 use std::array::IntoIter; +use std::ops::Deref; +use std::rc::Rc; use std::slice::Iter; fn main() { @@ -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 + } +} diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr index b11941fe0e1..b43338382f2 100644 --- a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr +++ b/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` @@ -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` @@ -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` @@ -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` diff --git a/src/test/ui/iterators/into-iter-on-arrays-2021.rs b/src/test/ui/iterators/into-iter-on-arrays-2021.rs index 1ac31b23b59..ec54ed00517 100644 --- a/src/test/ui/iterators/into-iter-on-arrays-2021.rs +++ b/src/test/ui/iterators/into-iter-on-arrays-2021.rs @@ -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]; @@ -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 + } +} |
