Skip to content

Commit

Permalink
Add test for struct variant
Browse files Browse the repository at this point in the history
  • Loading branch information
long-long-float committed May 4, 2024
1 parent c1974c4 commit 4bd1a5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
15 changes: 11 additions & 4 deletions tests/ui/lint/dead-code/unused-variant.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#![deny(dead_code)]

#[derive(Clone)]
enum Enum1 {
enum Enum {
Variant1, //~ ERROR: variant `Variant1` is never constructed
Variant2,
}

#[derive(Debug)]
enum Enum2 {
enum TupleVariant {
Variant1(i32), //~ ERROR: variant `Variant1` is never constructed
Variant2,
}

#[derive(Debug)]
enum StructVariant {
Variant1 { id: i32 }, //~ ERROR: variant `Variant1` is never constructed
Variant2,
}

fn main() {
let e = Enum1::Variant2;
let e = Enum::Variant2;
e.clone();

let _ = Enum2::Variant2;
let _ = TupleVariant::Variant2;
let _ = StructVariant::Variant2;
}
24 changes: 17 additions & 7 deletions tests/ui/lint/dead-code/unused-variant.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: variant `Variant1` is never constructed
--> $DIR/unused-variant.rs:5:5
|
LL | enum Enum1 {
| ----- variant in this enum
LL | enum Enum {
| ---- variant in this enum
LL | Variant1,
| ^^^^^^^^
|
= note: `Enum1` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
= note: `Enum` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
note: the lint level is defined here
--> $DIR/unused-variant.rs:1:9
|
Expand All @@ -16,12 +16,22 @@ LL | #![deny(dead_code)]
error: variant `Variant1` is never constructed
--> $DIR/unused-variant.rs:11:5
|
LL | enum Enum2 {
| ----- variant in this enum
LL | enum TupleVariant {
| ------------ variant in this enum
LL | Variant1(i32),
| ^^^^^^^^
|
= note: `Enum2` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `TupleVariant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error: aborting due to 2 previous errors
error: variant `Variant1` is never constructed
--> $DIR/unused-variant.rs:17:5
|
LL | enum StructVariant {
| ------------- variant in this enum
LL | Variant1 { id: i32 },
| ^^^^^^^^
|
= note: `StructVariant` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis

error: aborting due to 3 previous errors

0 comments on commit 4bd1a5e

Please sign in to comment.