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

thread '<main>' panicked at 'no entry found for key' #1175

Closed
untitaker opened this issue Jan 15, 2015 · 9 comments
Closed

thread '<main>' panicked at 'no entry found for key' #1175

untitaker opened this issue Jan 15, 2015 · 9 comments

Comments

@untitaker
Copy link
Contributor

thread '<main>' panicked at 'no entry found for key', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/s
rc/libcore/option.rs:330                                                                                                      stack backtrace:
   1:     0x7f33a8259230 - sys::backtrace::write::hb7fa0f4f6b33ee3a8Rt
   2:     0x7f33a827acd0 - failure::on_fail::h4388493538a5ad8ck8z
   3:     0x7f33a81e9880 - rt::unwind::begin_unwind_inner::h644ddf1c409df284cNz
   4:     0x7f33a81ea3b0 - rt::unwind::begin_unwind_fmt::h872fa98dc2f66468JLz
   5:     0x7f33a827ab30 - rust_begin_unwind
   6:     0x7f33a82c3680 - panicking::panic_fmt::h4359f3a82e34f47bvym
   7:     0x7f33a89d3440 - option::Option<T>::expect::h13725484968495965889
   8:     0x7f33a89d33c0 - collections::hash::map::HashMap<K, V, S>.IndexMut<Q>::index_mut::h6095433997224322788
   9:     0x7f33a89d2140 - cli::generate_contact::hfcebf25496e6fb0dfwa
  10:     0x7f33a89cd2b0 - cli::add_contact::h4c4cd0e71f37d5c32ra
  11:     0x7f33a89c5820 - cli::cli_main::h513d87d819442dddmha
  12:     0x7f33a89b3670 - main::h3ffbcf7ffbb59354gaa
  13:     0x7f33a82e1e80 - rust_try_inner
  14:     0x7f33a82e1e70 - rust_try
  15:     0x7f33a827c930 - rt::lang_start::h46417f3fa3eb30a5w2z
  16:     0x7f33a89b36a0 - main
  17:     0x7f33a7492f50 - __libc_start_main
  18:     0x7f33a89b3540 - <unknown>
  19:                0x0 - <unknown>

#885 possibly related. I have no idea what went wrong. Code that triggered this looks like this:

my_hashmap: HashMap<String, String> = HashMap::new();
my_hashmap["FOO".to_string()] = ...
@alexcrichton
Copy link
Member

Do you have a project that I could repro this issue with?

@untitaker
Copy link
Contributor Author

I'll try to trim down the code a bit... the LOC are several thousands. This might take a while though.

@alexcrichton
Copy link
Member

Sure! The manifest is normally enough to repro as well.

(also be sure you're using an up-to-date cargo)

@untitaker
Copy link
Contributor Author

Whoa, that was easy:

use std::collections::HashMap;

fn main() {
    let mut hm: HashMap<String, String> = HashMap::new();
    hm["LOL".to_string()] = "HAHA".to_string();
}

@untitaker
Copy link
Contributor Author

$ rustc --version
rustc 1.0.0-nightly (3d0d9bb6f 2015-01-12 22:56:20 +0000)

@untitaker
Copy link
Contributor Author

FWIW this is ArchLinux running on rust-nightly-bin from the AUR.

@alexcrichton
Copy link
Member

Oh! Sorry this is actually the bug tracker for Cargo issues, so I mistakenly thought that the backtrace was from Cargo itself :).

What you've got is actually expected behavior. Currently the IndexMut on HashMap (which the []= syntax is using) looks up the key first and then sets the value. In this case you're seeing the panic because the lookup is failing due to the key not being present. For insertion you'll currently want to use .insert instead of the overloaded syntax.

@untitaker
Copy link
Contributor Author

Ouch... I didn't look myself, sorry.

@alexcrichton
Copy link
Member

No worries!

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

2 participants