@@ -85,16 +85,19 @@ impl LateLintPass<'_> for InstantSubtraction {
85
85
lhs,
86
86
rhs,
87
87
) = expr. kind
88
+ && let typeck = cx. typeck_results ( )
89
+ && ty:: is_type_diagnostic_item ( cx, typeck. expr_ty ( lhs) , sym:: Instant )
88
90
{
91
+ let rhs_ty = typeck. expr_ty ( rhs) ;
92
+
89
93
if is_instant_now_call ( cx, lhs)
90
- && is_an_instant ( cx, rhs )
94
+ && ty :: is_type_diagnostic_item ( cx, rhs_ty , sym :: Instant )
91
95
&& let Some ( sugg) = Sugg :: hir_opt ( cx, rhs)
92
96
{
93
97
print_manual_instant_elapsed_sugg ( cx, expr, sugg) ;
94
- } else if !expr. span . from_expansion ( )
98
+ } else if ty:: is_type_diagnostic_item ( cx, rhs_ty, sym:: Duration )
99
+ && !expr. span . from_expansion ( )
95
100
&& self . msrv . meets ( msrvs:: TRY_FROM )
96
- && is_an_instant ( cx, lhs)
97
- && is_a_duration ( cx, rhs)
98
101
{
99
102
print_unchecked_duration_subtraction_sugg ( cx, lhs, rhs, expr) ;
100
103
}
@@ -115,16 +118,6 @@ fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool {
115
118
}
116
119
}
117
120
118
- fn is_an_instant ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
119
- let expr_ty = cx. typeck_results ( ) . expr_ty ( expr) ;
120
- ty:: is_type_diagnostic_item ( cx, expr_ty, sym:: Instant )
121
- }
122
-
123
- fn is_a_duration ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
124
- let expr_ty = cx. typeck_results ( ) . expr_ty ( expr) ;
125
- ty:: is_type_diagnostic_item ( cx, expr_ty, sym:: Duration )
126
- }
127
-
128
121
fn print_manual_instant_elapsed_sugg ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , sugg : Sugg < ' _ > ) {
129
122
span_lint_and_sugg (
130
123
cx,
0 commit comments