提交 752274ea 编写于 作者: M Manish Goregaokar

Fix indentation of suggestion

上级 8cb7e850
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 {
......
......@@ -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,
}
......
......@@ -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 | }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册