@@ -8,6 +8,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind};
8
8
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
9
9
use rustc_middle:: lint:: in_external_macro;
10
10
use rustc_middle:: ty:: { self , FloatTy } ;
11
+ use rustc_session:: impl_lint_pass;
11
12
use rustc_span:: { sym, Span } ;
12
13
13
14
declare_clippy_lint ! {
@@ -16,50 +17,50 @@ declare_clippy_lint! {
16
17
/// precision is lost.
17
18
///
18
19
/// ### Why is this bad?
19
- /// This can be bad if the user wanted to retain the full precision of the duration.
20
+ /// Retaining the full precision of a duration is usually desired .
20
21
///
21
22
/// ### Example
22
23
/// ```no_run
23
24
/// # use std::time::Duration;
24
- /// # let duration = Duration::from_nanos(1234500000);
25
+ /// let duration = Duration::from_nanos(1234500000);
25
26
/// let _ = duration.as_millis() as f64;
26
27
/// ```
27
28
///
28
29
/// Use instead:
29
30
///
30
31
/// ```no_run
31
32
/// # use std::time::Duration;
32
- /// # let duration = Duration::from_nanos(1234500000);
33
+ /// let duration = Duration::from_nanos(1234500000);
33
34
/// let _ = duration.as_secs_f64() * 1000.0;
34
35
/// ```
35
36
///
36
37
/// Another motivating example happens when calculating number of seconds as a float with millisecond precision:
37
38
///
38
39
/// ```no_run
39
40
/// # use std::time::Duration;
40
- /// # let duration = Duration::from_nanos(1234500000);
41
+ /// let duration = Duration::from_nanos(1234500000);
41
42
/// let _ = duration.as_millis() as f64 / 1000.0;
42
43
/// ```
43
44
///
44
45
/// Use instead:
45
46
///
46
47
/// ```no_run
47
48
/// # use std::time::Duration;
48
- /// # let duration = Duration::from_nanos(1234500000);
49
+ /// let duration = Duration::from_nanos(1234500000);
49
50
/// let _ = duration.as_secs_f64();
50
51
/// ```
51
- #[ clippy:: version = "1.78 .0" ]
52
+ #[ clippy:: version = "1.79 .0" ]
52
53
pub DURATION_TO_FLOAT_PRECISION_LOSS ,
53
- nursery ,
54
+ style ,
54
55
"conversion from duration to float that cause loss of precision"
55
56
}
56
57
57
58
/// This struct implements the logic needed to apply the lint
58
59
#[ derive( Debug ) ]
59
60
pub struct DurationToFloatPrecisionLoss {
60
- // This vector is used to prevent applying the lint to a sub-expression
61
+ /// This vector is used to prevent applying the lint to a sub-expression
61
62
lint_applications : Vec < Span > ,
62
- // `as_secs_f64` isn't applicable until 1.38.0
63
+ /// `as_secs_f64` isn't applicable until 1.38.0
63
64
msrv : Msrv ,
64
65
}
65
66
@@ -84,7 +85,7 @@ impl DurationToFloatPrecisionLoss {
84
85
}
85
86
}
86
87
87
- rustc_session :: impl_lint_pass!( DurationToFloatPrecisionLoss => [ DURATION_TO_FLOAT_PRECISION_LOSS ] ) ;
88
+ impl_lint_pass ! ( DurationToFloatPrecisionLoss => [ DURATION_TO_FLOAT_PRECISION_LOSS ] ) ;
88
89
89
90
impl < ' tcx > LateLintPass < ' tcx > for DurationToFloatPrecisionLoss {
90
91
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
0 commit comments