mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
mem_discriminant: split test, make rustfixable
This commit is contained in:
parent
483e140bce
commit
0d8e4d7c37
5 changed files with 100 additions and 33 deletions
45
tests/ui/mem_discriminant.fixed
Normal file
45
tests/ui/mem_discriminant.fixed
Normal file
|
@ -0,0 +1,45 @@
|
|||
// run-rustfix
|
||||
|
||||
#![deny(clippy::mem_discriminant_non_enum)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
enum Foo {
|
||||
One(usize),
|
||||
Two(u8),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// bad
|
||||
mem::discriminant(&Some(2));
|
||||
mem::discriminant(&None::<u8>);
|
||||
mem::discriminant(&Foo::One(5));
|
||||
mem::discriminant(&Foo::Two(5));
|
||||
|
||||
let ro = &Some(3);
|
||||
let rro = &ro;
|
||||
mem::discriminant(ro);
|
||||
mem::discriminant(*rro);
|
||||
mem::discriminant(*rro);
|
||||
|
||||
macro_rules! mem_discriminant_but_in_a_macro {
|
||||
($param:expr) => {
|
||||
mem::discriminant($param)
|
||||
};
|
||||
}
|
||||
|
||||
mem_discriminant_but_in_a_macro!(*rro);
|
||||
|
||||
let rrrrro = &&&rro;
|
||||
mem::discriminant(****rrrrro);
|
||||
mem::discriminant(****rrrrro);
|
||||
|
||||
// ok
|
||||
mem::discriminant(&Some(2));
|
||||
mem::discriminant(&None::<u8>);
|
||||
mem::discriminant(&Foo::One(5));
|
||||
mem::discriminant(&Foo::Two(5));
|
||||
mem::discriminant(ro);
|
||||
mem::discriminant(*rro);
|
||||
mem::discriminant(****rrrrro);
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// run-rustfix
|
||||
|
||||
#![deny(clippy::mem_discriminant_non_enum)]
|
||||
|
||||
use std::mem;
|
||||
|
@ -7,16 +9,12 @@ enum Foo {
|
|||
Two(u8),
|
||||
}
|
||||
|
||||
struct A(Foo);
|
||||
|
||||
fn main() {
|
||||
// bad
|
||||
mem::discriminant(&"hello");
|
||||
mem::discriminant(&&Some(2));
|
||||
mem::discriminant(&&None::<u8>);
|
||||
mem::discriminant(&&Foo::One(5));
|
||||
mem::discriminant(&&Foo::Two(5));
|
||||
mem::discriminant(&A(Foo::One(0)));
|
||||
|
||||
let ro = &Some(3);
|
||||
let rro = &ro;
|
||||
|
|
|
@ -1,25 +1,19 @@
|
|||
error: calling `mem::discriminant` on non-enum type `&str`
|
||||
--> $DIR/mem_discriminant.rs:14:5
|
||||
|
|
||||
LL | mem::discriminant(&"hello");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/mem_discriminant.rs:1:9
|
||||
|
|
||||
LL | #![deny(clippy::mem_discriminant_non_enum)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:15:5
|
||||
--> $DIR/mem_discriminant.rs:14:5
|
||||
|
|
||||
LL | mem::discriminant(&&Some(2));
|
||||
| ^^^^^^^^^^^^^^^^^^---------^
|
||||
| |
|
||||
| help: try dereferencing: `&Some(2)`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/mem_discriminant.rs:3:9
|
||||
|
|
||||
LL | #![deny(clippy::mem_discriminant_non_enum)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&std::option::Option<u8>`
|
||||
--> $DIR/mem_discriminant.rs:16:5
|
||||
--> $DIR/mem_discriminant.rs:15:5
|
||||
|
|
||||
LL | mem::discriminant(&&None::<u8>);
|
||||
| ^^^^^^^^^^^^^^^^^^------------^
|
||||
|
@ -27,7 +21,7 @@ LL | mem::discriminant(&&None::<u8>);
|
|||
| help: try dereferencing: `&None::<u8>`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&Foo`
|
||||
--> $DIR/mem_discriminant.rs:17:5
|
||||
--> $DIR/mem_discriminant.rs:16:5
|
||||
|
|
||||
LL | mem::discriminant(&&Foo::One(5));
|
||||
| ^^^^^^^^^^^^^^^^^^-------------^
|
||||
|
@ -35,21 +29,15 @@ LL | mem::discriminant(&&Foo::One(5));
|
|||
| help: try dereferencing: `&Foo::One(5)`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&Foo`
|
||||
--> $DIR/mem_discriminant.rs:18:5
|
||||
--> $DIR/mem_discriminant.rs:17:5
|
||||
|
|
||||
LL | mem::discriminant(&&Foo::Two(5));
|
||||
| ^^^^^^^^^^^^^^^^^^-------------^
|
||||
| |
|
||||
| help: try dereferencing: `&Foo::Two(5)`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `A`
|
||||
--> $DIR/mem_discriminant.rs:19:5
|
||||
|
|
||||
LL | mem::discriminant(&A(Foo::One(0)));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:23:5
|
||||
--> $DIR/mem_discriminant.rs:21:5
|
||||
|
|
||||
LL | mem::discriminant(&ro);
|
||||
| ^^^^^^^^^^^^^^^^^^---^
|
||||
|
@ -57,7 +45,7 @@ LL | mem::discriminant(&ro);
|
|||
| help: try dereferencing: `ro`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:24:5
|
||||
--> $DIR/mem_discriminant.rs:22:5
|
||||
|
|
||||
LL | mem::discriminant(rro);
|
||||
| ^^^^^^^^^^^^^^^^^^---^
|
||||
|
@ -65,7 +53,7 @@ LL | mem::discriminant(rro);
|
|||
| help: try dereferencing: `*rro`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:25:5
|
||||
--> $DIR/mem_discriminant.rs:23:5
|
||||
|
|
||||
LL | mem::discriminant(&rro);
|
||||
| ^^^^^^^^^^^^^^^^^^----^
|
||||
|
@ -73,7 +61,7 @@ LL | mem::discriminant(&rro);
|
|||
| help: try dereferencing: `*rro`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:29:13
|
||||
--> $DIR/mem_discriminant.rs:27:13
|
||||
|
|
||||
LL | mem::discriminant($param)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -85,7 +73,7 @@ LL | mem_discriminant_but_in_a_macro!(&rro);
|
|||
| in this macro invocation
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&&&&&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:36:5
|
||||
--> $DIR/mem_discriminant.rs:34:5
|
||||
|
|
||||
LL | mem::discriminant(&rrrrro);
|
||||
| ^^^^^^^^^^^^^^^^^^-------^
|
||||
|
@ -93,12 +81,12 @@ LL | mem::discriminant(&rrrrro);
|
|||
| help: try dereferencing: `****rrrrro`
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `&&&std::option::Option<i32>`
|
||||
--> $DIR/mem_discriminant.rs:37:5
|
||||
--> $DIR/mem_discriminant.rs:35:5
|
||||
|
|
||||
LL | mem::discriminant(*rrrrro);
|
||||
| ^^^^^^^^^^^^^^^^^^-------^
|
||||
| |
|
||||
| help: try dereferencing: `****rrrrro`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
16
tests/ui/mem_discriminant_unfixable.rs
Normal file
16
tests/ui/mem_discriminant_unfixable.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
#![deny(clippy::mem_discriminant_non_enum)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
enum Foo {
|
||||
One(usize),
|
||||
Two(u8),
|
||||
}
|
||||
|
||||
struct A(Foo);
|
||||
|
||||
fn main() {
|
||||
// bad
|
||||
mem::discriminant(&"hello");
|
||||
mem::discriminant(&A(Foo::One(0)));
|
||||
}
|
20
tests/ui/mem_discriminant_unfixable.stderr
Normal file
20
tests/ui/mem_discriminant_unfixable.stderr
Normal file
|
@ -0,0 +1,20 @@
|
|||
error: calling `mem::discriminant` on non-enum type `&str`
|
||||
--> $DIR/mem_discriminant_unfixable.rs:14:5
|
||||
|
|
||||
LL | mem::discriminant(&"hello");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/mem_discriminant_unfixable.rs:1:9
|
||||
|
|
||||
LL | #![deny(clippy::mem_discriminant_non_enum)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: calling `mem::discriminant` on non-enum type `A`
|
||||
--> $DIR/mem_discriminant_unfixable.rs:15:5
|
||||
|
|
||||
LL | mem::discriminant(&A(Foo::One(0)));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in a new issue