|
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}; |
2 | 2 | use if_chain::if_chain;
|
3 | 3 | use rustc_errors::Applicability;
|
4 | 4 | use rustc_hir::{Item, ItemKind};
|
@@ -80,33 +80,22 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
80 | 80 | } else {
|
81 | 81 | (EXHAUSTIVE_STRUCTS, "exported structs should not be exhaustive")
|
82 | 82 | };
|
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 | + ); |
84 | 98 |
|
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 |
| - } |
110 | 99 | }
|
111 | 100 | }
|
112 | 101 | }
|
|
0 commit comments