Skip to content

clippy::transmute_float_to_int in const context should not trigger when rust-version is less than 1.83 in Cargo.toml  #13383

Closed
rust-lang/rust
#130305
@tspiteri

Description

@tspiteri

Summary

When rust-version is less than 1.83, the suggested code does not compile.

Lint Name

clippy::transmute_float_to_int

Reproducer

Cargo.toml contains:

rust-version = "1.82"

I tried this code:

pub const fn f32_to_u32(f: f32) -> u32 {
    unsafe { core::mem::transmute(f) }
}

I saw this happen:

warning: transmute from a `f32` to a `u32`
 --> src/lib.rs:2:14
  |
2 |     unsafe { core::mem::transmute(f) }
  |              ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `f.to_bits()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#transmute_float_to_int
  = note: `#[warn(clippy::transmute_float_to_int)]` on by default

I expected to see this happen:
No warning as rust 1.82.0 does not support f32::to_bits in const context.

Version

rustc 1.83.0-nightly (0ee7cb5e3 2024-09-10)
binary: rustc
commit-hash: 0ee7cb5e3633502d9a90a85c3c367eccd59a0aba
commit-date: 2024-09-10
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions