Skip to content

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

Closed
@artella-coding

Description

@artella-coding

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions