forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#12047 - ARandomDev99:12007-empty-enum-variant…
…s-with-brackets, r=Jarcho New Lint: empty_enum_variants_with_brackets This PR: - adds a new early pass lint that checks for enum variants with no fields that were defined using brackets. **Category: Restriction** - adds relevant UI tests for the new lint. Closes rust-lang#12007 ``` changelog: New lint: [`empty_enum_variants_with_brackets`] ```
- Loading branch information
Showing
7 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![warn(clippy::empty_enum_variants_with_brackets)] | ||
#![allow(dead_code)] | ||
|
||
pub enum PublicTestEnum { | ||
NonEmptyBraces { x: i32, y: i32 }, // No error | ||
NonEmptyParentheses(i32, i32), // No error | ||
EmptyBraces, //~ ERROR: enum variant has empty brackets | ||
EmptyParentheses, //~ ERROR: enum variant has empty brackets | ||
} | ||
|
||
enum TestEnum { | ||
NonEmptyBraces { x: i32, y: i32 }, // No error | ||
NonEmptyParentheses(i32, i32), // No error | ||
EmptyBraces, //~ ERROR: enum variant has empty brackets | ||
EmptyParentheses, //~ ERROR: enum variant has empty brackets | ||
AnotherEnum, // No error | ||
} | ||
|
||
enum TestEnumWithFeatures { | ||
NonEmptyBraces { | ||
#[cfg(feature = "thisisneverenabled")] | ||
x: i32, | ||
}, // No error | ||
NonEmptyParentheses(#[cfg(feature = "thisisneverenabled")] i32), // No error | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![warn(clippy::empty_enum_variants_with_brackets)] | ||
#![allow(dead_code)] | ||
|
||
pub enum PublicTestEnum { | ||
NonEmptyBraces { x: i32, y: i32 }, // No error | ||
NonEmptyParentheses(i32, i32), // No error | ||
EmptyBraces {}, //~ ERROR: enum variant has empty brackets | ||
EmptyParentheses(), //~ ERROR: enum variant has empty brackets | ||
} | ||
|
||
enum TestEnum { | ||
NonEmptyBraces { x: i32, y: i32 }, // No error | ||
NonEmptyParentheses(i32, i32), // No error | ||
EmptyBraces {}, //~ ERROR: enum variant has empty brackets | ||
EmptyParentheses(), //~ ERROR: enum variant has empty brackets | ||
AnotherEnum, // No error | ||
} | ||
|
||
enum TestEnumWithFeatures { | ||
NonEmptyBraces { | ||
#[cfg(feature = "thisisneverenabled")] | ||
x: i32, | ||
}, // No error | ||
NonEmptyParentheses(#[cfg(feature = "thisisneverenabled")] i32), // No error | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error: enum variant has empty brackets | ||
--> $DIR/empty_enum_variants_with_brackets.rs:7:16 | ||
| | ||
LL | EmptyBraces {}, | ||
| ^^^ | ||
| | ||
= note: `-D clippy::empty-enum-variants-with-brackets` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::empty_enum_variants_with_brackets)]` | ||
= help: remove the brackets | ||
|
||
error: enum variant has empty brackets | ||
--> $DIR/empty_enum_variants_with_brackets.rs:8:21 | ||
| | ||
LL | EmptyParentheses(), | ||
| ^^ | ||
| | ||
= help: remove the brackets | ||
|
||
error: enum variant has empty brackets | ||
--> $DIR/empty_enum_variants_with_brackets.rs:14:16 | ||
| | ||
LL | EmptyBraces {}, | ||
| ^^^ | ||
| | ||
= help: remove the brackets | ||
|
||
error: enum variant has empty brackets | ||
--> $DIR/empty_enum_variants_with_brackets.rs:15:21 | ||
| | ||
LL | EmptyParentheses(), | ||
| ^^ | ||
| | ||
= help: remove the brackets | ||
|
||
error: aborting due to 4 previous errors | ||
|