Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 752274e

Browse files
committed
Fix indentation of suggestion
1 parent 8cb7e85 commit 752274e

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

clippy_lints/src/exhaustive_items.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{snippet_opt, span_lint_and_help, span_lint_and_sugg};
1+
use crate::utils::{indent_of, snippet_opt, span_lint_and_help, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::{Item, ItemKind};
@@ -82,13 +82,14 @@ impl LateLintPass<'_> for ExhaustiveItems {
8282
};
8383

8484
if let Some(snippet) = snippet_opt(cx, item.span) {
85+
let indent = " ".repeat(indent_of(cx, item.span).unwrap_or(0));
8586
span_lint_and_sugg(
8687
cx,
8788
lint,
8889
item.span,
8990
"enums should not be exhaustive",
9091
"try adding #[non_exhaustive]",
91-
format!("#[non_exhaustive]\n{}", snippet),
92+
format!("#[non_exhaustive]\n{}{}", indent, snippet),
9293
Applicability::MaybeIncorrect,
9394
);
9495
} else {

tests/ui/exhaustive_items.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99

1010
pub mod enums {
1111
#[non_exhaustive]
12-
pub enum Exhaustive {
12+
pub enum Exhaustive {
1313
Foo,
1414
Bar,
1515
Baz,
@@ -45,7 +45,7 @@ pub enum Exhaustive {
4545

4646
pub mod structs {
4747
#[non_exhaustive]
48-
pub struct Exhaustive {
48+
pub struct Exhaustive {
4949
foo: u8,
5050
bar: String,
5151
}

tests/ui/exhaustive_items.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
1717
help: try adding #[non_exhaustive]
1818
|
1919
LL | #[non_exhaustive]
20-
LL | pub enum Exhaustive {
20+
LL | pub enum Exhaustive {
2121
LL | Foo,
2222
LL | Bar,
2323
LL | Baz,
@@ -36,7 +36,7 @@ LL | | }
3636
help: try adding #[non_exhaustive]
3737
|
3838
LL | #[non_exhaustive]
39-
LL | pub struct Exhaustive {
39+
LL | pub struct Exhaustive {
4040
LL | foo: u8,
4141
LL | bar: String,
4242
LL | }

0 commit comments

Comments
 (0)