Skip to content

Commit

Permalink
use span_suggestion_hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed Mar 27, 2022
1 parent f82e5d5 commit 5b8fc45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions clippy_lints/src/unit_like_struct_brackets.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,14 +33,18 @@ impl EarlyLintPass for UnitLikeStructBrackets {
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);
},
);
}
}
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/unit_like_struct_brackets.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5b8fc45

Please sign in to comment.