mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-14 01:25:54 +00:00
Ignore associated types in traits when considering type complexity
This commit is contained in:
parent
35b0f2438d
commit
063f8aa094
@ -350,7 +350,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ImplItemKind::Const(ty, _) | ImplItemKind::TyAlias(ty) => self.check_ty(
|
ImplItemKind::Const(ty, _) => self.check_ty(
|
||||||
cx,
|
cx,
|
||||||
ty,
|
ty,
|
||||||
CheckTyContext {
|
CheckTyContext {
|
||||||
@ -358,8 +358,10 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
..CheckTyContext::default()
|
..CheckTyContext::default()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// methods are covered by check_fn
|
// Methods are covered by check_fn.
|
||||||
ImplItemKind::Fn(..) => (),
|
// Type aliases are ignored because oftentimes it's impossible to
|
||||||
|
// make type alias declaration in trait simpler, see #1013
|
||||||
|
ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
tests/ui/type_complexity_issue_1013.rs
Normal file
23
tests/ui/type_complexity_issue_1013.rs
Normal file
@ -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() {}
|
Loading…
Reference in New Issue
Block a user