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 8ea395e commit e9c2d82Copy full SHA for e9c2d82
clippy_utils/src/lib.rs
@@ -1638,6 +1638,18 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
1638
false
1639
}
1640
1641
+/// Checks whether the given expression is a constant integer of the given value
1642
+/// as a floating point literal.
1643
+pub fn is_floating_point_integer_literal(expr: &Expr<'_>, value: u32) -> bool {
1644
+ if let ExprKind::Lit(spanned) = expr.kind
1645
+ && let LitKind::Float(v, _) = spanned.node
1646
+ {
1647
+ v.as_str().parse() == Ok(f64::from(value))
1648
+ } else {
1649
+ false
1650
+ }
1651
+}
1652
+
1653
/// Returns `true` if the given `Expr` has been coerced before.
1654
///
1655
/// Examples of coercions can be found in the Nomicon at
0 commit comments