Skip to content

Commit

Permalink
Auto merge of rust-lang#12736 - UlazkaMateusz:fix-type_complexity_dup…
Browse files Browse the repository at this point in the history
…licate_errors, r=xFrednet

[`type_complexity`]: Fix duplicate errors

Relates to rust-lang#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
  • Loading branch information
bors committed Apr 29, 2024
2 parents 9e02abe + 71db2d1 commit 70e74b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
12 changes: 9 additions & 3 deletions clippy_lints/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod vec_box;
use rustc_hir as hir;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitItem,
TraitItemKind, TyKind,
Body, FnDecl, FnRetTy, GenericArg, ImplItem, ImplItemKind, Item, ItemKind, LetStmt, MutTy, QPath, TraitFn,
TraitItem, TraitItemKind, TyKind,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -420,7 +420,13 @@ impl<'tcx> LateLintPass<'tcx> for Types {
TraitItemKind::Const(ty, _) | TraitItemKind::Type(_, Some(ty)) => {
self.check_ty(cx, ty, context);
},
TraitItemKind::Fn(ref sig, _) => self.check_fn_decl(cx, sig.decl, context),
TraitItemKind::Fn(ref sig, trait_method) => {
// Check only methods without body
// Methods with body are covered by check_fn.
if let TraitFn::Required(_) = trait_method {
self.check_fn_decl(cx, sig.decl, context);
}
},
TraitItemKind::Type(..) => (),
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/type_complexity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@compile-flags: -Zdeduplicate-diagnostics=yes

#![warn(clippy::all)]
#![allow(unused, clippy::needless_pass_by_value, clippy::vec_box, clippy::useless_vec)]
#![feature(associated_type_defaults)]
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/type_complexity.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: very complex type used. Consider factoring parts into `type` definitions
--> tests/ui/type_complexity.rs:9:12
--> tests/ui/type_complexity.rs:7:12
|
LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,85 +8,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
= help: to override `-D warnings` add `#[allow(clippy::type_complexity)]`

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 70e74b1

Please sign in to comment.