Skip to content

Using impl Trait with closure local functions across crates results in ICE #43135

Closed
@Nemo157

Description

@Nemo157

Having an impl Trait type, containing a closure, where the closure has a locally defined function inside it, being passed across crate boundaries, results in an ICE.

The following function, defined in one crate, then used in another:

pub fn foo2() -> impl Future<Item=String, Error=()> {
    future::ok(()).and_then(|()| {
        fn msg() -> String { format!("Hello, {}!", "world") }
        future::ok(msg())
    })
}

gives the error:

error: internal compiler error: src/librustc_trans/collector.rs:662: Cannot create local trans-item for DefId { krate: CrateNum(12), node: DefIndex(9) => bar/ab23142::foo2[0]::{{closure}}[0]::msg[0] }

note: rustc 1.20.0-nightly (9b85e1cfa 2017-07-07) running on x86_64-apple-darwin

Presumably related to #40839/#35870, I found this while trying to come up with a decent workaround for #40839 specifically.

I have pushed a full testcase to https://github.com/Nemo157/impl-trait-across-crates, try building the foo2 crate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions