Add test case for negative literals
This commit is contained in:
parent
e8f12d2f02
commit
02f01104bf
4 changed files with 20 additions and 2 deletions
|
|
@ -1601,7 +1601,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
|
|||
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(ex), cx.typeck_results().expr_ty(expr));
|
||||
lint_fn_to_numeric_cast(cx, expr, ex, cast_from, cast_to);
|
||||
if let Some(lit) = get_numeric_literal(ex) {
|
||||
let literal_str = snippet_opt(cx, lit.span).unwrap_or_default();
|
||||
let literal_str = snippet_opt(cx, ex.span).unwrap_or_default();
|
||||
|
||||
if_chain! {
|
||||
if let LitKind::Int(n, _) = lit.node;
|
||||
|
|
|
|||
|
|
@ -29,4 +29,7 @@ fn main() {
|
|||
0.5_f32;
|
||||
|
||||
1.0 as u16;
|
||||
|
||||
-1_i32;
|
||||
-1.0_f32;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,4 +29,7 @@ fn main() {
|
|||
0.5 as f32;
|
||||
|
||||
1.0 as u16;
|
||||
|
||||
-1 as i32;
|
||||
-1.0 as f32;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,5 +60,17 @@ error: casting float literal to `f32` is unnecessary
|
|||
LL | 0.5 as f32;
|
||||
| ^^^^^^^^^^ help: try: `0.5_f32`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: casting integer literal to `i32` is unnecessary
|
||||
--> $DIR/unnecessary_cast_fixable.rs:33:5
|
||||
|
|
||||
LL | -1 as i32;
|
||||
| ^^^^^^^^^ help: try: `-1_i32`
|
||||
|
||||
error: casting float literal to `f32` is unnecessary
|
||||
--> $DIR/unnecessary_cast_fixable.rs:34:5
|
||||
|
|
||||
LL | -1.0 as f32;
|
||||
| ^^^^^^^^^^^ help: try: `-1.0_f32`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue