Skip to content

Type inference stopping short of success #5834

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

Closed
alexcrichton opened this issue Apr 11, 2013 · 2 comments
Closed

Type inference stopping short of success #5834

alexcrichton opened this issue Apr 11, 2013 · 2 comments
Labels
A-type-system Area: Type system

Comments

@alexcrichton
Copy link
Member

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.

@catamorphism
Copy link
Contributor

Seems like a typechecker bug to me (it should gather all the constraints before reporting this error). Though @nikomatsakis can correct me if I'm wrong.

Nominating for milestone 5, production-ready.

@nikomatsakis
Copy link
Contributor

This is working as expected. We use a hybrid form of HM which sometimes requires type information to proceed. Certain operators (the . operator and the * operator, in particular, though perhaps a few others) are overloaded based on the type of the argument and simply cannot be typed otherwise. Sorry, you'll just have to add an annotation on m.

bors pushed a commit to rust-lang-ci/rust that referenced this issue Oct 24, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 24, 2020
…e, r=flip1995

Ref style link false positive

This PR does not fix rust-lang#5834, but it records the problematic link text as a **known problem** inside `doc_markdown` lint.

r? `@flip1995`

- [ ] Followed [lint naming conventions][lint_naming]
- [ ] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [ ] Added lint documentation
- [x] Run `cargo dev fmt`

---

*Please keep the line below*
changelog: Document problematic link text style as known problem for `doc_markdown`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants