Skip to content

Recent regression in diagnostics ("trait Sized must be implemented" error message) #18040

Description

@japaric

(Sorry for the poor title, feel free to change it)

STR

use std::collections::HashMap;

fn main() {
    let arr = [(1i, 1u), (2, 2), (3, 3)];

    let m: HashMap<_, _> = arr.iter().collect();
    //                               ^~ forgot `.map(|&x| x)`
}

Error message

collect.rs:6:12: 6:25 error: unable to infer enough type information to locate the impl of the trait `core::kinds::Sized` for the type `<generic #2>`; type annotations required
collect.rs:6     let m: HashMap<_, _> = arr.iter().collect();
                        ^~~~~~~~~~~~~
collect.rs:6:12: 6:25 note: the trait `core::kinds::Sized` must be implemented because it is required by `std::collections::hashmap::map::HashMap`
collect.rs:6     let m: HashMap<_, _> = arr.iter().collect();
                        ^~~~~~~~~~~~~
error: aborting due to previous error

Compare it with the error reported with Rust 0.12:

<anon>:6:28: 6:48 error: type mismatch: the type `std::collections::hashmap::map::HashMap<<generic #2>,<generic #3>>` implements the trait `core::iter::FromIterator<(<generic #220>,<generic #221>)>`, but the trait `core::iter::FromIterator<&(int,uint)>` is required (expected &-ptr, found tuple)
<anon>:6     let m: HashMap<_, _> = arr.iter().collect();
                                    ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

Much better!

Version

rustc 0.13.0-dev (a1e2eb039 2014-10-14 04:02:48 +0000)

I thought this was the same as #17567, but the confusing error on #17567 also occurs with 0.12, which means that the issue reported here has been introduced more recently.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions