replace span_lint with span_lint_and_sugg along with error message

This commit is contained in:
iobtl 2021-03-13 16:54:59 +08:00
parent 65d046c9ad
commit 6d2236f503
2 changed files with 8 additions and 5 deletions

View File

@ -7,7 +7,7 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
use if_chain::if_chain;
use crate::utils::{numeric_literal::NumericLiteral, snippet_opt, span_lint, span_lint_and_sugg};
use crate::utils::{numeric_literal::NumericLiteral, snippet_opt, span_lint_and_sugg};
use super::UNNECESSARY_CAST;
@ -46,7 +46,7 @@ pub(super) fn check(
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
_ => {
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
span_lint(
span_lint_and_sugg(
cx,
UNNECESSARY_CAST,
expr.span,
@ -54,6 +54,9 @@ pub(super) fn check(
"casting to the same type is unnecessary (`{}` -> `{}`)",
cast_from, cast_to
),
"try",
literal_str,
Applicability::MachineApplicable,
);
return true;
}

View File

@ -2,7 +2,7 @@ error: casting to the same type is unnecessary (`i32` -> `i32`)
--> $DIR/unnecessary_cast.rs:6:5
|
LL | 1i32 as i32;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ help: try: `1i32`
|
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
@ -10,13 +10,13 @@ error: casting to the same type is unnecessary (`f32` -> `f32`)
--> $DIR/unnecessary_cast.rs:7:5
|
LL | 1f32 as f32;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ help: try: `1f32`
error: casting to the same type is unnecessary (`bool` -> `bool`)
--> $DIR/unnecessary_cast.rs:8:5
|
LL | false as bool;
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ help: try: `false`
error: aborting due to 3 previous errors