Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stevenblenkinsop opened this issue Jan 2, 2013 · 4 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions
Milestone

Comments

@stevenblenkinsop
Copy link

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.

@ghost ghost assigned catamorphism Jan 20, 2013
@catamorphism
Copy link
Contributor

I think this is almost the same as #4500, except with a block instead of a statement. Testing.

@catamorphism
Copy link
Contributor

Oops, blocks are already handled. I take that back.

catamorphism added a commit to catamorphism/rust that referenced this issue Mar 29, 2013
@catamorphism
Copy link
Contributor

Fixed itself. Updated the test case, pending #5617

@catamorphism
Copy link
Contributor

Test case added in bf519da

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

2 participants