Update tests for type_complexity lint

This commit is contained in:
Maybe Waffle 2021-11-25 12:47:29 +03:00
parent 063f8aa094
commit 40a6c519b4
3 changed files with 24 additions and 27 deletions

View file

@ -30,6 +30,14 @@ trait T {
fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
}
impl T for () {
const A: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
// Should not warn since there is likely no way to simplify this (#1013)
type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>;
fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
}
fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> {
vec![]
}

View file

@ -73,22 +73,34 @@ LL | fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:33:15
--> $DIR/type_complexity.rs:34:14
|
LL | const A: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:38:25
|
LL | fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:41:15
|
LL | fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:37:14
--> $DIR/type_complexity.rs:45:14
|
LL | fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:40:13
--> $DIR/type_complexity.rs:48:13
|
LL | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 15 previous errors
error: aborting due to 17 previous errors

View file

@ -1,23 +0,0 @@
#![warn(clippy::type_complexity)]
use std::iter::{Filter, Map};
use std::vec::IntoIter;
struct S;
impl IntoIterator for S {
type Item = i32;
// Should not warn since there is no way to simplify this
type IntoIter = Filter<Map<IntoIter<i32>, fn(i32) -> i32>, fn(&i32) -> bool>;
fn into_iter(self) -> Self::IntoIter {
fn m(a: i32) -> i32 {
a
}
fn p(_: &i32) -> bool {
true
}
vec![1i32, 2, 3].into_iter().map(m as fn(_) -> _).filter(p)
}
}
fn main() {}