2 // aux-build:macro_rules.rs
4 #![warn(clippy::default_numeric_fallback)]
9 clippy::unnecessary_operation,
10 clippy::branches_sharing_code,
11 clippy::let_unit_value
15 extern crate macro_rules;
19 // Should lint unsuffixed literals typed `i32`.
22 let x = if true { (1, 2) } else { (3, 4) };
28 // Should NOT lint suffixed literals.
31 // Should NOT lint literals in init expr if `Local` has a type annotation.
32 let x: [i32; 3] = [1, 2, 3];
33 let x: (i32, i32) = if true { (1, 2) } else { (3, 4) };
41 // Should lint this because this literal is not bound to any types.
44 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
49 // Should lint this because this literal is not bound to any types.
52 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
55 // Should lint this because this literal is not bound to any types.
58 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
66 // Even though the output type is specified,
67 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
72 // Should lint this because return type is inferred to `i32` and NOT bound to a concrete
74 let f = || -> _ { 1 };
76 // Even though the output type is specified,
77 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
78 let f = || -> i32 { 1 };
83 fn concrete_arg(x: i32) {}
85 fn generic_arg<T>(t: T) {}
88 // Should NOT lint this because the argument type is bound to a concrete type.
91 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
94 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
95 let x: _ = generic_arg(1);
100 struct ConcreteStruct {
104 struct GenericStruct<T> {
109 // Should NOT lint this because the field type is bound to a concrete type.
110 ConcreteStruct { x: 1 };
112 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
113 GenericStruct { x: 1 };
115 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
116 let _ = GenericStruct { x: 1 };
125 enum GenericEnum<T> {
130 // Should NOT lint this because the field type is bound to a concrete type.
133 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
139 struct StructForMethodCallTest;
141 impl StructForMethodCallTest {
142 fn concrete_arg(&self, x: i32) {}
144 fn generic_arg<T>(&self, t: T) {}
148 let s = StructForMethodCallTest {};
150 // Should NOT lint this because the argument type is bound to a concrete type.
153 // Should lint this because the argument type is bound to a concrete type.
159 macro_rules! internal_macro {
165 // Should lint in internal macro.
170 // Should NOT lint in external macro.
172 default_numeric_fallback!();