diff --git a/clippy_lints/src/unit_like_struct_brackets.rs b/clippy_lints/src/unit_like_struct_brackets.rs index cb6e2a44afb..7c93aa57d9b 100644 --- a/clippy_lints/src/unit_like_struct_brackets.rs +++ b/clippy_lints/src/unit_like_struct_brackets.rs @@ -1,4 +1,4 @@ -use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_opt}; +use clippy_utils::{diagnostics::span_lint_and_then, source::snippet_opt}; use rustc_ast::ast::{Item, ItemKind, VariantData}; use rustc_errors::Applicability; use rustc_lexer::TokenKind; @@ -33,14 +33,18 @@ 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) { - span_lint_and_sugg( + span_lint_and_then( cx, UNIT_LIKE_STRUCT_BRACKETS, span_after_ident, "found empty brackets on struct declaration", - "remove the brackets", - ";".to_string(), - Applicability::MachineApplicable + |diagnostic| { + diagnostic.span_suggestion_hidden( + span_after_ident, + "remove the brackets", + ";".to_string(), + Applicability::MachineApplicable); + }, ); } } diff --git a/tests/ui/unit_like_struct_brackets.stderr b/tests/ui/unit_like_struct_brackets.stderr index 7e7ba11cc71..d3037f5d350 100644 --- a/tests/ui/unit_like_struct_brackets.stderr +++ b/tests/ui/unit_like_struct_brackets.stderr @@ -2,15 +2,18 @@ error: found empty brackets on struct declaration --> $DIR/unit_like_struct_brackets.rs:5:25 | LL | pub struct MyEmptyStruct {} // should trigger lint - | ^^^ help: remove the brackets: `;` + | ^^^ | = note: `-D clippy::unit-like-struct-brackets` implied by `-D warnings` + = help: remove the brackets error: found empty brackets on struct declaration --> $DIR/unit_like_struct_brackets.rs:6:26 | LL | struct MyEmptyTupleStruct(); // should trigger lint - | ^^^ help: remove the brackets: `;` + | ^^^ + | + = help: remove the brackets error: aborting due to 2 previous errors