Skip to content

Commit 063f8aa

Browse files
committed
Ignore associated types in traits when considering type complexity
1 parent 35b0f24 commit 063f8aa

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

clippy_lints/src/types/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,18 @@ impl<'tcx> LateLintPass<'tcx> for Types {
350350

351351
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
352352
match item.kind {
353-
ImplItemKind::Const(ty, _) | ImplItemKind::TyAlias(ty) => self.check_ty(
353+
ImplItemKind::Const(ty, _) => self.check_ty(
354354
cx,
355355
ty,
356356
CheckTyContext {
357357
is_in_trait_impl: true,
358358
..CheckTyContext::default()
359359
},
360360
),
361-
// methods are covered by check_fn
362-
ImplItemKind::Fn(..) => (),
361+
// Methods are covered by check_fn.
362+
// Type aliases are ignored because oftentimes it's impossible to
363+
// make type alias declaration in trait simpler, see #1013
364+
ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (),
363365
}
364366
}
365367

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![warn(clippy::type_complexity)]
2+
use std::iter::{Filter, Map};
3+
use std::vec::IntoIter;
4+
5+
struct S;
6+
7+
impl IntoIterator for S {
8+
type Item = i32;
9+
// Should not warn since there is no way to simplify this
10+
type IntoIter = Filter<Map<IntoIter<i32>, fn(i32) -> i32>, fn(&i32) -> bool>;
11+
12+
fn into_iter(self) -> Self::IntoIter {
13+
fn m(a: i32) -> i32 {
14+
a
15+
}
16+
fn p(_: &i32) -> bool {
17+
true
18+
}
19+
vec![1i32, 2, 3].into_iter().map(m as fn(_) -> _).filter(p)
20+
}
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)