Skip to content

Odd type inference failure: unable to infer enough type information about _ #21635

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
bgamari opened this issue Jan 25, 2015 · 3 comments
Closed

Comments

@bgamari
Copy link
Contributor

bgamari commented Jan 25, 2015

This,

/// A binary tree with nodes labelled with `T`
pub struct Tree<T> {
    pub value: T,
    pub left: Option<Box<Tree<T>>>,
    pub right: Option<Box<Tree<T>>>,
}

impl<T> Tree<T> {
    pub fn map_step<F, V>(self, f: &mut FnMut(T) -> V) -> Tree<V> {
        Tree {
            left: self.left.map(|x| { let a: Tree<V> = x.map_step(f);
                                      Box::new(a) }),
            right: self.right.map(|x| Box::new(x.map_step(f))),
            value: f(self.value),
        }
    }
}

fn main() {}

fails with,

hi.rs:12:58: 12:69 error: unable to infer enough type information about `_`; type annotations required [E0282]
hi.rs:12             left: self.left.map(|x| { let a: Tree<V> = x.map_step(f);
                                                                  ^~~~~~~~~~~

All of my attempts at helping the compiler find the right types have failed, therefore I suspect it's a bug.

@Aatch
Copy link
Contributor

Aatch commented Jan 25, 2015

There isn't enough information for the compiler to infer the type of F in this case, since it's not used anywhere in the function signature.

The message could be more clear though, closing as a duplicate of #19477

@Aatch Aatch closed this as completed Jan 25, 2015
@bgamari
Copy link
Contributor Author

bgamari commented Jan 25, 2015

@Aatch, I'm not sure I follow. The type of f is given explicitly in the signature of map_step.

@bgamari
Copy link
Contributor Author

bgamari commented Jan 25, 2015

Ahh, I missed the F type variable. It was a remnant from refactoring. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants