4 ms·
>the borrowing/ownership semantics of rust (at the time I looked at it) felt needlessly over complicated. Taking a wild guess here, but it sounds like you mayb
by manaskarekar 8y ago
>the borrowing/ownership semantics of rust (at the time I looked at it) felt needlessly over complicated.
Taking a wild guess here, but it sounds like you maybe referring to issues addressed by Non-Lexical Lifetimes (NLL)?
Reference: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md https://github.com/rust-lang/rfcs/blob/master/text/2094-nll....
NLL are a part of Rust 2018 Edition.
Three complementary books are the best resources:
- The Official book: https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/
- The Rust By Example book : https://doc.rust-lang.org/rust-by-example/ https://doc.rust-lang.org/rust-by-example/
- Programming Rust (O'Reilly) : https://www.amazon.com/Programming-Rust-Fast-Systems-Development/dp/1491927283 https://www.amazon.com/Programming-Rust-Fast-Systems-Develop...
- est31 8y agoNLL only modes aren't available on stable Rust atm. What edition 2018 has right now is migrate mode NLL. In order to fully enjoy NLL, you'll have to use Rust nightly and do #![feature(nll)] or -Z borrowck=mir -Z two-phase-borrows, both flags being independent of the edition you're using. Edit: removed outdated behaviour of migration mode.
- burntsushi 8y ago> What edition 2018 has right now is migrate mode NLL which emits an error if either NLL borrowck or AST borrowck think there is an issue with your code. If that were true, then this example would fail to compile, since it fails with the old AST borrowck: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=66e745314774b90573159d2f2c2c4850 https://play.rust-lang.org/?version=stable&mode=debug&editio... See: https://rust-lang-nursery.github.io/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html https://rust-lang-nursery.github.io/edition-guide/rust-2018/...
- est31 8y agoOh right, seems it got a bit more tolerant. The mode's still called migration mode though, full NLL is to be unleashed later on: https://github.com/rust-lang/rust/issues/57895 https://github.com/rust-lang/rust/issues/57895
- steveklabnik 8y agoThis is incorrect. NLL is on for Rust 2018 code. The transition mode is for Rust 2015 code.
- est31 8y agoPlease see the code: https://github.com/rust-lang/rust/blob/68650cacf23c60ee2f346b27bcefa7c6c31de1e4/src/librustc/ty/context.rs#L1532-L1575 https://github.com/rust-lang/rust/blob/68650cacf23c60ee2f346... In edition 2018, migration mode is turned on. I learned myself about this today btw, after I saw this PR: https://github.com/rust-lang/rust/pull/58342 https://github.com/rust-lang/rust/pull/58342 I think I was mistaken about one point though which is that migration mode is erroring if one of the two errors. IIRC migration mode was introduced that way but it seems to have been changed to be a bit more tolerant than AST borrowck. Anyways, more NLL fun is to come, and it's to come to both editions.
- TheCoelacanth 8y agoThe only difference between migration mode and NLL-only mode is that errors produced by the NLL checker are downgraded to warnings if the old borrow checker doesn't produce any errors on that code[1]. This is strictly more permissive than NLL-only and completely equivalent if you treat warnings as errors. You can completely take advantage of any NLL feature, you just might be able to write code that should be an error but is instead a warning if you hit an edge case (I think this would be considered a bug in one of the borrow checkers since NLL is supposed to allow anything that the old borrow checker allows). [1] https://github.com/rust-lang/rust/issues/46908 https://github.com/rust-lang/rust/issues/46908
- pjmlp 8y agoNLL still doesn't cover all use cases, for example common GUI patterns with callbacks having references to internal fields.