Skip to content

rustc can't parse large untyped literals correctly #18744

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mahkoh opened this issue Nov 7, 2014 · 7 comments
Closed

rustc can't parse large untyped literals correctly #18744

mahkoh opened this issue Nov 7, 2014 · 7 comments

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Nov 7, 2014

0xFFFF_FFFF_FFFF_FFFF will be interpreted as -1 in certain situations where the correct type is known to be u64.

@huonw
Copy link
Member

huonw commented Nov 7, 2014

Why is being interpreted as -1 bad? It is exactly that.

Could you add a code example demonstrating the issue?

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 7, 2014

fn main() {
    match 1u64 {
        0...0xFFFF_FFFF_FFFF_FFFF => { },
        _ => { },
    }
}

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 7, 2014

test5.rs:3:9: 3:13 error: lower range bound must be less than upper [E0030]
test5.rs:3         0...0xFFFF_FFFF_FFFF_FFFF => { },
                   ^~~~

@thestinger
Copy link
Contributor

@huonw: Generic literals are supposed to have an inferred type but Rust treats them as int in a few places.

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 7, 2014

I guess that means that

fn main() {
    match 1u64 {
        0...0xFFFF_FFFF_FFFF_FF => { },
        _ => { },
    }
}

which compiles correctly on 64 bit will fail to compile on 32 bit or, much worse, truncate the upper bound to something that fits in an int.

@steveklabnik
Copy link
Member

Triage: same error today.

@vbezhenar
Copy link

The following program does not compile:

fn main() {
    let x: u64 = 0;
    match x {
        9223372036854775807 ... 9223372036854775808 => (),
        _ => (),
    }
}

The following program does compile:

fn main() {
    let x: u64 = 0;
    match x {
        9223372036854775808 ... 9223372036854775809 => (),
        _ => (),
    }
}

it's very misleading behavior.

@mahkoh mahkoh closed this as completed Apr 11, 2015
@rust-lang rust-lang locked and limited conversation to collaborators Apr 11, 2015
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants