Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

'static reference to local variable that never goes out of scope? #565

Copy link
Copy link
@joshlf

Description

@joshlf
Issue body actions

Is the following sound? In particular, is it sound to synthesize a 'static reference to a local variable if we can prove that that variable will never go out of scope at runtime because the local scope will never finish executing?

fn with_static<T: 'static, F: FnOnce(&'static T)>(t: T, f: F) {
    let tp: *const T = &t;
    // SAFETY: The `loop {}` below ensures that `t` never goes
    // out of scope.
    let tr: &'static T = unsafe { &*tp };
    f(tr);
    loop {}
    drop(t)
}

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.