Borrow error resolved with new variable not fixed by NLL?

How come this builds:

let len = file.read(&mut buf)?;
let curslice = &buf[..len];

play

But this doesn't?

let curslice = &buf[..file.read(&mut buf)?];

play

I mean, sure, I get that the mutable borrow is held for the entire duration of the statement so the immutable borrow can't happen, but... the mutable borrow clearly isn't needed anymore so why not just end its lifetime before the immutable starts? I thought Non-Lexical Lifetimes was implemented to fix things like that. What gives?

This is basically the same as this, but with the borrow types flipped

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.