From 38d36992a116706cd854728cf3a7855bb983717c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 5 Oct 2017 00:22:33 -0700 Subject: [PATCH] Handle borrows of unions in NLL --- text/2094-nll.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/text/2094-nll.md b/text/2094-nll.md index c950be696b5..a01976e095d 100644 --- a/text/2094-nll.md +++ b/text/2094-nll.md @@ -1694,6 +1694,16 @@ if they meet one of the following criteria: - so: writing a path like `a` is illegal if `a.b` is borrowed - but: writing `a` is legal if `*a` is borrowed, whether or not `a` is a shared or mutable reference +- the loan path has a **shallow prefix** `.` that accesses a + field of a union, and `lvalue` has a prefix of the form `.` + for a _different_ field of the same base union. + - so: if `s.u` is a union with distinct fields `a` and `b`, shallowly + accessing a path `s.u.a.x` is illegal if `s.u.b` or `s.u.b.y` is borrowed. + In here, `` is `s.u`, `` is `b` and `` is `a`. + - but: unless `s.u.a` is _also_ a union, the access `s.u.a.x` is _legal_ + if `s.u.a.z` is borrowed, because the same union field is used in both borrows. + - the prefix of `lvalue` can be an arbitrary prefix - if `s.u.b.w` is borrowed, + then it is illegal to shallowly access `*(*s.u.a.z).t` For **deep** accesses to the path `lvalue`, we consider borrows relevant if they meet one of the following criteria: @@ -1707,6 +1717,14 @@ if they meet one of the following criteria: - so: reading a path like `a` is illegal if `a.b` is mutably borrowed, but -- in contrast with shallow accesses -- reading `a` is also illegal if `*a` is mutably borrowed +- the loan path has a **supporting prefix** `.` that accesses a + field of a union, and `lvalue` has a prefix of the form `.` for + a _different_ field with the same base union. + - so: if `s.u` is a union with distinct fields `a` and `b`, deeply accessing + a path `s.u.a.x` is illegal if `s.u.b`, `s.u.b.w`, or (in contrast with + shallow accesses, and as long as both dereferences are of the form `&mut T`) + `*(*s.u.b.w).t` is borrowed. In here, `` is `s.u`, `` is `b`, + and `` is `a`. **Dropping an lvalue LV.** Dropping an lvalue can be treated as a DEEP WRITE, like a move, but this is overly conservative. The rules here