Test array into_iter with more wrapper types
This commit is contained in:
parent
25f02b276f
commit
4d089a41b1
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user