Skip to content

Commit d2b2fb9

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

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

tests/ui/useless_conversion.fixed

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

208+
trait Helper2<T> {}
209+
impl Helper2<std::array::IntoIter<i32, 3>> for i32 {}
210+
impl Helper2<[i32; 3]> for i32 {}
211+
fn foo3<I>(_: I)
212+
where
213+
I: IntoIterator<Item = i32>,
214+
i32: Helper2<I>,
215+
{
216+
}
217+
208218
pub fn bar() {
209219
// This should not trigger the lint:
210220
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
@@ -217,6 +227,10 @@ mod issue11300 {
217227
// This again should *not* lint, since X = () and I = std::array::IntoIter<i32, 3>,
218228
// and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter<i32, 3>: Helper<()>` is).
219229
foo2::<(), _>([1, 2, 3].into_iter());
230+
231+
// This should lint. `I` gets substituted with `[i32; 3]`, and
232+
// `i32: Helper<[i32, 3]>` is true.
233+
foo3([1, 2, 3]);
220234
}
221235
}
222236

tests/ui/useless_conversion.rs

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

208+
trait Helper2<T> {}
209+
impl Helper2<std::array::IntoIter<i32, 3>> for i32 {}
210+
impl Helper2<[i32; 3]> for i32 {}
211+
fn foo3<I>(_: I)
212+
where
213+
I: IntoIterator<Item = i32>,
214+
i32: Helper2<I>,
215+
{
216+
}
217+
208218
pub fn bar() {
209219
// This should not trigger the lint:
210220
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
@@ -217,6 +227,10 @@ mod issue11300 {
217227
// This again should *not* lint, since X = () and I = std::array::IntoIter<i32, 3>,
218228
// and `[i32; 3]: Helper<()>` is not true (only `std::array::IntoIter<i32, 3>: Helper<()>` is).
219229
foo2::<(), _>([1, 2, 3].into_iter());
230+
231+
// This should lint. `I` gets substituted with `[i32; 3]`, and
232+
// `i32: Helper<[i32, 3]>` is true.
233+
foo3([1, 2, 3].into_iter());
220234
}
221235
}
222236

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:225: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:233: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:213:12
201+
|
202+
LL | I: IntoIterator<Item = i32>,
203+
| ^^^^^^^^^^^^^^^^^^^^^^^^
204+
205+
error: aborting due to 26 previous errors
194206

0 commit comments

Comments
 (0)