Skip to content

Commit 70e74b1

Browse files
committed
Auto merge of #12736 - UlazkaMateusz:fix-type_complexity_duplicate_errors, r=xFrednet
[`type_complexity`]: Fix duplicate errors Relates to #12379 Following message was duplicated: ``` LL | fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: very complex type used. Consider factoring parts into `type` definitions --> tests/ui/type_complexity.rs:55:15 ``` Methods `check_trait_item` and `check_fn` were both checking method named def_method. Now `check_trait_item` only checks methods without body. --- changelog: [`type_complexity`]: Fix duplicate diagnostics
2 parents 9e02abe + 71db2d1 commit 70e74b1

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Diff for: clippy_lints/src/types/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ mod vec_box;
1212
use rustc_hir as hir;
1313
use rustc_hir::intravisit::FnKind;
1414
use rustc_hir::{
15-
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitItem,
16-
TraitItemKind, TyKind,
15+
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitFn,
16+
TraitItem, TraitItemKind, TyKind,
1717
};
1818
use rustc_lint::{LateContext, LateLintPass};
1919
use rustc_session::impl_lint_pass;
@@ -420,7 +420,13 @@ impl<'tcx> LateLintPass<'tcx> for Types {
420420
TraitItemKind::Const(ty, _) | TraitItemKind::Type(_, Some(ty)) => {
421421
self.check_ty(cx, ty, context);
422422
},
423-
TraitItemKind::Fn(ref sig, _) => self.check_fn_decl(cx, sig.decl, context),
423+
TraitItemKind::Fn(ref sig, trait_method) => {
424+
// Check only methods without body
425+
// Methods with body are covered by check_fn.
426+
if let TraitFn::Required(_) = trait_method {
427+
self.check_fn_decl(cx, sig.decl, context);
428+
}
429+
},
424430
TraitItemKind::Type(..) => (),
425431
}
426432
}

Diff for: tests/ui/type_complexity.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@compile-flags: -Zdeduplicate-diagnostics=yes
2-
31
#![warn(clippy::all)]
42
#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box, clippy::useless_vec)]
53
#![feature(associated_type_defaults)]

Diff for: tests/ui/type_complexity.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: very complex type used. Consider factoring parts into `type` definitions
2-
--> tests/ui/type_complexity.rs:9:12
2+
--> tests/ui/type_complexity.rs:7:12
33
|
44
LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,85 +8,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
88
= help: to override `-D warnings` add `#[allow(clippy::type_complexity)]`
99

1010
error: very complex type used. Consider factoring parts into `type` definitions
11-
--> tests/ui/type_complexity.rs:12:12
11+
--> tests/ui/type_complexity.rs:10:12
1212
|
1313
LL | static ST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515

1616
error: very complex type used. Consider factoring parts into `type` definitions
17-
--> tests/ui/type_complexity.rs:16:8
17+
--> tests/ui/type_complexity.rs:14:8
1818
|
1919
LL | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2121

2222
error: very complex type used. Consider factoring parts into `type` definitions
23-
--> tests/ui/type_complexity.rs:20:11
23+
--> tests/ui/type_complexity.rs:18:11
2424
|
2525
LL | struct Ts(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

2828
error: very complex type used. Consider factoring parts into `type` definitions
29-
--> tests/ui/type_complexity.rs:24:11
29+
--> tests/ui/type_complexity.rs:22:11
3030
|
3131
LL | Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333

3434
error: very complex type used. Consider factoring parts into `type` definitions
35-
--> tests/ui/type_complexity.rs:26:17
35+
--> tests/ui/type_complexity.rs:24:17
3636
|
3737
LL | Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> },
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: very complex type used. Consider factoring parts into `type` definitions
41-
--> tests/ui/type_complexity.rs:31:14
41+
--> tests/ui/type_complexity.rs:29:14
4242
|
4343
LL | const A: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545

4646
error: very complex type used. Consider factoring parts into `type` definitions
47-
--> tests/ui/type_complexity.rs:33:30
47+
--> tests/ui/type_complexity.rs:31:30
4848
|
4949
LL | fn impl_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
error: very complex type used. Consider factoring parts into `type` definitions
53-
--> tests/ui/type_complexity.rs:38:14
53+
--> tests/ui/type_complexity.rs:36:14
5454
|
5555
LL | const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>;
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5757

5858
error: very complex type used. Consider factoring parts into `type` definitions
59-
--> tests/ui/type_complexity.rs:40:14
59+
--> tests/ui/type_complexity.rs:38:14
6060
|
6161
LL | type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>;
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363

6464
error: very complex type used. Consider factoring parts into `type` definitions
65-
--> tests/ui/type_complexity.rs:42:25
65+
--> tests/ui/type_complexity.rs:40:25
6666
|
6767
LL | fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>);
6868
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969

7070
error: very complex type used. Consider factoring parts into `type` definitions
71-
--> tests/ui/type_complexity.rs:44:29
71+
--> tests/ui/type_complexity.rs:42:29
7272
|
7373
LL | fn def_method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7575

7676
error: very complex type used. Consider factoring parts into `type` definitions
77-
--> tests/ui/type_complexity.rs:57:15
77+
--> tests/ui/type_complexity.rs:55:15
7878
|
7979
LL | fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> {
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8181

8282
error: very complex type used. Consider factoring parts into `type` definitions
83-
--> tests/ui/type_complexity.rs:62:14
83+
--> tests/ui/type_complexity.rs:60:14
8484
|
8585
LL | fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
error: very complex type used. Consider factoring parts into `type` definitions
89-
--> tests/ui/type_complexity.rs:66:13
89+
--> tests/ui/type_complexity.rs:64:13
9090
|
9191
LL | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)