Skip to content

Literal overflow warnings should only apply to decimal. #24361

Closed
@theemathas

Description

@theemathas
Contributor

E.g. 0x8888i16 should not warn. Similar to binary operations | and &, hexadecimal, binary, and octal literals are often used to specify the concrete representation in memory whereas decimal literals are used to represent abstract values.

Also note that -(0x8000i16) which evaluates to -32768 (hex: 0x8000i16, which is the minimum value of i16) currently does not warn.

cc #22020

reincarnation of #23463

Activity

steveklabnik

steveklabnik commented on Jun 27, 2016

@steveklabnik
Member

Triage: @rust-lang/lang , what do you think about this? This does still warn today, and I'm not sure where i stand, personally.

eddyb

eddyb commented on Jun 27, 2016

@eddyb
Member

I would say that 0x8888u16 as i16 is the "correct" form, but I'm a bit torn.

pnkfelix

pnkfelix commented on Jul 4, 2016

@pnkfelix
Member

I agree with @eddyb

Also, regarding the -(0x8000i16) that does not warn: that falls at runtime on builds with overflow checking. E.g. debug builds.

estebank

estebank commented on Aug 15, 2018

@estebank
Contributor

@rust-lang/lang should we close this given the resolution of #48073? There's no suggestion to write 0x8888u16 as i16, but #48432 could be expanded to do so. Otherwise, if we're not suggesting that, then we we should close this in my opinion.

Mark-Simulacrum

Mark-Simulacrum commented on Sep 8, 2019

@Mark-Simulacrum
Member

I'm going to go ahead and close this as I think we've essentially intentionally chosen a path here and I believe the suggestion has been implemented, if indirectly, by showing what the literal in i16 would be. It seems like largely writing the "end result" or allowing the lint is an acceptable tradeoff.

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-diagnosticsArea: Messages for errors, warnings, and lintsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@eddyb@pnkfelix@estebank@Mark-Simulacrum

        Issue actions

          Literal overflow warnings should only apply to decimal. · Issue #24361 · rust-lang/rust