We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
is_floating_point_integer_literal
1 parent 25d319d commit dcc678fCopy full SHA for dcc678f
clippy_utils/src/lib.rs
@@ -1648,6 +1648,18 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
1648
false
1649
}
1650
1651
+/// Checks whether the given expression is a constant integer of the given value
1652
+/// as a floating point literal.
1653
+pub fn is_floating_point_integer_literal(expr: &Expr<'_>, value: u32) -> bool {
1654
+ if let ExprKind::Lit(spanned) = expr.kind
1655
+ && let LitKind::Float(v, _) = spanned.node
1656
+ {
1657
+ v.as_str().parse() == Ok(f64::from(value))
1658
+ } else {
1659
+ false
1660
+ }
1661
+}
1662
+
1663
/// Returns `true` if the given `Expr` has been coerced before.
1664
///
1665
/// Examples of coercions can be found in the Nomicon at
0 commit comments