Skip to content

Commit 5b8fc45

Browse files
committed
use span_suggestion_hidden
1 parent f82e5d5 commit 5b8fc45

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

clippy_lints/src/unit_like_struct_brackets.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::{diagnostics::span_lint_and_sugg, source::snippet_opt};
1+
use clippy_utils::{diagnostics::span_lint_and_then, source::snippet_opt};
22
use rustc_ast::ast::{Item, ItemKind, VariantData};
33
use rustc_errors::Applicability;
44
use rustc_lexer::TokenKind;
@@ -33,14 +33,18 @@ impl EarlyLintPass for UnitLikeStructBrackets {
3333
let span_after_ident = item.span.with_lo(item.ident.span.hi());
3434

3535
if let ItemKind::Struct(var_data, _) = &item.kind && has_no_fields(cx, var_data, span_after_ident) {
36-
span_lint_and_sugg(
36+
span_lint_and_then(
3737
cx,
3838
UNIT_LIKE_STRUCT_BRACKETS,
3939
span_after_ident,
4040
"found empty brackets on struct declaration",
41-
"remove the brackets",
42-
";".to_string(),
43-
Applicability::MachineApplicable
41+
|diagnostic| {
42+
diagnostic.span_suggestion_hidden(
43+
span_after_ident,
44+
"remove the brackets",
45+
";".to_string(),
46+
Applicability::MachineApplicable);
47+
},
4448
);
4549
}
4650
}

tests/ui/unit_like_struct_brackets.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error: found empty brackets on struct declaration
22
--> $DIR/unit_like_struct_brackets.rs:5:25
33
|
44
LL | pub struct MyEmptyStruct {} // should trigger lint
5-
| ^^^ help: remove the brackets: `;`
5+
| ^^^
66
|
77
= note: `-D clippy::unit-like-struct-brackets` implied by `-D warnings`
8+
= help: remove the brackets
89

910
error: found empty brackets on struct declaration
1011
--> $DIR/unit_like_struct_brackets.rs:6:26
1112
|
1213
LL | struct MyEmptyTupleStruct(); // should trigger lint
13-
| ^^^ help: remove the brackets: `;`
14+
| ^^^
15+
|
16+
= help: remove the brackets
1417

1518
error: aborting due to 2 previous errors
1619

0 commit comments

Comments
 (0)