Fix indentation of suggestion

This commit is contained in:
Manish Goregaokar 2021-01-21 14:00:25 -08:00
parent 8cb7e85006
commit 752274eabd
3 changed files with 7 additions and 6 deletions

View File

@ -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};
@ -82,13 +82,14 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
};
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 {

View File

@ -9,7 +9,7 @@ fn main() {
pub mod enums {
#[non_exhaustive]
pub enum Exhaustive {
pub enum Exhaustive {
Foo,
Bar,
Baz,
@ -45,7 +45,7 @@ pub enum Exhaustive {
pub mod structs {
#[non_exhaustive]
pub struct Exhaustive {
pub struct Exhaustive {
foo: u8,
bar: String,
}

View File

@ -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,
@ -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 | }