On Monday, 12 May 2014 at 00:50:24 UTC, Walter Bright wrote:
On 5/11/2014 1:59 PM, Timon Gehr wrote:
Borrowed pointers are not even superficially similar to near*. They are compatible with everything else, because they can store data that was borrowed
from anywhere else.

As long as those pointers don't escape. Am I right in that one cannot store a borrowed pointer into a global data structure?

Perhaps:

struct Test {
    n: &'static int, // [1]
    m: int
}

static val: int = 123;
static mut t: Test = Test { n: &'static val, m: 0 };

fn main() {
    unsafe { // [2]
        let p = &mut t.m;
        *p = 456;
        println!("{} {}", *t.n, t.m); // prints: 123 456
    }
}

[1]: In order to create a static instance of 'Test', the 'n' field (which is a borrowed pointer) must be specified as to be pointing at a static immutable (int) variable.

[2]: Any use of static mutable data requires the use of an 'unsafe' block (similar to @trusted in D)

Reply via email to