rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

`clippy::type_complexity` has become more sensitive

Open kpreid opened this issue 3 years ago • 1 comments

Summary

The following code (an excerpt from my actual code) produces a clippy::type_complexity warning on nightly, but not on stable 1.62.1. I think this should be considered a regression, because the type does not really have very much nesting to it, and would not be made clearer by introducing a type alias — it's “just” a boxed function.

Lint Name

type_complexity

Reproducer

use std::{error::Error, rc::Rc};

type PredicateRes = Result<(), Box<dyn Error>>;
struct TransactionAndPredicate<'a, Tr, Ta> {
    transaction: Tr,
    predicate: Rc<dyn Fn(&Ta, &Ta) -> PredicateRes + 'a>,
}

I saw this happen:

warning: very complex type used. Consider factoring parts into `type` definitions
 --> src/lib.rs:6:16
  |
6 |     predicate: Rc<dyn Fn(&Ta, &Ta) -> PredicateRes + 'a>,
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::type_complexity)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

I expected to see this happen: No warning.

Version

rustc 1.64.0-nightly (affe0d3a0 2022-08-05)
binary: rustc
commit-hash: affe0d3a00e92fa7885e3f5d2c5073fde432d154
commit-date: 2022-08-05
host: x86_64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6

Additional Labels

No response

kpreid avatar Aug 07 '22 18:08 kpreid

PolyTraitRef.bound_generic_params changed. Used to be []. Now [GenericParam; GenericParam].

lengyijun avatar Aug 08 '22 05:08 lengyijun

I'm also seeing a bunch of clippy warnings for rather basic types now, with 1.63.0.

warning: very complex type used. Consider factoring parts into `type` definitions
  --> druid\src\widget\env_scope.rs:25:19
   |
25 |     pub(crate) f: Box<dyn Fn(&mut Env, &T)>,
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity

xStrom avatar Aug 16 '22 03:08 xStrom