Skip to content

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

Closed
@bgamari

Description

@bgamari

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions