Clippy lints / Nursery
Clippy lint · Nursery · checked with Clippy 0.1.99
clippy::unused_rounding: used the `ceil` method with a whole number float
What it meansDetects cases where a whole-number literal float is being rounded, using the floor, ceil, or round methods. It is in the nursery group and off by default.
What you see
warning: used the `ceil` method with a whole number float --> main.rs:3:9 | 3 | let x = 1f32.ceil(); | ^^^^^^^^^^^ help: remove the `ceil` method call: `1f32` | = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#unused_rounding = note: `-W clippy::unused-rounding` implied by `-W clippy::nursery`
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
This is unnecessary and confusing to the reader. Doing this is probably a mistake.
New lints still being finished. Off by default and may have false positives.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
let x = 1f32.ceil();
Write this instead
let x = 1f32;
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
unused_rounding = "warn"In code
#![warn(clippy::unused_rounding)]One run
cargo clippy -- -W clippy::unused-roundingThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Detects cases where a whole-number literal float is being rounded, using
the floor, ceil, or round methods.
Why is this bad?
This is unnecessary and confusing to the reader. Doing this is probably a mistake.
Example
let x = 1f32.ceil();
Use instead:
let x = 1f32;
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- redundant_cloneChecks for a redundant clone() (and its relatives) which clones an owned value that is going to be dropped without further use
- uninhabited_referencesdereferencing a reference to an uninhabited type would be undefined behavior
- unnecessary_struct_initializationunnecessary struct building
- unused_peekable`peek` never called on `Peekable` iterator
- use_selfunnecessary structure name repetition
- useless_let_if_seqChecks for variable declarations immediately followed by a conditional affectation
- volatile_compositestype `main::MyDevice` is not volatile-compatible
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::redundant_cloneChecks for a redundant clone() (and its relatives) which clones an owned value that is going to be dropped without further useRead it next →Did this answer your question?