Skip to content

Commit 6d2236f

Browse files
committed
replace span_lint with span_lint_and_sugg along with error message
1 parent 65d046c commit 6d2236f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

clippy_lints/src/casts/unnecessary_cast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{self, FloatTy, InferTy, Ty};
77

88
use if_chain::if_chain;
99

10-
use crate::utils::{numeric_literal::NumericLiteral, snippet_opt, span_lint, span_lint_and_sugg};
10+
use crate::utils::{numeric_literal::NumericLiteral, snippet_opt, span_lint_and_sugg};
1111

1212
use super::UNNECESSARY_CAST;
1313

@@ -46,14 +46,17 @@ pub(super) fn check(
4646
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
4747
_ => {
4848
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
49-
span_lint(
49+
span_lint_and_sugg(
5050
cx,
5151
UNNECESSARY_CAST,
5252
expr.span,
5353
&format!(
5454
"casting to the same type is unnecessary (`{}` -> `{}`)",
5555
cast_from, cast_to
5656
),
57+
"try",
58+
literal_str,
59+
Applicability::MachineApplicable,
5760
);
5861
return true;
5962
}

tests/ui/unnecessary_cast.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ error: casting to the same type is unnecessary (`i32` -> `i32`)
22
--> $DIR/unnecessary_cast.rs:6:5
33
|
44
LL | 1i32 as i32;
5-
| ^^^^^^^^^^^
5+
| ^^^^^^^^^^^ help: try: `1i32`
66
|
77
= note: `-D clippy::unnecessary-cast` implied by `-D warnings`
88

99
error: casting to the same type is unnecessary (`f32` -> `f32`)
1010
--> $DIR/unnecessary_cast.rs:7:5
1111
|
1212
LL | 1f32 as f32;
13-
| ^^^^^^^^^^^
13+
| ^^^^^^^^^^^ help: try: `1f32`
1414

1515
error: casting to the same type is unnecessary (`bool` -> `bool`)
1616
--> $DIR/unnecessary_cast.rs:8:5
1717
|
1818
LL | false as bool;
19-
| ^^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^^ help: try: `false`
2020

2121
error: aborting due to 3 previous errors
2222

0 commit comments

Comments
 (0)