Skip to content

Order of code affects lifetime resolution #23108

Closed
@chlai88

Description

@chlai88

This playpen code snippet now fails in compile : playpen

with error

<anon>:23:26: 23:46 error: `long_enough_lifetime` does not live long enough
<anon>:23         handle.set_data(&long_enough_lifetime); // This is OK
                                 ^~~~~~~~~~~~~~~~~~~~
<anon>:17:34: 27:2 note: reference must be valid for the block suffix following statement 0 at 17:33...

But if you just swap the following 2 lines, line 17 with line 18, it compiles fine.

let long_enough_lifetime = DropCanary{label:"long"};
let mut handle = Handle(None);

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