@@ -21,7 +21,7 @@ declare_clippy_lint! {
2121 /// ```rust
2222 /// struct Cookie;
2323 /// ```
24- #[ clippy:: version = "1.61 .0" ]
24+ #[ clippy:: version = "1.62 .0" ]
2525 pub UNIT_LIKE_STRUCT_BRACKETS ,
2626 style,
2727 "finds struct declarations with empty brackets"
@@ -32,7 +32,9 @@ impl EarlyLintPass for UnitLikeStructBrackets {
3232 fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
3333 let span_after_ident = item. span . with_lo ( item. ident . span . hi ( ) ) ;
3434
35- if let ItemKind :: Struct ( var_data, _) = & item. kind && has_no_fields ( cx, var_data, span_after_ident) {
35+ if let ItemKind :: Struct ( var_data, _) = & item. kind
36+ && !is_unit_like_struct ( var_data)
37+ && has_no_fields ( cx, var_data, span_after_ident) {
3638 span_lint_and_then (
3739 cx,
3840 UNIT_LIKE_STRUCT_BRACKETS ,
@@ -50,23 +52,20 @@ impl EarlyLintPass for UnitLikeStructBrackets {
5052 }
5153}
5254
53- fn has_fields_in_hir ( var_data : & VariantData ) -> bool {
54- match var_data {
55- VariantData :: Struct ( defs, _) | VariantData :: Tuple ( defs, _) => !defs. is_empty ( ) ,
56- VariantData :: Unit ( _) => true ,
57- }
58- }
59-
6055fn has_no_ident_token ( braces_span_str : & str ) -> bool {
6156 !rustc_lexer:: tokenize ( braces_span_str) . any ( |t| t. kind == TokenKind :: Ident )
6257}
6358
59+ fn is_unit_like_struct ( var_data : & VariantData ) -> bool {
60+ matches ! ( var_data, VariantData :: Unit ( _) )
61+ }
62+
6463fn has_no_fields ( cx : & EarlyContext < ' _ > , var_data : & VariantData , braces_span : Span ) -> bool {
65- if has_fields_in_hir ( var_data) {
64+ if ! var_data. fields ( ) . is_empty ( ) {
6665 return false ;
6766 }
6867
69- // there might still be field declarations hidden from HIR
68+ // there might still be field declarations hidden from the AST
7069 // (conditionaly compiled code using #[cfg(..)])
7170
7271 let Some ( braces_span_str) = snippet_opt ( cx, braces_span) else {
0 commit comments