You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: I was playing around with trees for a bit, when I decided the order of the children didn't matter and swapped Vecs for HashSets. However, I forgot to substitute them everywhere, which resulted in the following (minimized) code and a compiler panic.
I tried this code:
use std::collections::HashMap;use std::collections::HashSet;fnmain(){let tree:HashMap<usize,HashSet<usize>> = HashMap::new();let size_of_1 = tree.get(&1).unwrap_or(&Vec::new()).len();}
I expected to see this happen: the rust compiler complaining about incorrect types. After all, the &Vec::new() should've been a &HashSet::new().
Instead, this happened:
$ rustc test.rs
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'index out of bounds: the len is 18 but the index is 20', src/libcollections/vec.rs:1166
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Note that using the correct intializer works, and using
use std::collections::HashMap;use std::collections::HashSet;structA{a:usize}fnmain(){let tree:HashMap<usize,HashSet<usize>> = HashMap::new();let size_of_1 = tree.get(&1).unwrap_or(&A{a:1}).len();}
complains as expected:
$ rustc test.rs
test.rs:9:44: 9:53 error: mismatched types:
expected `&std::collections::HashSet<usize>`,
found `&A`
(expected struct `std::collections::HashSet`,
found struct `A`) [E0308]
test.rs:9 let size_of_1 = tree.get(&1).unwrap_or(&A {a: 1}).len();
^~~~~~~~~
test.rs:9:44: 9:53 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Context: I was playing around with trees for a bit, when I decided the order of the children didn't matter and swapped
Vec
s forHashSet
s. However, I forgot to substitute them everywhere, which resulted in the following (minimized) code and a compiler panic.I tried this code:
I expected to see this happen: the rust compiler complaining about incorrect types. After all, the
&Vec::new()
should've been a&HashSet::new()
.Instead, this happened:
Note that using the correct intializer works, and using
complains as expected:
Meta
Backtrace:
The text was updated successfully, but these errors were encountered: