Skip to content

Commit 442225f

Browse files
committed
Updated exclusivity example
1 parent 37381a1 commit 442225f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

docs/P3444R0.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,14 @@ <h2 data-number="1.1" id="exclusivity"><span class="header-section-number">1.1</
584584
the <code class="sourceCode cpp"><span class="op">[</span>safety<span class="op">]</span></code>
585585
feature. We’ve already stumbled on a soundness bug.</p>
586586
<p>Coming from the other direction, it may be necessary to form aliasing
587-
references just to use the APIs for existing code. Consider a function
588-
that takes an lvalue reference to a container and an lvalue reference to
589-
one of its elements. If safe code can’t even form aliased lvalue
590-
references, it wouldn’t be able to use that API at all.</p>
587+
references just to use the APIs for existing code. Consider a call to
588+
<code class="sourceCode cpp">vec<span class="op">.</span>push_back<span class="op">(</span>vec<span class="op">[</span><span class="dv">0</span><span class="op">])</span></code>.
589+
This is <em>impossible to express</em> without mutable aliasing: we form
590+
a mutable lvalue reference to <code class="sourceCode cpp">vec</code>
591+
and a const lvalue reference to one of
592+
<code class="sourceCode cpp">vec</code>’s elements. If safe code can’t
593+
even form aliased lvalue references, it won’t be able to use this API at
594+
all.</p>
591595
<p>Exclusivity is a program-wide invariant on safe references. We need
592596
separate safe and unsafe reference types for both soundness and
593597
expressiveness.</p>

lifetimes/P3444R0.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ With a desire to simplify, you may suggest "rather than adding a new safe refere
8080

8181
If safe code calls legacy code that returns a struct with a pair of references, do those references alias? Of course they may alias, but the parsimonious treatment claims that mutable references don't alias under the `[safety]` feature. We've already stumbled on a soundness bug.
8282

83-
Coming from the other direction, it may be necessary to form aliasing references just to use the APIs for existing code. Consider a function that takes an lvalue reference to a container and an lvalue reference to one of its elements. If safe code can't even form aliased lvalue references, it wouldn't be able to use that API at all.
83+
Coming from the other direction, it may be necessary to form aliasing references just to use the APIs for existing code. Consider a call to `vec.push_back(vec[0])`. This is _impossible to express_ without mutable aliasing: we form a mutable lvalue reference to `vec` and a const lvalue reference to one of `vec`'s elements. If safe code can't even form aliased lvalue references, it won't be able to use this API at all.
8484

8585
Exclusivity is a program-wide invariant on safe references. We need separate safe and unsafe reference types for both soundness and expressiveness.
8686

0 commit comments

Comments
 (0)