diff options
| author | Max Baumann <max@bmn.dev> | 2022-03-28 11:18:20 +0200 |
|---|---|---|
| committer | Max Baumann <max@bmn.dev> | 2022-03-30 20:12:58 +0200 |
| commit | 37d5a6264c3ad22f878351267fbbfe47e62cd35b (patch) | |
| tree | 13c45d4c214c0cf1e9ba84313446ef610b95d8e6 /clippy_lints/src | |
| parent | 33383a418d6e57995a35a08b6b3d74dc010b9189 (diff) | |
| download | rust-37d5a6264c3ad22f878351267fbbfe47e62cd35b.tar.gz rust-37d5a6264c3ad22f878351267fbbfe47e62cd35b.zip | |
changes after review
Diffstat (limited to 'clippy_lints/src')
| -rw-r--r-- | clippy_lints/src/unit_like_struct_brackets.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/clippy_lints/src/unit_like_struct_brackets.rs b/clippy_lints/src/unit_like_struct_brackets.rs index 7c93aa57d9b..6269719e696 100644 --- a/clippy_lints/src/unit_like_struct_brackets.rs +++ b/clippy_lints/src/unit_like_struct_brackets.rs @@ -21,7 +21,7 @@ declare_clippy_lint! { /// ```rust /// struct Cookie; /// ``` - #[clippy::version = "1.61.0"] + #[clippy::version = "1.62.0"] pub UNIT_LIKE_STRUCT_BRACKETS, style, "finds struct declarations with empty brackets" @@ -32,7 +32,9 @@ impl EarlyLintPass for UnitLikeStructBrackets { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { let span_after_ident = item.span.with_lo(item.ident.span.hi()); - if let ItemKind::Struct(var_data, _) = &item.kind && has_no_fields(cx, var_data, span_after_ident) { + if let ItemKind::Struct(var_data, _) = &item.kind + && !is_unit_like_struct(var_data) + && has_no_fields(cx, var_data, span_after_ident) { span_lint_and_then( cx, UNIT_LIKE_STRUCT_BRACKETS, @@ -50,23 +52,20 @@ impl EarlyLintPass for UnitLikeStructBrackets { } } -fn has_fields_in_hir(var_data: &VariantData) -> bool { - match var_data { - VariantData::Struct(defs, _) | VariantData::Tuple(defs, _) => !defs.is_empty(), - VariantData::Unit(_) => true, - } -} - fn has_no_ident_token(braces_span_str: &str) -> bool { !rustc_lexer::tokenize(braces_span_str).any(|t| t.kind == TokenKind::Ident) } +fn is_unit_like_struct(var_data: &VariantData) -> bool { + matches!(var_data, VariantData::Unit(_)) +} + fn has_no_fields(cx: &EarlyContext<'_>, var_data: &VariantData, braces_span: Span) -> bool { - if has_fields_in_hir(var_data) { + if !var_data.fields().is_empty() { return false; } - // there might still be field declarations hidden from HIR + // there might still be field declarations hidden from the AST // (conditionaly compiled code using #[cfg(..)]) let Some(braces_span_str) = snippet_opt(cx, braces_span) else { |
