[Dlang-internal] DIP1000 discussion and testing: borrowing a range

Walter Bright via Dlang-internal dlang-internal at puremagic.com
Sun Oct 16 12:30:53 PDT 2016


On 10/16/2016 7:02 AM, Dicebot wrote:
>     Owner instance;
>     // must work, lifetime of 'instance' exceeds one of x :
>     scope x = instance.borrow();
>     // must not work, infinite lifetime
>     auto y  = instance.borrow();
> }

> Second error is an existing limitation of @safe code (can't take pointer
> from ref) which seems extremely limiting now that tools to enforce scope
> lifetime come into play.

It works because 'scope' is inferred as a storage class when an expression that 
needs scope is used to initialize a local. y gets a subset of the life of 
instance. Doing such inference makes using -transition=safe far more palatable.

BTW, reducing the examples to their minimums helps a lot.



More information about the Dlang-internal mailing list