use std::collections::BTreeMap;
fn main() {
let mut q = BTreeMap::new;
for i in 0..1000_000_000 {
q.insert(i, [0u8; 65536]);
}
}
$ rustc heapoverflow.rs
heapoverflow.rs:6:11: 6:34 error: no method named `insert` found for type `fn() -> collections::btree::map::BTreeMap<_, _> {collections::btree::map::BTreeMap<K, V>::new}` in the current scope
heapoverflow.rs:6 q.insert(i, [0u8; 65536]);
^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
At first I tried add instead of insert, then looked at docs, changed to insert again, then tried deliberately invalid inse3rt to ensure that error message does not change. Then I noticed fn() in error message and after little thinking found the issue.
Maybe such simple mistake should have friendlier error message? For example, if obj.method does not exist, but obj().method does, it can be mentioned somehow.
At first I tried
addinstead ofinsert, then looked at docs, changed toinsertagain, then tried deliberately invalidinse3rtto ensure that error message does not change. Then I noticedfn()in error message and after little thinking found the issue.Maybe such simple mistake should have friendlier error message? For example, if
obj.methoddoes not exist, butobj().methoddoes, it can be mentioned somehow.