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

HashMap with Path key crashes rustc #23036

Closed
dextero opened this issue Mar 4, 2015 · 2 comments
Closed

HashMap with Path key crashes rustc #23036

dextero opened this issue Mar 4, 2015 · 2 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@dextero
Copy link

dextero commented Mar 4, 2015

Hello,

Lately I've been experimenting with Rust, and it seems I accidentally managed to crash rustc. Trying to compile following snippet:

#![feature(path)]
use std::collections::HashMap;
use std::path::Path;

fn main() {
    let mut map = HashMap::new();
    map.insert(Path::new("a"), 0);
    map.get(Path::new("a"));
}

... causes an assertion fail:

$ RUST_BACKTRACE=1 rustc --verbose src/main.rs
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/lib/IR/Instructions.cpp:1083: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
[1]    30171 abort (core dumped)  rustc --verbose src/main.rs

Specifying an explicit variable type prevents crashing. Such code:

#![feature(path)]
use std::collections::HashMap;
use std::path::Path;

fn main() {
    let mut map: HashMap<Path, i32> = HashMap::new();
    map.insert(Path::new("a"), 0);
    map.get(Path::new("a"));
}

... produces an compile-time error as expected:

$ rustc --verbose src/main.rs
src/main.rs:6:18: 6:36 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
src/main.rs:6     let mut map: HashMap<Path, i32> = HashMap::new();
                               ^~~~~~~~~~~~~~~~~~
src/main.rs:6:18: 6:36 note: `[u8]` does not have a constant size known at compile-time
src/main.rs:6     let mut map: HashMap<Path, i32> = HashMap::new();
                               ^~~~~~~~~~~~~~~~~~
src/main.rs:7:9: 7:34 error: type `std::collections::hash::map::HashMap<std::path::Path, i32>` does not implement any method in scope named `insert`
src/main.rs:7     map.insert(Path::new("a"), 0);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:8:9: 8:28 error: type `std::collections::hash::map::HashMap<std::path::Path, i32>` does not implement any method in scope named `get`
src/main.rs:8     map.get(Path::new("a"));
                      ^~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors

The [u8] in the error message is quite surprising, though - it's not entirely clear what's really going on without looking at the libstd code. I would rather expect to see a Path there.

Meta

Both snippets were tested on 64-bit Ubuntu 14.04 and compiled with two versions of rustc (the behavior is exactly the same for both):

$ rustc --version --verbose
rustc 1.0.0-dev (522d09dfe 2015-02-19) (built 2015-03-04)
binary: rustc
commit-hash: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
commit-date: 2015-02-19
build-date: 2015-03-04
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev
$ rustc --version --verbose
rustc 1.0.0-nightly (fed12499e 2015-03-03) (built 2015-03-04)
binary: rustc
commit-hash: fed12499e7d91f9cdfba5833e34d20e8fd19b898
commit-date: 2015-03-03
build-date: 2015-03-04
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 4, 2015
@Stebalien
Copy link
Contributor

I cannot reproduce on the latest (2015-05-09) nightly (64bit linux).

@arielb1
Copy link
Contributor

arielb1 commented Sep 13, 2015

does not crash 1.2+

@arielb1 arielb1 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 13, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Sep 15, 2015
bors added a commit that referenced this issue Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants