Skip to content

Commit

Permalink
Fix indentation of suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 21, 2021
1 parent b263919 commit 1e7a67c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions clippy_lints/src/exhaustive_items.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{snippet_opt, span_lint_and_help, span_lint_and_sugg};
use crate::utils::{indent_of, snippet_opt, span_lint_and_help, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
Expand Down Expand Up @@ -82,13 +82,14 @@ impl LateLintPass<'_> for ExhaustiveItems {
};

if let Some(snippet) = snippet_opt(cx, item.span) {
let indent = " ".repeat(indent_of(cx, item.span).unwrap_or(0));
span_lint_and_sugg(
cx,
lint,
item.span,
"enums should not be exhaustive",
"try adding #[non_exhaustive]",
format!("#[non_exhaustive]\n{}", snippet),
format!("#[non_exhaustive]\n{}{}", indent, snippet),
Applicability::MaybeIncorrect,
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/exhaustive_items.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {

pub mod enums {
#[non_exhaustive]
pub enum Exhaustive {
pub enum Exhaustive {
Foo,
Bar,
Baz,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub enum Exhaustive {

pub mod structs {
#[non_exhaustive]
pub struct Exhaustive {
pub struct Exhaustive {
foo: u8,
bar: String,
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/exhaustive_items.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | #![deny(clippy::exhaustive_enums, clippy::exhaustive_structs)]
help: try adding #[non_exhaustive]
|
LL | #[non_exhaustive]
LL | pub enum Exhaustive {
LL | pub enum Exhaustive {
LL | Foo,
LL | Bar,
LL | Baz,
Expand All @@ -36,7 +36,7 @@ LL | | }
help: try adding #[non_exhaustive]
|
LL | #[non_exhaustive]
LL | pub struct Exhaustive {
LL | pub struct Exhaustive {
LL | foo: u8,
LL | bar: String,
LL | }
Expand Down

0 comments on commit 1e7a67c

Please sign in to comment.