From 3bc5abef6219f15929ffb6ff8ddedd998f013c63 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Thu, 8 Jul 2021 11:37:12 +0900 Subject: [PATCH 1/4] default_numeric_fallback: Fix FP with floating literal --- clippy_lints/src/default_numeric_fallback.rs | 6 ++-- tests/ui/default_numeric_fallback.rs | 37 ++++++++++++++++++-- tests/ui/default_numeric_fallback.stderr | 32 +++++++++++++---- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index a125376bffa..ea28644b9a4 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -78,7 +78,7 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { if let Some(ty_bound) = self.ty_bounds.last(); if matches!(lit.node, LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed)); - if !ty_bound.is_integral(); + if !ty_bound.is_numeric(); then { let suffix = match lit_ty.kind() { ty::Int(IntTy::I32) => "i32", @@ -219,10 +219,10 @@ enum TyBound<'tcx> { } impl<'tcx> TyBound<'tcx> { - fn is_integral(self) -> bool { + fn is_numeric(self) -> bool { match self { TyBound::Any => true, - TyBound::Ty(t) => t.is_integral(), + TyBound::Ty(t) => t.is_numeric(), TyBound::Nothing => false, } } diff --git a/tests/ui/default_numeric_fallback.rs b/tests/ui/default_numeric_fallback.rs index c0625fd1b75..58a7f377374 100644 --- a/tests/ui/default_numeric_fallback.rs +++ b/tests/ui/default_numeric_fallback.rs @@ -81,17 +81,25 @@ mod function_def { } mod function_calls { - fn concrete_arg(x: i32) {} + fn concrete_arg_i32(x: i32) {} + + fn concrete_arg_f64(f: f64) {} fn generic_arg(t: T) {} fn test() { // Should NOT lint this because the argument type is bound to a concrete type. - concrete_arg(1); + concrete_arg_i32(1); + + // Should NOT lint this because the argument type is bound to a concrete type. + concrete_arg_f64(1.); // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. generic_arg(1); + // Should lint this because the argument type is inferred to `f32` and NOT bound to a concrete type. + generic_arg(1.0); + // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. let x: _ = generic_arg(1); } @@ -118,6 +126,31 @@ mod struct_ctor { } } +mod enum_ctor { + enum ConcreteEnum { + X(i32), + Y(f64), + } + + enum GenericEnum { + X(T), + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteEnum::X(1); + + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteEnum::Y(1.); + + // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. + GenericEnum::X(1); + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + GenericEnum::X(1.); + } +} + mod method_calls { struct StructForMethodCallTest {} diff --git a/tests/ui/default_numeric_fallback.stderr b/tests/ui/default_numeric_fallback.stderr index 5862cd936ac..3965385189e 100644 --- a/tests/ui/default_numeric_fallback.stderr +++ b/tests/ui/default_numeric_fallback.stderr @@ -115,37 +115,55 @@ LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:93:21 + --> $DIR/default_numeric_fallback.rs:98:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:96:32 + --> $DIR/default_numeric_fallback.rs:101:21 + | +LL | generic_arg(1.0); + | ^^^ help: consider adding suffix: `1.0_f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback.rs:104:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:114:28 + --> $DIR/default_numeric_fallback.rs:122:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:117:36 + --> $DIR/default_numeric_fallback.rs:125:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:137:23 + --> $DIR/default_numeric_fallback.rs:147:24 + | +LL | GenericEnum::X(1); + | ^ help: consider adding suffix: `1_i32` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback.rs:150:24 + | +LL | GenericEnum::X(1.); + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback.rs:170:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:144:21 + --> $DIR/default_numeric_fallback.rs:177:21 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -155,5 +173,5 @@ LL | internal_macro!(); | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 25 previous errors +error: aborting due to 28 previous errors From 04aa3f7e9b81748c239440b7f78d94971b6bf95e Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Fri, 9 Jul 2021 14:51:16 +0900 Subject: [PATCH 2/4] `default_numeric_fallback`: Add more tests for floating literal --- tests/ui/default_numeric_fallback_f64.rs | 174 ++++++++++++++++++ tests/ui/default_numeric_fallback_f64.stderr | 147 +++++++++++++++ ...ack.rs => default_numeric_fallback_i32.rs} | 24 +-- ...rr => default_numeric_fallback_i32.stderr} | 70 +++---- 4 files changed, 349 insertions(+), 66 deletions(-) create mode 100644 tests/ui/default_numeric_fallback_f64.rs create mode 100644 tests/ui/default_numeric_fallback_f64.stderr rename tests/ui/{default_numeric_fallback.rs => default_numeric_fallback_i32.rs} (85%) rename tests/ui/{default_numeric_fallback.stderr => default_numeric_fallback_i32.stderr} (70%) diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs new file mode 100644 index 00000000000..fff6f95950d --- /dev/null +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -0,0 +1,174 @@ +// aux-build:macro_rules.rs + +#![warn(clippy::default_numeric_fallback)] +#![allow(unused)] +#![allow(clippy::never_loop)] +#![allow(clippy::no_effect)] +#![allow(clippy::unnecessary_operation)] +#![allow(clippy::branches_sharing_code)] +#![allow(clippy::branches_sharing_code)] +#![allow(clippy::match_single_binding)] + +#[macro_use] +extern crate macro_rules; + +mod basic_expr { + fn test() { + // Should lint unsuffixed literals typed `f64`. + let x = 0.12; + let x = [1., 2., 3.]; + let x = if true { (1., 2.) } else { (3., 4.) }; + let x = match 1. { + _ => 1., + }; + + // Should NOT lint suffixed literals. + let x = 0.12_f64; + + // Should NOT lint literals in init expr if `Local` has a type annotation. + let x: f64 = 0.1; + let x: [f64; 3] = [1., 2., 3.]; + let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) }; + let x: _ = 1.; + } +} + +mod nested_local { + fn test() { + let x: _ = { + // Should lint this because this literal is not bound to any types. + let y = 1.; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1. + }; + + let x: _ = if true { + // Should lint this because this literal is not bound to any types. + let y = 1.; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1. + } else { + // Should lint this because this literal is not bound to any types. + let y = 1.; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 2. + }; + } +} + +mod function_def { + fn ret_f64() -> f64 { + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + 1. + } + + fn test() { + // Should lint this because return type is inferred to `f64` and NOT bound to a concrete + // type. + let f = || -> _ { 1. }; + + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + let f = || -> f64 { 1. }; + } +} + +mod function_calls { + fn concrete_arg(f: f64) {} + + fn generic_arg(t: T) {} + + fn test() { + // Should NOT lint this because the argument type is bound to a concrete type. + concrete_arg(1.); + + // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. + generic_arg(1.); + + // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. + let x: _ = generic_arg(1.); + } +} + +mod struct_ctor { + struct ConcreteStruct { + x: f64, + } + + struct GenericStruct { + x: T, + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteStruct { x: 1. }; + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + GenericStruct { x: 1. }; + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + let _ = GenericStruct { x: 1. }; + } +} + +mod enum_ctor { + enum ConcreteEnum { + X(f64), + } + + enum GenericEnum { + X(T), + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteEnum::X(1.); + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + GenericEnum::X(1.); + } +} + +mod method_calls { + struct StructForMethodCallTest {} + + impl StructForMethodCallTest { + fn concrete_arg(&self, f: f64) {} + + fn generic_arg(&self, t: T) {} + } + + fn test() { + let s = StructForMethodCallTest {}; + + // Should NOT lint this because the argument type is bound to a concrete type. + s.concrete_arg(1.); + + // Should lint this because the argument type is bound to a concrete type. + s.generic_arg(1.); + } +} + +mod in_macro { + macro_rules! internal_macro { + () => { + let x = 22.; + }; + } + + // Should lint in internal macro. + fn internal() { + internal_macro!(); + } + + // Should NOT lint in external macro. + fn external() { + default_numeric_fallback!(); + } +} + +fn main() {} diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr new file mode 100644 index 00000000000..aed44843d89 --- /dev/null +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -0,0 +1,147 @@ +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:18:17 + | +LL | let x = 0.12; + | ^^^^ help: consider adding suffix: `0.12_f64` + | + = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:19:18 + | +LL | let x = [1., 2., 3.]; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:19:22 + | +LL | let x = [1., 2., 3.]; + | ^^ help: consider adding suffix: `2._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:19:26 + | +LL | let x = [1., 2., 3.]; + | ^^ help: consider adding suffix: `3._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:20:28 + | +LL | let x = if true { (1., 2.) } else { (3., 4.) }; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:20:32 + | +LL | let x = if true { (1., 2.) } else { (3., 4.) }; + | ^^ help: consider adding suffix: `2._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:20:46 + | +LL | let x = if true { (1., 2.) } else { (3., 4.) }; + | ^^ help: consider adding suffix: `3._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:20:50 + | +LL | let x = if true { (1., 2.) } else { (3., 4.) }; + | ^^ help: consider adding suffix: `4._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:21:23 + | +LL | let x = match 1. { + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:22:18 + | +LL | _ => 1., + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:40:21 + | +LL | let y = 1.; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:48:21 + | +LL | let y = 1.; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:54:21 + | +LL | let y = 1.; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:66:9 + | +LL | 1. + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:72:27 + | +LL | let f = || -> _ { 1. }; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:76:29 + | +LL | let f = || -> f64 { 1. }; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:90:21 + | +LL | generic_arg(1.); + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:93:32 + | +LL | let x: _ = generic_arg(1.); + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:111:28 + | +LL | GenericStruct { x: 1. }; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:114:36 + | +LL | let _ = GenericStruct { x: 1. }; + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:132:24 + | +LL | GenericEnum::X(1.); + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:152:23 + | +LL | s.generic_arg(1.); + | ^^ help: consider adding suffix: `1._f64` + +error: default numeric fallback might occur + --> $DIR/default_numeric_fallback_f64.rs:159:21 + | +LL | let x = 22.; + | ^^^ help: consider adding suffix: `22._f64` +... +LL | internal_macro!(); + | ------------------ in this macro invocation + | + = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 23 previous errors + diff --git a/tests/ui/default_numeric_fallback.rs b/tests/ui/default_numeric_fallback_i32.rs similarity index 85% rename from tests/ui/default_numeric_fallback.rs rename to tests/ui/default_numeric_fallback_i32.rs index 58a7f377374..e84c70c344c 100644 --- a/tests/ui/default_numeric_fallback.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -21,15 +21,10 @@ mod basic_expr { _ => 2, }; - // Should lint unsuffixed literals typed `f64`. - let x = 0.12; - // Should NOT lint suffixed literals. let x = 22_i32; - let x = 0.12_f64; // Should NOT lint literals in init expr if `Local` has a type annotation. - let x: f64 = 0.1; let x: [i32; 3] = [1, 2, 3]; let x: (i32, i32) = if true { (1, 2) } else { (3, 4) }; let x: _ = 1; @@ -81,25 +76,17 @@ mod function_def { } mod function_calls { - fn concrete_arg_i32(x: i32) {} - - fn concrete_arg_f64(f: f64) {} + fn concrete_arg(x: i32) {} fn generic_arg(t: T) {} fn test() { // Should NOT lint this because the argument type is bound to a concrete type. - concrete_arg_i32(1); - - // Should NOT lint this because the argument type is bound to a concrete type. - concrete_arg_f64(1.); + concrete_arg(1); // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. generic_arg(1); - // Should lint this because the argument type is inferred to `f32` and NOT bound to a concrete type. - generic_arg(1.0); - // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. let x: _ = generic_arg(1); } @@ -129,7 +116,6 @@ mod struct_ctor { mod enum_ctor { enum ConcreteEnum { X(i32), - Y(f64), } enum GenericEnum { @@ -140,14 +126,8 @@ mod enum_ctor { // Should NOT lint this because the field type is bound to a concrete type. ConcreteEnum::X(1); - // Should NOT lint this because the field type is bound to a concrete type. - ConcreteEnum::Y(1.); - // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. GenericEnum::X(1); - - // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. - GenericEnum::X(1.); } } diff --git a/tests/ui/default_numeric_fallback.stderr b/tests/ui/default_numeric_fallback_i32.stderr similarity index 70% rename from tests/ui/default_numeric_fallback.stderr rename to tests/ui/default_numeric_fallback_i32.stderr index 3965385189e..9b8f232366d 100644 --- a/tests/ui/default_numeric_fallback.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -1,5 +1,5 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:16:17 + --> $DIR/default_numeric_fallback_i32.rs:16:17 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -7,163 +7,145 @@ LL | let x = 22; = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:17:18 + --> $DIR/default_numeric_fallback_i32.rs:17:18 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:17:21 + --> $DIR/default_numeric_fallback_i32.rs:17:21 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:17:24 + --> $DIR/default_numeric_fallback_i32.rs:17:24 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:18:28 + --> $DIR/default_numeric_fallback_i32.rs:18:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:18:31 + --> $DIR/default_numeric_fallback_i32.rs:18:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:18:44 + --> $DIR/default_numeric_fallback_i32.rs:18:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:18:47 + --> $DIR/default_numeric_fallback_i32.rs:18:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:19:23 + --> $DIR/default_numeric_fallback_i32.rs:19:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:20:13 + --> $DIR/default_numeric_fallback_i32.rs:20:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:20:18 + --> $DIR/default_numeric_fallback_i32.rs:20:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:21:18 + --> $DIR/default_numeric_fallback_i32.rs:21:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:25:17 - | -LL | let x = 0.12; - | ^^^^ help: consider adding suffix: `0.12_f64` - -error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:43:21 + --> $DIR/default_numeric_fallback_i32.rs:38:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:51:21 + --> $DIR/default_numeric_fallback_i32.rs:46:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:57:21 + --> $DIR/default_numeric_fallback_i32.rs:52:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:69:9 + --> $DIR/default_numeric_fallback_i32.rs:64:9 | LL | 1 | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:75:27 + --> $DIR/default_numeric_fallback_i32.rs:70:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:79:29 + --> $DIR/default_numeric_fallback_i32.rs:74:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:98:21 + --> $DIR/default_numeric_fallback_i32.rs:88:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:101:21 - | -LL | generic_arg(1.0); - | ^^^ help: consider adding suffix: `1.0_f64` - -error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:104:32 + --> $DIR/default_numeric_fallback_i32.rs:91:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:122:28 + --> $DIR/default_numeric_fallback_i32.rs:109:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:125:36 + --> $DIR/default_numeric_fallback_i32.rs:112:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:147:24 + --> $DIR/default_numeric_fallback_i32.rs:130:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:150:24 - | -LL | GenericEnum::X(1.); - | ^^ help: consider adding suffix: `1._f64` - -error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:170:23 + --> $DIR/default_numeric_fallback_i32.rs:150:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback.rs:177:21 + --> $DIR/default_numeric_fallback_i32.rs:157:21 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -173,5 +155,5 @@ LL | internal_macro!(); | = note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 28 previous errors +error: aborting due to 25 previous errors From 4e8cd4d346c13b0ef873f69c213ba96dc5bab5bf Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Tue, 13 Jul 2021 22:56:41 +0900 Subject: [PATCH 3/4] Fix `NumericLiteral::format` that may produce a invalid literal --- clippy_utils/src/numeric_literal.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clippy_utils/src/numeric_literal.rs b/clippy_utils/src/numeric_literal.rs index 546706d51d7..4a28c7dd9a0 100644 --- a/clippy_utils/src/numeric_literal.rs +++ b/clippy_utils/src/numeric_literal.rs @@ -162,6 +162,9 @@ impl<'a> NumericLiteral<'a> { } if let Some(suffix) = self.suffix { + if output.ends_with('.') { + output.push('0'); + } output.push('_'); output.push_str(suffix); } From 25e4c7d73fd4c929208edf151c827f6c97318374 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Tue, 13 Jul 2021 22:57:47 +0900 Subject: [PATCH 4/4] `default_numeric_fallback`: Add rustfix tests --- clippy_lints/src/default_numeric_fallback.rs | 20 ++- tests/ui/default_numeric_fallback_f64.fixed | 174 +++++++++++++++++++ tests/ui/default_numeric_fallback_f64.rs | 2 +- tests/ui/default_numeric_fallback_f64.stderr | 44 ++--- tests/ui/default_numeric_fallback_i32.fixed | 173 ++++++++++++++++++ tests/ui/default_numeric_fallback_i32.rs | 1 + tests/ui/default_numeric_fallback_i32.stderr | 50 +++--- 7 files changed, 411 insertions(+), 53 deletions(-) create mode 100644 tests/ui/default_numeric_fallback_f64.fixed create mode 100644 tests/ui/default_numeric_fallback_i32.fixed diff --git a/clippy_lints/src/default_numeric_fallback.rs b/clippy_lints/src/default_numeric_fallback.rs index ea28644b9a4..e719a1b0abf 100644 --- a/clippy_lints/src/default_numeric_fallback.rs +++ b/clippy_lints/src/default_numeric_fallback.rs @@ -1,5 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::source::snippet; +use clippy_utils::numeric_literal; +use clippy_utils::source::snippet_opt; use if_chain::if_chain; use rustc_ast::ast::{LitFloatType, LitIntType, LitKind}; use rustc_errors::Applicability; @@ -80,14 +81,23 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> { LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed)); if !ty_bound.is_numeric(); then { - let suffix = match lit_ty.kind() { - ty::Int(IntTy::I32) => "i32", - ty::Float(FloatTy::F64) => "f64", + let (suffix, is_float) = match lit_ty.kind() { + ty::Int(IntTy::I32) => ("i32", false), + ty::Float(FloatTy::F64) => ("f64", true), // Default numeric fallback never results in other types. _ => return, }; - let sugg = format!("{}_{}", snippet(self.cx, lit.span, ""), suffix); + let src = if let Some(src) = snippet_opt(self.cx, lit.span) { + src + } else { + match lit.node { + LitKind::Int(src, _) => format!("{}", src), + LitKind::Float(src, _) => format!("{}", src), + _ => return, + } + }; + let sugg = numeric_literal::format(&src, Some(suffix), is_float); span_lint_and_sugg( self.cx, DEFAULT_NUMERIC_FALLBACK, diff --git a/tests/ui/default_numeric_fallback_f64.fixed b/tests/ui/default_numeric_fallback_f64.fixed new file mode 100644 index 00000000000..1b0e7544e79 --- /dev/null +++ b/tests/ui/default_numeric_fallback_f64.fixed @@ -0,0 +1,174 @@ +// run-rustfix +// aux-build:macro_rules.rs + +#![warn(clippy::default_numeric_fallback)] +#![allow(unused)] +#![allow(clippy::never_loop)] +#![allow(clippy::no_effect)] +#![allow(clippy::unnecessary_operation)] +#![allow(clippy::branches_sharing_code)] +#![allow(clippy::match_single_binding)] + +#[macro_use] +extern crate macro_rules; + +mod basic_expr { + fn test() { + // Should lint unsuffixed literals typed `f64`. + let x = 0.12_f64; + let x = [1.0_f64, 2.0_f64, 3.0_f64]; + let x = if true { (1.0_f64, 2.0_f64) } else { (3.0_f64, 4.0_f64) }; + let x = match 1.0_f64 { + _ => 1.0_f64, + }; + + // Should NOT lint suffixed literals. + let x = 0.12_f64; + + // Should NOT lint literals in init expr if `Local` has a type annotation. + let x: f64 = 0.1; + let x: [f64; 3] = [1., 2., 3.]; + let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) }; + let x: _ = 1.; + } +} + +mod nested_local { + fn test() { + let x: _ = { + // Should lint this because this literal is not bound to any types. + let y = 1.0_f64; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1. + }; + + let x: _ = if true { + // Should lint this because this literal is not bound to any types. + let y = 1.0_f64; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1. + } else { + // Should lint this because this literal is not bound to any types. + let y = 1.0_f64; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 2. + }; + } +} + +mod function_def { + fn ret_f64() -> f64 { + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + 1.0_f64 + } + + fn test() { + // Should lint this because return type is inferred to `f64` and NOT bound to a concrete + // type. + let f = || -> _ { 1.0_f64 }; + + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + let f = || -> f64 { 1.0_f64 }; + } +} + +mod function_calls { + fn concrete_arg(f: f64) {} + + fn generic_arg(t: T) {} + + fn test() { + // Should NOT lint this because the argument type is bound to a concrete type. + concrete_arg(1.); + + // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. + generic_arg(1.0_f64); + + // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type. + let x: _ = generic_arg(1.0_f64); + } +} + +mod struct_ctor { + struct ConcreteStruct { + x: f64, + } + + struct GenericStruct { + x: T, + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteStruct { x: 1. }; + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + GenericStruct { x: 1.0_f64 }; + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + let _ = GenericStruct { x: 1.0_f64 }; + } +} + +mod enum_ctor { + enum ConcreteEnum { + X(f64), + } + + enum GenericEnum { + X(T), + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteEnum::X(1.); + + // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type. + GenericEnum::X(1.0_f64); + } +} + +mod method_calls { + struct StructForMethodCallTest {} + + impl StructForMethodCallTest { + fn concrete_arg(&self, f: f64) {} + + fn generic_arg(&self, t: T) {} + } + + fn test() { + let s = StructForMethodCallTest {}; + + // Should NOT lint this because the argument type is bound to a concrete type. + s.concrete_arg(1.); + + // Should lint this because the argument type is bound to a concrete type. + s.generic_arg(1.0_f64); + } +} + +mod in_macro { + macro_rules! internal_macro { + () => { + let x = 22.0_f64; + }; + } + + // Should lint in internal macro. + fn internal() { + internal_macro!(); + } + + // Should NOT lint in external macro. + fn external() { + default_numeric_fallback!(); + } +} + +fn main() {} diff --git a/tests/ui/default_numeric_fallback_f64.rs b/tests/ui/default_numeric_fallback_f64.rs index fff6f95950d..e9687777bbd 100644 --- a/tests/ui/default_numeric_fallback_f64.rs +++ b/tests/ui/default_numeric_fallback_f64.rs @@ -1,3 +1,4 @@ +// run-rustfix // aux-build:macro_rules.rs #![warn(clippy::default_numeric_fallback)] @@ -6,7 +7,6 @@ #![allow(clippy::no_effect)] #![allow(clippy::unnecessary_operation)] #![allow(clippy::branches_sharing_code)] -#![allow(clippy::branches_sharing_code)] #![allow(clippy::match_single_binding)] #[macro_use] diff --git a/tests/ui/default_numeric_fallback_f64.stderr b/tests/ui/default_numeric_fallback_f64.stderr index aed44843d89..961c7cb57c5 100644 --- a/tests/ui/default_numeric_fallback_f64.stderr +++ b/tests/ui/default_numeric_fallback_f64.stderr @@ -10,133 +10,133 @@ error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:19:18 | LL | let x = [1., 2., 3.]; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:19:22 | LL | let x = [1., 2., 3.]; - | ^^ help: consider adding suffix: `2._f64` + | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:19:26 | LL | let x = [1., 2., 3.]; - | ^^ help: consider adding suffix: `3._f64` + | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:20:28 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:20:32 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; - | ^^ help: consider adding suffix: `2._f64` + | ^^ help: consider adding suffix: `2.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:20:46 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; - | ^^ help: consider adding suffix: `3._f64` + | ^^ help: consider adding suffix: `3.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:20:50 | LL | let x = if true { (1., 2.) } else { (3., 4.) }; - | ^^ help: consider adding suffix: `4._f64` + | ^^ help: consider adding suffix: `4.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:21:23 | LL | let x = match 1. { - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:22:18 | LL | _ => 1., - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:40:21 | LL | let y = 1.; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:48:21 | LL | let y = 1.; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:54:21 | LL | let y = 1.; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:66:9 | LL | 1. - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:72:27 | LL | let f = || -> _ { 1. }; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:76:29 | LL | let f = || -> f64 { 1. }; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:90:21 | LL | generic_arg(1.); - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:93:32 | LL | let x: _ = generic_arg(1.); - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:111:28 | LL | GenericStruct { x: 1. }; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:114:36 | LL | let _ = GenericStruct { x: 1. }; - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:132:24 | LL | GenericEnum::X(1.); - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:152:23 | LL | s.generic_arg(1.); - | ^^ help: consider adding suffix: `1._f64` + | ^^ help: consider adding suffix: `1.0_f64` error: default numeric fallback might occur --> $DIR/default_numeric_fallback_f64.rs:159:21 | LL | let x = 22.; - | ^^^ help: consider adding suffix: `22._f64` + | ^^^ help: consider adding suffix: `22.0_f64` ... LL | internal_macro!(); | ------------------ in this macro invocation diff --git a/tests/ui/default_numeric_fallback_i32.fixed b/tests/ui/default_numeric_fallback_i32.fixed new file mode 100644 index 00000000000..55c082fcb19 --- /dev/null +++ b/tests/ui/default_numeric_fallback_i32.fixed @@ -0,0 +1,173 @@ +// run-rustfix +// aux-build:macro_rules.rs + +#![warn(clippy::default_numeric_fallback)] +#![allow(unused)] +#![allow(clippy::never_loop)] +#![allow(clippy::no_effect)] +#![allow(clippy::unnecessary_operation)] +#![allow(clippy::branches_sharing_code)] + +#[macro_use] +extern crate macro_rules; + +mod basic_expr { + fn test() { + // Should lint unsuffixed literals typed `i32`. + let x = 22_i32; + let x = [1_i32, 2_i32, 3_i32]; + let x = if true { (1_i32, 2_i32) } else { (3_i32, 4_i32) }; + let x = match 1_i32 { + 1_i32 => 1_i32, + _ => 2_i32, + }; + + // Should NOT lint suffixed literals. + let x = 22_i32; + + // Should NOT lint literals in init expr if `Local` has a type annotation. + let x: [i32; 3] = [1, 2, 3]; + let x: (i32, i32) = if true { (1, 2) } else { (3, 4) }; + let x: _ = 1; + } +} + +mod nested_local { + fn test() { + let x: _ = { + // Should lint this because this literal is not bound to any types. + let y = 1_i32; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1 + }; + + let x: _ = if true { + // Should lint this because this literal is not bound to any types. + let y = 1_i32; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 1 + } else { + // Should lint this because this literal is not bound to any types. + let y = 1_i32; + + // Should NOT lint this because this literal is bound to `_` of outer `Local`. + 2 + }; + } +} + +mod function_def { + fn ret_i32() -> i32 { + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + 1_i32 + } + + fn test() { + // Should lint this because return type is inferred to `i32` and NOT bound to a concrete + // type. + let f = || -> _ { 1_i32 }; + + // Even though the output type is specified, + // this unsuffixed literal is linted to reduce heuristics and keep codebase simple. + let f = || -> i32 { 1_i32 }; + } +} + +mod function_calls { + fn concrete_arg(x: i32) {} + + fn generic_arg(t: T) {} + + fn test() { + // Should NOT lint this because the argument type is bound to a concrete type. + concrete_arg(1); + + // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. + generic_arg(1_i32); + + // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type. + let x: _ = generic_arg(1_i32); + } +} + +mod struct_ctor { + struct ConcreteStruct { + x: i32, + } + + struct GenericStruct { + x: T, + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteStruct { x: 1 }; + + // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. + GenericStruct { x: 1_i32 }; + + // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. + let _ = GenericStruct { x: 1_i32 }; + } +} + +mod enum_ctor { + enum ConcreteEnum { + X(i32), + } + + enum GenericEnum { + X(T), + } + + fn test() { + // Should NOT lint this because the field type is bound to a concrete type. + ConcreteEnum::X(1); + + // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type. + GenericEnum::X(1_i32); + } +} + +mod method_calls { + struct StructForMethodCallTest {} + + impl StructForMethodCallTest { + fn concrete_arg(&self, x: i32) {} + + fn generic_arg(&self, t: T) {} + } + + fn test() { + let s = StructForMethodCallTest {}; + + // Should NOT lint this because the argument type is bound to a concrete type. + s.concrete_arg(1); + + // Should lint this because the argument type is bound to a concrete type. + s.generic_arg(1_i32); + } +} + +mod in_macro { + macro_rules! internal_macro { + () => { + let x = 22_i32; + }; + } + + // Should lint in internal macro. + fn internal() { + internal_macro!(); + } + + // Should NOT lint in external macro. + fn external() { + default_numeric_fallback!(); + } +} + +fn main() {} diff --git a/tests/ui/default_numeric_fallback_i32.rs b/tests/ui/default_numeric_fallback_i32.rs index e84c70c344c..e0a4828ce9f 100644 --- a/tests/ui/default_numeric_fallback_i32.rs +++ b/tests/ui/default_numeric_fallback_i32.rs @@ -1,3 +1,4 @@ +// run-rustfix // aux-build:macro_rules.rs #![warn(clippy::default_numeric_fallback)] diff --git a/tests/ui/default_numeric_fallback_i32.stderr b/tests/ui/default_numeric_fallback_i32.stderr index 9b8f232366d..5edf48b2020 100644 --- a/tests/ui/default_numeric_fallback_i32.stderr +++ b/tests/ui/default_numeric_fallback_i32.stderr @@ -1,5 +1,5 @@ error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:16:17 + --> $DIR/default_numeric_fallback_i32.rs:17:17 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32` @@ -7,145 +7,145 @@ LL | let x = 22; = note: `-D clippy::default-numeric-fallback` implied by `-D warnings` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:17:18 + --> $DIR/default_numeric_fallback_i32.rs:18:18 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:17:21 + --> $DIR/default_numeric_fallback_i32.rs:18:21 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:17:24 + --> $DIR/default_numeric_fallback_i32.rs:18:24 | LL | let x = [1, 2, 3]; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:18:28 + --> $DIR/default_numeric_fallback_i32.rs:19:28 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:18:31 + --> $DIR/default_numeric_fallback_i32.rs:19:31 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:18:44 + --> $DIR/default_numeric_fallback_i32.rs:19:44 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `3_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:18:47 + --> $DIR/default_numeric_fallback_i32.rs:19:47 | LL | let x = if true { (1, 2) } else { (3, 4) }; | ^ help: consider adding suffix: `4_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:19:23 + --> $DIR/default_numeric_fallback_i32.rs:20:23 | LL | let x = match 1 { | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:20:13 + --> $DIR/default_numeric_fallback_i32.rs:21:13 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:20:18 + --> $DIR/default_numeric_fallback_i32.rs:21:18 | LL | 1 => 1, | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:21:18 + --> $DIR/default_numeric_fallback_i32.rs:22:18 | LL | _ => 2, | ^ help: consider adding suffix: `2_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:38:21 + --> $DIR/default_numeric_fallback_i32.rs:39:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:46:21 + --> $DIR/default_numeric_fallback_i32.rs:47:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:52:21 + --> $DIR/default_numeric_fallback_i32.rs:53:21 | LL | let y = 1; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:64:9 + --> $DIR/default_numeric_fallback_i32.rs:65:9 | LL | 1 | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:70:27 + --> $DIR/default_numeric_fallback_i32.rs:71:27 | LL | let f = || -> _ { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:74:29 + --> $DIR/default_numeric_fallback_i32.rs:75:29 | LL | let f = || -> i32 { 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:88:21 + --> $DIR/default_numeric_fallback_i32.rs:89:21 | LL | generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:91:32 + --> $DIR/default_numeric_fallback_i32.rs:92:32 | LL | let x: _ = generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:109:28 + --> $DIR/default_numeric_fallback_i32.rs:110:28 | LL | GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:112:36 + --> $DIR/default_numeric_fallback_i32.rs:113:36 | LL | let _ = GenericStruct { x: 1 }; | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:130:24 + --> $DIR/default_numeric_fallback_i32.rs:131:24 | LL | GenericEnum::X(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:150:23 + --> $DIR/default_numeric_fallback_i32.rs:151:23 | LL | s.generic_arg(1); | ^ help: consider adding suffix: `1_i32` error: default numeric fallback might occur - --> $DIR/default_numeric_fallback_i32.rs:157:21 + --> $DIR/default_numeric_fallback_i32.rs:158:21 | LL | let x = 22; | ^^ help: consider adding suffix: `22_i32`