Skip to content

Inference weirdness with a closure #20558

Closed

Description

Sorry this is a vague bug report and a crap example, it comes from trans_struct in expr.rs, the following fails:

let mut need_base: Vec<_> = repeat(true).take(field_tys.len()).collect();

        let numbered_fields = fields.iter().map(|field| {
            let opt_pos =
                field_tys.iter().position(|field_ty|
                                          field_ty.name == field.ident.node.name);
            let result = match opt_pos {
                Some(i) => {
                    need_base[i] = false;
                    (i, &*field.expr)
                }
                None => {
                    tcx.sess.span_bug(field.span,
                                      "Couldn't find field in struct type")
                }
            };
            result
        }).collect::<Vec<_>>();

Changing Vec<_> to Vec<bool> makes it compile.

The error message is unable to infer enough type information about "closure[/home/ncameron/rust3/src/librustc_trans/trans/expr.rs:1390:74: 1405:10]; type annotations required".

The reason I think this is a bug and not just annoying is that it is so obvious that the parameter is bool.

cc @nikomatsakis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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