Auto merge of #6938 - Y-Nak:refactor-types, r=flip1995
Refactor types r? `@flip1995` This is the last PR to close #6724 🎉 Also, this fixes #6936. changelog: `vec_box`: Fix FN in `const` or `static` changelog: `linkedlist`: Fix FN in `const` or `static` changelog: `option_option`: Fix FN in `const` or `static`
This commit is contained in:
commit
2e33bf6347
15 changed files with 1132 additions and 1055 deletions
|
|
@ -5,6 +5,9 @@
|
|||
extern crate alloc;
|
||||
use alloc::collections::linked_list::LinkedList;
|
||||
|
||||
const C: LinkedList<i32> = LinkedList::new();
|
||||
static S: LinkedList<i32> = LinkedList::new();
|
||||
|
||||
trait Foo {
|
||||
type Baz = LinkedList<u8>;
|
||||
fn foo(_: LinkedList<u8>);
|
||||
|
|
@ -1,14 +1,30 @@
|
|||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:9:16
|
||||
--> $DIR/linkedlist.rs:8:10
|
||||
|
|
||||
LL | type Baz = LinkedList<u8>;
|
||||
| ^^^^^^^^^^^^^^
|
||||
LL | const C: LinkedList<i32> = LinkedList::new();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::linkedlist` implied by `-D warnings`
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:10:15
|
||||
--> $DIR/linkedlist.rs:9:11
|
||||
|
|
||||
LL | static S: LinkedList<i32> = LinkedList::new();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/linkedlist.rs:12:16
|
||||
|
|
||||
LL | type Baz = LinkedList<u8>;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/linkedlist.rs:13:15
|
||||
|
|
||||
LL | fn foo(_: LinkedList<u8>);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -16,7 +32,7 @@ LL | fn foo(_: LinkedList<u8>);
|
|||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:11:23
|
||||
--> $DIR/linkedlist.rs:14:23
|
||||
|
|
||||
LL | const BAR: Option<LinkedList<u8>>;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -24,7 +40,7 @@ LL | const BAR: Option<LinkedList<u8>>;
|
|||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:22:15
|
||||
--> $DIR/linkedlist.rs:25:15
|
||||
|
|
||||
LL | fn foo(_: LinkedList<u8>) {}
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -32,7 +48,7 @@ LL | fn foo(_: LinkedList<u8>) {}
|
|||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:25:39
|
||||
--> $DIR/linkedlist.rs:28:39
|
||||
|
|
||||
LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -40,12 +56,12 @@ LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
|
|||
= help: a `VecDeque` might work
|
||||
|
||||
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
|
||||
--> $DIR/dlist.rs:29:29
|
||||
--> $DIR/linkedlist.rs:32:29
|
||||
|
|
||||
LL | pub fn test_ret() -> Option<LinkedList<u8>> {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: a `VecDeque` might work
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#![deny(clippy::option_option)]
|
||||
#![allow(clippy::unnecessary_wraps)]
|
||||
|
||||
const C: Option<Option<i32>> = None;
|
||||
static S: Option<Option<i32>> = None;
|
||||
|
||||
fn input(_: Option<Option<u8>>) {}
|
||||
|
||||
fn output() -> Option<Option<u8>> {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:4:13
|
||||
--> $DIR/option_option.rs:4:10
|
||||
|
|
||||
LL | fn input(_: Option<Option<u8>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | const C: Option<Option<i32>> = None;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/option_option.rs:1:9
|
||||
|
|
@ -11,58 +11,70 @@ LL | #![deny(clippy::option_option)]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:6:16
|
||||
--> $DIR/option_option.rs:5:11
|
||||
|
|
||||
LL | static S: Option<Option<i32>> = None;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:7:13
|
||||
|
|
||||
LL | fn input(_: Option<Option<u8>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:9:16
|
||||
|
|
||||
LL | fn output() -> Option<Option<u8>> {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:10:27
|
||||
--> $DIR/option_option.rs:13:27
|
||||
|
|
||||
LL | fn output_nested() -> Vec<Option<Option<u8>>> {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:15:30
|
||||
--> $DIR/option_option.rs:18:30
|
||||
|
|
||||
LL | fn output_nested_nested() -> Option<Option<Option<u8>>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:20:8
|
||||
--> $DIR/option_option.rs:23:8
|
||||
|
|
||||
LL | x: Option<Option<u8>>,
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:24:23
|
||||
--> $DIR/option_option.rs:27:23
|
||||
|
|
||||
LL | fn struct_fn() -> Option<Option<u8>> {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:30:22
|
||||
--> $DIR/option_option.rs:33:22
|
||||
|
|
||||
LL | fn trait_fn() -> Option<Option<u8>>;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:34:11
|
||||
--> $DIR/option_option.rs:37:11
|
||||
|
|
||||
LL | Tuple(Option<Option<u8>>),
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:35:17
|
||||
--> $DIR/option_option.rs:38:17
|
||||
|
|
||||
LL | Struct { x: Option<Option<u8>> },
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
|
||||
--> $DIR/option_option.rs:76:14
|
||||
--> $DIR/option_option.rs:79:14
|
||||
|
|
||||
LL | foo: Option<Option<Cow<'a, str>>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:7:12
|
||||
--> $DIR/type_complexity.rs:7:12
|
||||
|
|
||||
LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -7,85 +7,85 @@ LL | const CST: (u32, (u32, (u32, (u32, u32)))) = (0, (0, (0, (0, 0))));
|
|||
= note: `-D clippy::type-complexity` implied by `-D warnings`
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:8:12
|
||||
--> $DIR/type_complexity.rs:8: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
|
||||
--> $DIR/complex_types.rs:11:8
|
||||
--> $DIR/type_complexity.rs:11:8
|
||||
|
|
||||
LL | f: Vec<Vec<Box<(u32, u32, u32, u32)>>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:14:11
|
||||
--> $DIR/type_complexity.rs:14:11
|
||||
|
|
||||
LL | struct Ts(Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:17:11
|
||||
--> $DIR/type_complexity.rs:17:11
|
||||
|
|
||||
LL | Tuple(Vec<Vec<Box<(u32, u32, u32, u32)>>>),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:18:17
|
||||
--> $DIR/type_complexity.rs:18:17
|
||||
|
|
||||
LL | Struct { f: Vec<Vec<Box<(u32, u32, u32, u32)>>> },
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:22:14
|
||||
--> $DIR/type_complexity.rs:22: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
|
||||
--> $DIR/complex_types.rs:23:30
|
||||
--> $DIR/type_complexity.rs:23: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
|
||||
--> $DIR/complex_types.rs:27:14
|
||||
--> $DIR/type_complexity.rs:27:14
|
||||
|
|
||||
LL | const A: Vec<Vec<Box<(u32, u32, u32, u32)>>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:28:14
|
||||
--> $DIR/type_complexity.rs:28:14
|
||||
|
|
||||
LL | type B = Vec<Vec<Box<(u32, u32, u32, u32)>>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:29:25
|
||||
--> $DIR/type_complexity.rs:29:25
|
||||
|
|
||||
LL | fn method(&self, p: Vec<Vec<Box<(u32, u32, u32, u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:30:29
|
||||
--> $DIR/type_complexity.rs:30: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
|
||||
--> $DIR/complex_types.rs:33:15
|
||||
--> $DIR/type_complexity.rs:33:15
|
||||
|
|
||||
LL | fn test1() -> Vec<Vec<Box<(u32, u32, u32, u32)>>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:37:14
|
||||
--> $DIR/type_complexity.rs:37:14
|
||||
|
|
||||
LL | fn test2(_x: Vec<Vec<Box<(u32, u32, u32, u32)>>>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: very complex type used. Consider factoring parts into `type` definitions
|
||||
--> $DIR/complex_types.rs:40:13
|
||||
--> $DIR/type_complexity.rs:40:13
|
||||
|
|
||||
LL | let _y: Vec<Vec<Box<(u32, u32, u32, u32)>>> = vec![];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -9,6 +9,8 @@ struct BigStruct([i32; 10000]);
|
|||
/// The following should trigger the lint
|
||||
mod should_trigger {
|
||||
use super::SizedStruct;
|
||||
const C: Vec<i32> = Vec::new();
|
||||
static S: Vec<i32> = Vec::new();
|
||||
|
||||
struct StructWithVecBox {
|
||||
sized_type: Vec<SizedStruct>,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ struct BigStruct([i32; 10000]);
|
|||
/// The following should trigger the lint
|
||||
mod should_trigger {
|
||||
use super::SizedStruct;
|
||||
const C: Vec<Box<i32>> = Vec::new();
|
||||
static S: Vec<Box<i32>> = Vec::new();
|
||||
|
||||
struct StructWithVecBox {
|
||||
sized_type: Vec<Box<SizedStruct>>,
|
||||
|
|
|
|||
|
|
@ -1,28 +1,40 @@
|
|||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:14:21
|
||||
--> $DIR/vec_box_sized.rs:12:14
|
||||
|
|
||||
LL | sized_type: Vec<Box<SizedStruct>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
LL | const C: Vec<Box<i32>> = Vec::new();
|
||||
| ^^^^^^^^^^^^^ help: try: `Vec<i32>`
|
||||
|
|
||||
= note: `-D clippy::vec-box` implied by `-D warnings`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:17:14
|
||||
--> $DIR/vec_box_sized.rs:13:15
|
||||
|
|
||||
LL | static S: Vec<Box<i32>> = Vec::new();
|
||||
| ^^^^^^^^^^^^^ help: try: `Vec<i32>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:16:21
|
||||
|
|
||||
LL | sized_type: Vec<Box<SizedStruct>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:19:14
|
||||
|
|
||||
LL | struct A(Vec<Box<SizedStruct>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:18:18
|
||||
--> $DIR/vec_box_sized.rs:20:18
|
||||
|
|
||||
LL | struct B(Vec<Vec<Box<(u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:46:23
|
||||
--> $DIR/vec_box_sized.rs:48:23
|
||||
|
|
||||
LL | pub fn f() -> Vec<Box<S>> {
|
||||
| ^^^^^^^^^^^ help: try: `Vec<S>`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue