Skip to content

Type incorrectly inferred for negative integer that is inferred as an usize #26033

Closed
@pvginkel

Description

@pvginkel

The output of the following test case is 18446744073709551615:

fn main() {
    let mut x = -1;

    for i in vec![1usize] {
        break;
        x = i;
    }

    println!("{}", x);
}

The problem is that x is inferred as being usize. However, the -1 initial value cannot be hold in that type, so it overflows/gets transmuted into an usize.

My expectation is that this should result in a compilation error.

Meta

rustc 1.1.0-beta (cd7d89a 2015-05-16) (built 2015-05-16)
binary: rustc
commit-hash: cd7d89a
commit-date: 2015-05-16
build-date: 2015-05-16
host: x86_64-pc-windows-gnu
release: 1.1.0-beta

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions