@@ -8,6 +8,7 @@ use rustc_hir::{BinOpKind, Expr, ExprKind};
88use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
99use rustc_middle:: lint:: in_external_macro;
1010use rustc_middle:: ty:: { self , FloatTy } ;
11+ use rustc_session:: impl_lint_pass;
1112use rustc_span:: { sym, Span } ;
1213
1314declare_clippy_lint ! {
@@ -16,50 +17,50 @@ declare_clippy_lint! {
1617 /// precision is lost.
1718 ///
1819 /// ### 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 .
2021 ///
2122 /// ### Example
2223 /// ```no_run
2324 /// # use std::time::Duration;
24- /// # let duration = Duration::from_nanos(1234500000);
25+ /// let duration = Duration::from_nanos(1234500000);
2526 /// let _ = duration.as_millis() as f64;
2627 /// ```
2728 ///
2829 /// Use instead:
2930 ///
3031 /// ```no_run
3132 /// # use std::time::Duration;
32- /// # let duration = Duration::from_nanos(1234500000);
33+ /// let duration = Duration::from_nanos(1234500000);
3334 /// let _ = duration.as_secs_f64() * 1000.0;
3435 /// ```
3536 ///
3637 /// Another motivating example happens when calculating number of seconds as a float with millisecond precision:
3738 ///
3839 /// ```no_run
3940 /// # use std::time::Duration;
40- /// # let duration = Duration::from_nanos(1234500000);
41+ /// let duration = Duration::from_nanos(1234500000);
4142 /// let _ = duration.as_millis() as f64 / 1000.0;
4243 /// ```
4344 ///
4445 /// Use instead:
4546 ///
4647 /// ```no_run
4748 /// # use std::time::Duration;
48- /// # let duration = Duration::from_nanos(1234500000);
49+ /// let duration = Duration::from_nanos(1234500000);
4950 /// let _ = duration.as_secs_f64();
5051 /// ```
51- #[ clippy:: version = "1.78 .0" ]
52+ #[ clippy:: version = "1.79 .0" ]
5253 pub DURATION_TO_FLOAT_PRECISION_LOSS ,
53- nursery ,
54+ style ,
5455 "conversion from duration to float that cause loss of precision"
5556}
5657
5758/// This struct implements the logic needed to apply the lint
5859#[ derive( Debug ) ]
5960pub 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
6162 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
6364 msrv : Msrv ,
6465}
6566
@@ -84,7 +85,7 @@ impl DurationToFloatPrecisionLoss {
8485 }
8586}
8687
87- rustc_session :: impl_lint_pass!( DurationToFloatPrecisionLoss => [ DURATION_TO_FLOAT_PRECISION_LOSS ] ) ;
88+ impl_lint_pass ! ( DurationToFloatPrecisionLoss => [ DURATION_TO_FLOAT_PRECISION_LOSS ] ) ;
8889
8990impl < ' tcx > LateLintPass < ' tcx > for DurationToFloatPrecisionLoss {
9091 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' _ > ) {
0 commit comments