Skip to content

Borrows of unsafe immubtable static items is permitted on constructors #13005

Closed
@flaper87

Description

@flaper87

This is currently valid and it shouldn't be.

The issue is in borrowck::gather_loans::mod:: specifically in the gather_loans_for_static_initializer function. This should be fixed by implementing a small Visitor that will walk the passed expr and look for cases like the one in the example below:

struct Wrap<T> { value: T }
static UNSAFE: Unsafe<int> = Unsafe{value: 1, marker1: marker::InvariantType};
static WRAPPED_UNSAFE: Wrap<&'static Unsafe<int>> = Wrap { value: &UNSAFE };

fn main() {}

cc @nikomatsakis

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