Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
pvginkel opened this issue Jun 5, 2015 · 2 comments
Closed

Comments

@pvginkel
Copy link

pvginkel commented Jun 5, 2015

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

@nagisa
Copy link
Member

nagisa commented Jun 5, 2015

Same thing as #24676.

@alexcrichton
Copy link
Member

Indeed, closing as a dupe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants