useless_conversion: don't lint if ty param has multiple bounds
This commit is contained in:
parent
3de0f19c41
commit
e34e49f7ff
4 changed files with 128 additions and 27 deletions
|
|
@ -151,6 +151,8 @@ fn main() {
|
|||
let _ = s3;
|
||||
let s4: Foo<'a'> = Foo;
|
||||
let _ = vec![s4, s4, s4].into_iter();
|
||||
|
||||
issue11300::bar();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -196,6 +198,22 @@ fn explicit_into_iter_fn_arg() {
|
|||
b(macro_generated!());
|
||||
}
|
||||
|
||||
mod issue11300 {
|
||||
pub fn foo<I>(i: I)
|
||||
where
|
||||
I: IntoIterator<Item = i32> + ExactSizeIterator,
|
||||
{
|
||||
assert_eq!(i.len(), 3);
|
||||
}
|
||||
|
||||
pub fn bar() {
|
||||
// This should not trigger the lint:
|
||||
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
|
||||
// removed and is not useless.
|
||||
foo([1, 2, 3].into_iter());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Foo<const C: char>;
|
||||
|
||||
|
|
|
|||
|
|
@ -151,6 +151,8 @@ fn main() {
|
|||
let _ = Foo::<'a'>::from(s3);
|
||||
let s4: Foo<'a'> = Foo;
|
||||
let _ = vec![s4, s4, s4].into_iter().into_iter();
|
||||
|
||||
issue11300::bar();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -196,6 +198,22 @@ fn explicit_into_iter_fn_arg() {
|
|||
b(macro_generated!());
|
||||
}
|
||||
|
||||
mod issue11300 {
|
||||
pub fn foo<I>(i: I)
|
||||
where
|
||||
I: IntoIterator<Item = i32> + ExactSizeIterator,
|
||||
{
|
||||
assert_eq!(i.len(), 3);
|
||||
}
|
||||
|
||||
pub fn bar() {
|
||||
// This should not trigger the lint:
|
||||
// `[i32, 3]` does not satisfy the `ExactSizeIterator` bound, so the into_iter call cannot be
|
||||
// removed and is not useless.
|
||||
foo([1, 2, 3].into_iter());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Foo<const C: char>;
|
||||
|
||||
|
|
|
|||
|
|
@ -119,61 +119,61 @@ LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`
|
||||
|
||||
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
|
||||
--> $DIR/useless_conversion.rs:183:7
|
||||
--> $DIR/useless_conversion.rs:185:7
|
||||
|
|
||||
LL | b(vec![1, 2].into_iter());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
||||
|
|
||||
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
|
||||
--> $DIR/useless_conversion.rs:173:13
|
||||
--> $DIR/useless_conversion.rs:175:13
|
||||
|
|
||||
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
|
||||
--> $DIR/useless_conversion.rs:184:7
|
||||
--> $DIR/useless_conversion.rs:186:7
|
||||
|
|
||||
LL | c(vec![1, 2].into_iter());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
||||
|
|
||||
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
|
||||
--> $DIR/useless_conversion.rs:174:18
|
||||
--> $DIR/useless_conversion.rs:176:18
|
||||
|
|
||||
LL | fn c(_: impl IntoIterator<Item = i32>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
|
||||
--> $DIR/useless_conversion.rs:185:7
|
||||
--> $DIR/useless_conversion.rs:187:7
|
||||
|
|
||||
LL | d(vec![1, 2].into_iter());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
||||
|
|
||||
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
|
||||
--> $DIR/useless_conversion.rs:177:12
|
||||
--> $DIR/useless_conversion.rs:179:12
|
||||
|
|
||||
LL | T: IntoIterator<Item = i32>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
|
||||
--> $DIR/useless_conversion.rs:188:7
|
||||
--> $DIR/useless_conversion.rs:190:7
|
||||
|
|
||||
LL | b(vec![1, 2].into_iter().into_iter());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
|
||||
|
|
||||
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
|
||||
--> $DIR/useless_conversion.rs:173:13
|
||||
--> $DIR/useless_conversion.rs:175:13
|
||||
|
|
||||
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
|
||||
--> $DIR/useless_conversion.rs:189:7
|
||||
--> $DIR/useless_conversion.rs:191:7
|
||||
|
|
||||
LL | b(vec![1, 2].into_iter().into_iter().into_iter());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
|
||||
|
|
||||
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
|
||||
--> $DIR/useless_conversion.rs:173:13
|
||||
--> $DIR/useless_conversion.rs:175:13
|
||||
|
|
||||
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue