Skip to content

lifetime cannot outlive unknown scope. Please report a bug... #4335

Closed
@stevenblenkinsop

Description

@stevenblenkinsop

This code fails to compile:

fn id<T>(t: T) -> T { t }

fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }

fn main() {
    let v = &5;
    io::println(fmt!("%d", f(v)()));
}

With error:

test.rs:3:49: 3:55 error: cannot infer an appropriate lifetime due to conflicting requirements
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
                                                       ^~~~~~
note: first, the lifetime cannot outlive unknown scope: 44.  Please report a bug....
test.rs:3:54: 3:55 note: ...due to the following expression
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
                                                            ^
test.rs:3:31: 3:58 note: but, the lifetime must be valid for the lifetime &r as defined on the block
at 3:31...
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:3:49: 3:55 note: ...due to the following expression
test.rs:3 fn f<T>(v: &r/T) -> &r/fn()->T { id::<&r/fn()->T>(|| *v) }
                                                       ^~~~~~
error: aborting due to previous error

I was trying to return a closure containing a borrowed pointer. id is there so that the closure isn't inferred as an @fn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions