Skip to content

Type inference issue when destructuring a struct #8783

@sfackler

Description

@sfackler

The program

extern mod extra;

use extra::url::Url;

fn main() {
    let Url { host, port, _ } = FromStr::from_str("localhost:1234").unwrap();
}

fails to compile with the following error message:

test.rs:6:5: 6:26 error: the type of this value must be known in this context
test.rs:6   let Url { host, port, _ } = FromStr::from_str("localhost:1234").unwrap();
                ^~~~~~~~~~~~~~~~~~~~~
test.rs:6:29: 6:46 error: failed to find an implementation of trait std::from_str::FromStr for [type error]
test.rs:6   let Url { host, port, _ } = FromStr::from_str("localhost:1234").unwrap();
                                        ^~~~~~~~~~~~~~~~~

even though the compiler should be able to infer that it's looking for the FromStr implementation for Url.

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