Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore associated types in traits when considering type complexity #8030

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clippy_lints/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,18 @@ impl<'tcx> LateLintPass<'tcx> for Types {

fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
match item.kind {
ImplItemKind::Const(ty, _) | ImplItemKind::TyAlias(ty) => self.check_ty(
ImplItemKind::Const(ty, _) => self.check_ty(
cx,
ty,
CheckTyContext {
is_in_trait_impl: true,
..CheckTyContext::default()
},
),
// methods are covered by check_fn
ImplItemKind::Fn(..) => (),
// Methods are covered by check_fn.
// Type aliases are ignored because oftentimes it's impossible to
// make type alias declaration in trait simpler, see #1013
ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (),
}
}

Expand Down
23 changes: 23 additions & 0 deletions tests/ui/type_complexity_issue_1013.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![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() {}