Skip to content

Should lossy conversions be compiler warning #2784

Description

@elichai

Hi,
Should lossy conversions (i.e. let a = 300u16 as u8) be a compile time warning?
that way people can opt in with #![deny(cast_lossy)]

Otherwise maybe a way to make generic that have size constraints?

I'm working on a new library where I'm casting a bunch of stuff to usize and for example usize::from(0u32) isn't a thing. even though it should work on both 32bit and 64bit machines.

So right now I have a bunch of static asserts to check that size_of<usize> => size_of<u32>().

Edit: Related to #2715

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-conversionsConversion related proposals & ideasA-lintProposals relating to lints / warnings / clippy.T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions