2 // aux-build:macro_rules.rs
4 #![feature(lint_reasons)]
5 #![warn(clippy::default_numeric_fallback)]
10 clippy::unnecessary_operation,
11 clippy::branches_sharing_code,
12 clippy::let_unit_value
16 extern crate macro_rules;
20 // Should lint unsuffixed literals typed `i32`.
23 let x = if true { (1, 2) } else { (3, 4) };
29 // Should NOT lint suffixed literals.
32 // 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) };
37 const CONST_X: i8 = 1;
44 // Should lint this because this literal is not bound to any types.
47 // 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`.
58 // Should lint this because this literal is not bound to any types.
61 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
65 const CONST_X: i32 = {
66 // Should lint this because this literal is not bound to any types.
69 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
77 // Even though the output type is specified,
78 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
83 // Should lint this because return type is inferred to `i32` and NOT bound to a concrete
85 let f = || -> _ { 1 };
87 // Even though the output type is specified,
88 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
89 let f = || -> i32 { 1 };
94 fn concrete_arg(x: i32) {}
96 fn generic_arg<T>(t: T) {}
99 // Should NOT lint this because the argument type is bound to a concrete type.
102 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
105 // Should lint this because the argument type is inferred to `i32` and NOT bound to a concrete type.
106 let x: _ = generic_arg(1);
111 struct ConcreteStruct {
115 struct GenericStruct<T> {
120 // Should NOT lint this because the field type is bound to a concrete type.
121 ConcreteStruct { x: 1 };
123 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
124 GenericStruct { x: 1 };
126 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
127 let _ = GenericStruct { x: 1 };
136 enum GenericEnum<T> {
141 // Should NOT lint this because the field type is bound to a concrete type.
144 // Should lint this because the field type is inferred to `i32` and NOT bound to a concrete type.
150 struct StructForMethodCallTest;
152 impl StructForMethodCallTest {
153 fn concrete_arg(&self, x: i32) {}
155 fn generic_arg<T>(&self, t: T) {}
159 let s = StructForMethodCallTest {};
161 // Should NOT lint this because the argument type is bound to a concrete type.
164 // Should lint this because the argument type is bound to a concrete type.
170 macro_rules! internal_macro {
176 // Should lint in internal macro.
181 // Should NOT lint in external macro.
183 default_numeric_fallback!();
187 fn check_expect_suppression() {
188 #[expect(clippy::default_numeric_fallback)]