Lifetime tracking

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 2 17:31:31 PDT 2016


On 6/2/2016 4:29 PM, Timon Gehr wrote:
> // need to know that lifetime of a ends not after lifetime of b
> void assign(S,T)(ref S a, T b){ a = b; }
>
> void foo(scope int* k){
>     void bar(){
>         scope int* x;
>         // need to check that lifetime of x ends not after lifetime of k
>         assign(x,k);

It'll fail to compile because T is not annotated with 'scope'. Annotating T with 
scope will then fail to compile because the assignment to 'a' may outlive 'b'.

>     }
> }


 > Note that it is tempting to come up with ad-hoc solutions that make some 
small finite set of examples work.

If they cover the cases that matter, it's good. Rust has the type system 
annotations you want, but Rust has a reputation for being difficult to write 
code for.


More information about the Digitalmars-d mailing list