<p dir="auto">On 3/4/2015 on playpen, the following code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo {
    type A;
}

struct FooStruct;

impl Foo for FooStruct {
    type A = &lt;FooStruct as Foo&gt;::A;
}

fn main() { }"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">type</span> <span class="pl-smi">A</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">FooStruct</span><span class="pl-kos">;</span>

<span class="pl-k">impl</span> <span class="pl-smi">Foo</span> <span class="pl-k">for</span> <span class="pl-smi">FooStruct</span> <span class="pl-kos">{</span>
    <span class="pl-k">type</span> <span class="pl-smi">A</span> = &lt;<span class="pl-smi">FooStruct</span> <span class="pl-k">as</span> <span class="pl-smi">Foo</span>&gt;<span class="pl-kos">::</span><span class="pl-smi">A</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">...gives the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'rustc' has overflowed its stack
Illegal instruction (core dumped)
playpen: application terminated with error code 132"><pre class="notranslate"><code class="notranslate">thread 'rustc' has overflowed its stack
Illegal instruction (core dumped)
playpen: application terminated with error code 132
</code></pre></div>
<p dir="auto">This may be considered a duplicate of issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="53358617" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/20551" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/20551/hovercard" href="https://github.com/rust-lang/rust/issues/20551">#20551</a>, which notes a similar problem with recursive trait bounds.  I figured this may be unique given that this involves a recursive associated type on a trait, rather than a recursive trait itself.</p>
<p dir="auto">This works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn main() {
    let mut nums=vec![10i,11,12,13];
    let index=nums.len()-2;
    *nums.get_mut(index)=2;
}"><pre class="notranslate"><code class="notranslate">fn main() {
    let mut nums=vec![10i,11,12,13];
    let index=nums.len()-2;
    *nums.get_mut(index)=2;
}
</code></pre></div>
<p dir="auto">I would like to be able to write this instead:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn main() {
    let mut nums=vec![10i,11,12,13];
    *nums.get_mut(nums.len()-2)=2;
}"><pre class="notranslate"><code class="notranslate">fn main() {
    let mut nums=vec![10i,11,12,13];
    *nums.get_mut(nums.len()-2)=2;
}
</code></pre></div>
<p dir="auto">But:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="test.rs:3:16: 3:20 error: cannot borrow `nums` as immutable because it is also borrowed as mutable
test.rs:3   *nums.get_mut(nums.len()-2)=2;
                          ^~~~
test.rs:3:3: 3:7 note: previous borrow of `nums` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `nums` until the borrow ends
test.rs:3   *nums.get_mut(nums.len()-2)=2;
             ^~~~"><pre class="notranslate"><code class="notranslate">test.rs:3:16: 3:20 error: cannot borrow `nums` as immutable because it is also borrowed as mutable
test.rs:3   *nums.get_mut(nums.len()-2)=2;
                          ^~~~
test.rs:3:3: 3:7 note: previous borrow of `nums` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `nums` until the borrow ends
test.rs:3   *nums.get_mut(nums.len()-2)=2;
             ^~~~
</code></pre></div>
<p dir="auto">Lexically, the receivers appears before the parameters, but semantically it appears later, which is when I'd expect the borrow to happen.</p>