Skip to content

Commit e0ae980

Browse files
committed
Better suggestion span
1 parent 65d003a commit e0ae980

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

clippy_lints/src/exhaustive_items.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{indent_of, snippet_opt, span_lint_and_help, span_lint_and_then};
1+
use crate::utils::{indent_of, span_lint_and_then};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Item, ItemKind};
@@ -80,33 +80,22 @@ impl LateLintPass<'_> for ExhaustiveItems {
8080
} else {
8181
(EXHAUSTIVE_STRUCTS, "exported structs should not be exhaustive")
8282
};
83-
let suggestion_span = item.span.until(item.ident.span);
83+
let suggestion_span = item.span.shrink_to_lo();
84+
let indent = " ".repeat(indent_of(cx, item.span).unwrap_or(0));
85+
span_lint_and_then(
86+
cx,
87+
lint,
88+
item.span,
89+
msg,
90+
|diag| {
91+
let sugg = format!("#[non_exhaustive]\n{}", indent);
92+
diag.span_suggestion(suggestion_span,
93+
"try adding #[non_exhaustive]",
94+
sugg,
95+
Applicability::MaybeIncorrect);
96+
}
97+
);
8498

85-
if let Some(snippet) = snippet_opt(cx, suggestion_span) {
86-
let indent = " ".repeat(indent_of(cx, item.span).unwrap_or(0));
87-
span_lint_and_then(
88-
cx,
89-
lint,
90-
item.span,
91-
msg,
92-
|diag| {
93-
let sugg = format!("#[non_exhaustive]\n{}{}", indent, snippet);
94-
diag.span_suggestion(suggestion_span,
95-
"try adding #[non_exhaustive]",
96-
sugg,
97-
Applicability::MaybeIncorrect);
98-
}
99-
);
100-
} else {
101-
span_lint_and_help(
102-
cx,
103-
lint,
104-
item.span,
105-
msg,
106-
None,
107-
"try adding #[non_exhaustive]",
108-
);
109-
}
11099
}
111100
}
112101
}

0 commit comments

Comments
 (0)