Skip to content

Function pointers and lifetimes : 2014-07-24 -> 2014-07-26 #16002

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

Closed
artella-coding opened this issue Jul 26, 2014 · 2 comments
Closed

Function pointers and lifetimes : 2014-07-24 -> 2014-07-26 #16002

artella-coding opened this issue Jul 26, 2014 · 2 comments

Comments

@artella-coding
Copy link

In going from rustc 0.12.0-pre-nightly (2224edcfe 2014-07-24 00:26:14 +0000) to rustc 0.12.0-pre-nightly (cf1381c1d 2014-07-26 00:46:16 +0000), a certain symmetry breaking seems to have arisen and I want to check that this is not a bug.

The following code works in both nighty :

static myval: int = 5;

struct cls<'a>{
  z: &'a int
}

fn create<'r>() -> cls<'r> {
  cls { z : & myval }
}

fn main(){}

However the following code, which is a "functionised" version of the above example, fails in the 2014-07-26 nightly but not in the 2014-07-24 nightly.

fn retn() -> int{ return 5; }

struct cls<'a>{
  fz: &'a fn() -> int
}
/*
error: borrowed value does not live long enough
       cls { fz : & retn }
                    ^~~~
*/
fn create<'r>() -> cls<'r> {
  cls { fz : & retn }
}

fn main(){}

I don't understand why the latter should not work, since if I am not mistaken, the scope of the function fn retn() is the same as the scope of static myval: int. Thanks

@bluss
Copy link
Member

bluss commented Jul 26, 2014

It changed in #15961. You should be able to just use the fn() -> int type which is already a copyable function pointer.

@artella-coding
Copy link
Author

@blake2-ppc Ah Patrick's post explains that the above is a breaking change. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants