3 ms·
Currently, borrows are lexical. We don't want them to be that way forever. https://github.com/rust-lang/rust/issues/6393 https://github.com/rust-lang/rust/issue
by steveklabnik 12y ago
Currently, borrows are lexical. We don't want them to be that way forever. https://github.com/rust-lang/rust/issues/6393 https://github.com/rust-lang/rust/issues/6393
- wycats 12y agoTo be more specific, automatic dropping will likely always be scope-based. In the rare case where you need to drop something before its owning scope completes, you can explicitly use `drop` as people have said downstream. Borrows are a different story. Especially with mutable borrows (which are basically a static lock on the value), the current lexical restriction is too coarse-grained. There are always workarounds, but it will be nice when it's fixed :)
- rcthompson 12y agoIs there a specific reason for automatic dropping to be scope-based? Is it because dropping things could have side effects (e.g. closing a filehandle) and scope-based dropping makes it easy for someone looking at the code to determine when these side effects will occur?