2 // aux-build:macro_rules.rs
4 #![warn(clippy::default_numeric_fallback)]
6 #![allow(clippy::never_loop)]
7 #![allow(clippy::no_effect)]
8 #![allow(clippy::unnecessary_operation)]
9 #![allow(clippy::branches_sharing_code)]
12 extern crate macro_rules;
16 // Should lint unsuffixed literals typed `i32`.
19 let x = if true { (1, 2) } else { (3, 4) };
25 // Should NOT lint suffixed literals.
28 // Should NOT lint literals in init expr if `Local` has a type annotation.
29 let x: [i32; 3] = [1, 2, 3];
30 let x: (i32, i32) = if true { (1, 2) } else { (3, 4) };
38 // Should lint this because this literal is not bound to any types.
41 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
46 // Should lint this because this literal is not bound to any types.
49 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
52 // Should lint this because this literal is not bound to any types.
55 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
63 // Even though the output type is specified,
64 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
69 // Should lint this because return type is inferred to `i32` and NOT bound to a concrete
71 let f = || -> _ { 1 };
73 // Even though the output type is specified,
74 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
75 let f = || -> i32 { 1 };
80 fn concrete_arg(x: i32) {}
82 fn generic_arg<T>(t: T) {}
85 // Should NOT lint this because the argument type is bound to a concrete type.
88 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
91 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
92 let x: _ = generic_arg(1);
97 struct ConcreteStruct {
101 struct GenericStruct<T> {
106 // Should NOT lint this because the field type is bound to a concrete type.
107 ConcreteStruct { x: 1 };
109 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
110 GenericStruct { x: 1 };
112 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
113 let _ = GenericStruct { x: 1 };
122 enum GenericEnum<T> {
127 // Should NOT lint this because the field type is bound to a concrete type.
130 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
136 struct StructForMethodCallTest {}
138 impl StructForMethodCallTest {
139 fn concrete_arg(&self, x: i32) {}
141 fn generic_arg<T>(&self, t: T) {}
145 let s = StructForMethodCallTest {};
147 // Should NOT lint this because the argument type is bound to a concrete type.
150 // Should lint this because the argument type is bound to a concrete type.
156 macro_rules! internal_macro {
162 // Should lint in internal macro.
167 // Should NOT lint in external macro.
169 default_numeric_fallback!();