I ran into something minor, but still surprising. Using this code:
fn main() {
let md = std::fs::metadata("file.txt").unwrap();
let size = md.len() as u64;
println!("{size}");
}
And this section in Cargo.toml
:
[lints.clippy]
all = { level = "deny", priority = -1 }
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
cargo_common_metadata = "allow"
On macos:
$ cargo version
cargo 1.81.0 (2dbb1af80 2024-08-20)
$ cargo clippy
Checking playground v0.1.0 (/Volumes/ramdisk/playground)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
On Linux:
$ cargo version
cargo 1.81.0 (2dbb1af80 2024-08-20)
$ cargo clippy
Checking playground v0.1.0 (/tmp/playground)
error: casting to the same type is unnecessary (`u64` -> `u64`)
--> src/main.rs:4:14
|
4 | let size = md.len() as u64;
| ^^^^^^^^^^^^^^^ help: try: `md.len()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
= note: `-D clippy::unnecessary-cast` implied by `-D clippy::all`
= help: to override `-D clippy::all` add `#[allow(clippy::unnecessary_cast)]`
error: could not compile `playground` (bin "playground") due to 1 previous error
Ignoring the fact that it, indeed, is a unnecessary cast -- why would this lint trigger on Linux, but not mac (both x86-64 platforms)? The md.len()
returns u64
on both platforms.