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_float_literal
1 parent c5218d5 commit 0aa03e1Copy full SHA for 0aa03e1
clippy_utils/src/lib.rs
@@ -1655,6 +1655,17 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
1655
false
1656
}
1657
1658
+/// Checks whether the given expression is a constant literal of the given value.
1659
+pub fn is_float_literal(expr: &Expr<'_>, value: f64) -> bool {
1660
+ if let ExprKind::Lit(spanned) = expr.kind
1661
+ && let LitKind::Float(v, _) = spanned.node
1662
+ {
1663
+ v.as_str().parse() == Ok(value)
1664
+ } else {
1665
+ false
1666
+ }
1667
+}
1668
+
1669
/// Returns `true` if the given `Expr` has been coerced before.
1670
///
1671
/// Examples of coercions can be found in the Nomicon at
0 commit comments