Skip to content

Trouble passing closures with borrowed pointers inside options #10846

Closed
@SiegeLord

Description

@SiegeLord

rustc 0.9-pre (aa4455e 2013-12-06 01:11:18 -0800)

Consider this code and errors:

fn main()
{
    fn test1(x: Option<|y: &int|>) {}

    test1(Some(|y| {}));
    test1(Some(|y: &int| {}));

    fn test2(x: Option<|y: Option<|z: &int|>|>) {}

    test2(Some(|y| {}));
    test2(Some(|y: Option<|z: &int|>| {}));
}
test.rs:7:7: 7:20 error: mismatched types: expected `std::option::Option<|&int|>` but found `std::option::Option<|<V1>|>` (expected concrete lifetime, but found bound lifetime parameter &)
test.rs:7       test1(Some(|y| {}));
                      ^~~~~~~~~~~~~
note: expected concrete lifetime is lifetime ReInfer(ReSkolemized(0u, BrAnon(0u)))
test.rs:10:7: 10:20 error: mismatched types: expected `std::option::Option<|std::option::Option<|&int|>|>` but found `std::option::Option<|<V8>|>` (expected concrete lifetime, but found bound lifetime parameter &)
test.rs:10      test2(Some(|y| {}));
                      ^~~~~~~~~~~~~
note: expected concrete lifetime is lifetime ReInfer(ReSkolemized(5u, BrAnon(0u)))
task 'rustc' failed at 'assertion failed: !r0.is_bound()', /home/siege/src/rust2/src/librustc/middle/typeck/infer/lub.rs:157
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: https://github.com/mozilla/rust/wiki/HOWTO-submit-a-Rust-bug-report
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task '<main>' failed at 'explicit failure', /home/siege/src/rust2/src/librustc/lib.rs:390

As you can see, in case of test1, it has trouble inferring the type of the closure parameter, but if you specify it manually it works. In the case of test2 specifying it manually crashes the compiler outright. Note that both cases work just fine if you remove all the Options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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