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)]
10 #![allow(clippy::match_single_binding)]
13 extern crate macro_rules;
17 // Should lint unsuffixed literals typed `f64`.
20 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.
30 let x: [f64; 3] = [1., 2., 3.];
31 let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) };
39 // Should lint this because this literal is not bound to any types.
42 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
47 // Should lint this because this literal is not bound to any types.
50 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
53 // Should lint this because this literal is not bound to any types.
56 // Should NOT lint this because this literal is bound to `_` of outer `Local`.
64 // Even though the output type is specified,
65 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
70 // Should lint this because return type is inferred to `f64` and NOT bound to a concrete
72 let f = || -> _ { 1. };
74 // Even though the output type is specified,
75 // this unsuffixed literal is linted to reduce heuristics and keep codebase simple.
76 let f = || -> f64 { 1. };
81 fn concrete_arg(f: f64) {}
83 fn generic_arg<T>(t: T) {}
86 // Should NOT lint this because the argument type is bound to a concrete type.
89 // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type.
92 // Should lint this because the argument type is inferred to `f64` and NOT bound to a concrete type.
93 let x: _ = generic_arg(1.);
98 struct ConcreteStruct {
102 struct GenericStruct<T> {
107 // Should NOT lint this because the field type is bound to a concrete type.
108 ConcreteStruct { x: 1. };
110 // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type.
111 GenericStruct { x: 1. };
113 // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type.
114 let _ = GenericStruct { x: 1. };
123 enum GenericEnum<T> {
128 // Should NOT lint this because the field type is bound to a concrete type.
131 // Should lint this because the field type is inferred to `f64` and NOT bound to a concrete type.
137 struct StructForMethodCallTest {}
139 impl StructForMethodCallTest {
140 fn concrete_arg(&self, f: f64) {}
142 fn generic_arg<T>(&self, t: T) {}
146 let s = StructForMethodCallTest {};
148 // Should NOT lint this because the argument type is bound to a concrete type.
151 // Should lint this because the argument type is bound to a concrete type.
157 macro_rules! internal_macro {
163 // Should lint in internal macro.
168 // Should NOT lint in external macro.
170 default_numeric_fallback!();