Skip to content

cast_lossless is triggered on const fn #3656

@roblabla

Description

@roblabla
pub const fn ioport(ioport: u16) -> u32 {
    0b11_1111_1111 | ((ioport as u32) << 11)
}

This triggers the cast_lossless lint:

    Checking playground v0.0.1 (/playground)
warning: casting u16 to u32 may become silently lossy if types change
 --> src/main.rs:2:23
  |
2 |     0b11_1111_1111 | ((ioport as u32) << 11)
  |                       ^^^^^^^^^^^^^^^ help: try: `u32::from(ioport)`
  |
  = note: #[warn(clippy::cast_lossless)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless

    Finished dev [unoptimized + debuginfo] target(s) in 1.39s

However, u32::from is not a const fn, and thus the suggested replacement will fail. Link to playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e5a19374d44dd33555594f205a7b3aa5

Clippy version: clippy 0.0.212 (39bd844 2018-12-30)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions