Skip to content

Unable to infer type information despite enough context. #19853

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
aatxe opened this issue Dec 15, 2014 · 1 comment
Closed

Unable to infer type information despite enough context. #19853

aatxe opened this issue Dec 15, 2014 · 1 comment
Labels
A-type-system Area: Type system

Comments

@aatxe
Copy link
Member

aatxe commented Dec 15, 2014

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.

@aatxe
Copy link
Member Author

aatxe commented Apr 24, 2015

This disappeared at some point along the road.

lnicola pushed a commit to lnicola/rust that referenced this issue May 26, 2025
lnicola pushed a commit to lnicola/rust that referenced this issue May 28, 2025
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

2 participants