Skip to content

Type inference stopping short of success #5834

Closed
@alexcrichton

Description

@alexcrichton

For this program

use core::hashmap::HashMap;

fn main() {
  let mut m = HashMap::new();

  match m.find_mut(&1) {
    Some(a) => { a.push(2); }
    None => ()
  }
  m.insert(3, ~[3]);
}

You get the error

foo.rs:7:17: 7:18 error: the type of this value must be known in this context
foo.rs:7     Some(a) => { a.push(2); }
                          ^
error: aborting due to previous error

If the m.insert line were farther up, the program compiles just fine. It seems like if the compiler were to look ahead a bit farther it could figure out the type of the hash map.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions