Skip to content

Type inference requires type of LHS to be known for binary operators #8280

Closed
@mihneadb

Description

@mihneadb

This is the code:

use std::hashmap;

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

    let str = "Hello, world!";

    for &char in str.to_ascii().iter() {
        let count = map.find(&char);
        match count {
            Some(&x) => map.insert(char, x + 1),
            None => map.insert(char, 1)
        }
    }

    println!("{:?}", map);
}

Error message:

count_chars.rs:11:41: 11:42 error: the type of this value must be known in this context
count_chars.rs:11             Some(&x) => map.insert(char, x + 1),
                                                       ^
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions