3 ms·
> 2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will jus
by celeritascelery 5y ago
> 2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will just correctly Panic, so it's not wonderful. But that is the point of RefCell.
That’s not the interesting part. The point is that rust won’t optimize a lifetime inside a struct the same way it will optimize an actual reference. It can’t assume that the lifetime will be valid for the whole function (as it can with ref). This limits the amount of reordering you can do in the optimizer.
The example you were looking at was explaining why that is the case.
- gridspy 5y agoOkay, thanks for clarifying that. Ultimately I'm happy for Rust to only be so smart, of course there are going to be limitations. But you are right, the author was making a clear example and my comment doesn't make sense in that context.
- spoiler 5y agoIsn't this (at least in part) addressed by NLLs[1], or am I misunderstanding? [1]: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md https://github.com/rust-lang/rfcs/blob/master/text/2094-nll....