1 // aux-build:macro_rules.rs
3 #![warn(clippy::default_numeric_fallback)]
5 #![allow(clippy::never_loop)]
6 #![allow(clippy::no_effect)]
7 #![allow(clippy::unnecessary_operation)]
8 #![allow(clippy::branches_sharing_code)]
11 extern crate macro_rules;
15 // Should lint unsuffixed literals typed `i32`.
18 let x = if true { (1, 2) } else { (3, 4) };
24 // Should lint unsuffixed literals typed `f64`.
27 // Should NOT lint suffixed literals.
31 // Should NOT lint literals in init expr if `Local` has a type annotation.
33 let x: [i32; 3] = [1, 2, 3];
34 let x: (i32, i32) = if true { (1, 2) } else { (3, 4) };
42 // Should lint this because this literal is not bound to any types.
45 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
50 // Should lint this because this literal is not bound to any types.
53 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
56 // Should lint this because this literal is not bound to any types.
59 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
67 // Even though the output type is specified,
68 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
73 // Should lint this because return type is inferred to `i32` and NOT bound to a concrete
75 let f = || -> _ { 1 };
77 // Even though the output type is specified,
78 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
79 let f = || -> i32 { 1 };
84 fn concrete_arg(x: i32) {}
86 fn generic_arg<T>(t: T) {}
89 // Should NOT lint this because the argument type is bound to a concrete type.
92 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
95 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
96 let x: _ = generic_arg(1);
101 struct ConcreteStruct {
105 struct GenericStruct<T> {
110 // Should NOT lint this because the field type is bound to a concrete type.
111 ConcreteStruct { x: 1 };
113 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
114 GenericStruct { x: 1 };
116 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
117 let _ = GenericStruct { x: 1 };
122 struct StructForMethodCallTest {}
124 impl StructForMethodCallTest {
125 fn concrete_arg(&self, x: i32) {}
127 fn generic_arg<T>(&self, t: T) {}
131 let s = StructForMethodCallTest {};
133 // Should NOT lint this because the argument type is bound to a concrete type.
136 // Should lint this because the argument type is bound to a concrete type.
142 macro_rules! internal_macro {
148 // Should lint in internal macro.
153 // Should NOT lint in external macro.
155 default_numeric_fallback!();