Closed
Description
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