Skip to content

Unable to infer type information despite enough context. #19853

Closed
@aatxe

Description

@aatxe

So, I have the following code, and it no longer compiles after a recent nightly. This issue appears to be inference-related. This is the error I'm suddenly getting:

markov/src/lib.rs:78:13: 78:27 error: unable to infer enough type information to locate the impl of the trait `core::cmp::Eq` for the type `_`; type annotations required
markov/src/lib.rs:78             self.map[p[0]].add(p[1].clone());
                                 ^~~~~~~~~~~~~~

Here's the code, the line with *** is the one that does not compile.:

impl<T: Eq + Hash> Chain<T> {
    // ...
    pub fn feed(&mut self, tokens: Vec<T>) -> &mut Chain<T> {
        if tokens.len() == 0 { return self }
        let mut toks = Vec::new();
        toks.push(self.start.clone());
        toks.extend(tokens.into_iter().map(|token| {
            let rc = Rc::new(token);
            if !self.map.contains_key(&rc) {
                self.map.insert(rc.clone(), HashMap::new());
            }
            rc
        }));
        toks.push(self.end.clone());
        for p in toks.windows(2) {
            self.map[p[0]].add(p[1].clone()); // *** does not compile
        }
        self
    }
    // ...
}

impl<T: Eq + Hash> States<T> for HashMap<Rc<T>, uint> {
    fn add(&mut self, token: Rc<T>) {
        match self.entry(token) {
            Occupied(mut e) => *e.get_mut() += 1,
            Vacant(e) => { e.set(1); },
        }
    }
    // ...
}

If more context is needed, the full code can be seen here.

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