Skip to content

Commit db9c9b9

Browse files
committed
add another test
1 parent 96dfe52 commit db9c9b9

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

tests/ui/useless_conversion.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ mod issue11300 {
205205
{
206206
}
207207

208+
209+
trait Helper2<T> {}
210+
impl Helper2<std::array::IntoIter<i32, 3>> for i32 {}
211+
impl Helper2<[i32; 3]> for i32 {}
212+
fn foo3<I>(_: I)
213+
where
214+
I: IntoIterator<Item = i32>,
215+
i32: Helper2<I>
216+
{
217+
}
218+
208219
pub fn bar() {
209220
// This should not trigger the lint:
210221
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
@@ -217,6 +228,10 @@ mod issue11300 {
217228
// This again should *not* lint, since X = () and I = std::array::IntoIter<i32, 3>,
218229
// and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter<i32, 3>: Helper<()>` is).
219230
foo2::<(), _>([1, 2, 3].into_iter());
231+
232+
// This should lint. `I` gets substituted with `[i32; 3]`, and
233+
// `i32: Helper<[i32, 3]>` is true.
234+
foo3([1, 2, 3]);
220235
}
221236
}
222237

tests/ui/useless_conversion.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ mod issue11300 {
205205
{
206206
}
207207

208+
209+
trait Helper2<T> {}
210+
impl Helper2<std::array::IntoIter<i32, 3>> for i32 {}
211+
impl Helper2<[i32; 3]> for i32 {}
212+
fn foo3<I>(_: I)
213+
where
214+
I: IntoIterator<Item = i32>,
215+
i32: Helper2<I>
216+
{
217+
}
218+
208219
pub fn bar() {
209220
// This should not trigger the lint:
210221
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
@@ -217,6 +228,10 @@ mod issue11300 {
217228
// This again should *not* lint, since X = () and I = std::array::IntoIter<i32, 3>,
218229
// and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter<i32, 3>: Helper<()>` is).
219230
foo2::<(), _>([1, 2, 3].into_iter());
231+
232+
// This should lint. `I` gets substituted with `[i32; 3]`, and
233+
// `i32: Helper<[i32, 3]>` is true.
234+
foo3([1, 2, 3].into_iter());
220235
}
221236
}
222237

tests/ui/useless_conversion.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
179179
| ^^^^^^^^^^^^^^^^^^^^^^^^
180180

181181
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
182-
--> $DIR/useless_conversion.rs:215:24
182+
--> $DIR/useless_conversion.rs:226:24
183183
|
184184
LL | foo2::<i32, _>([1, 2, 3].into_iter());
185185
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
@@ -190,5 +190,17 @@ note: this parameter accepts any `IntoIterator`, so you don't need to call `.int
190190
LL | I: IntoIterator<Item = i32> + Helper<X>,
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^
192192

193-
error: aborting due to 25 previous errors
193+
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
194+
--> $DIR/useless_conversion.rs:234:14
195+
|
196+
LL | foo3([1, 2, 3].into_iter());
197+
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
198+
|
199+
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
200+
--> $DIR/useless_conversion.rs:214:12
201+
|
202+
LL | I: IntoIterator<Item = i32>,
203+
| ^^^^^^^^^^^^^^^^^^^^^^^^
204+
205+
error: aborting due to 26 previous errors
194206

0 commit comments

Comments
 (0)