News for hackers. Stuff that matters.
Re:John Carmack: writing Rust code feels wholesome by manaskarekar on Sunday February 10, 2019 @08:51AM (#19127743)
>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....

NLL are a part of Rust 2018 Edition.

Three complementary books are the best resources:

- The Official book: https://doc.rust-lang.org/book/

- The Rust By Example book : https://doc.rust-lang.org/rust-by-example/

- Programming Rust (O'Reilly) : https://www.amazon.com/Programming-Rust-Fast-Systems-Develop...

Re:John Carmack: writing Rust code feels wholesome by pjmlp on Sunday February 10, 2019 @11:38AM (#19128442)
NLL still doesn't cover all use cases, for example common GUI patterns with callbacks having references to internal fields.
Re:John Carmack: writing Rust code feels wholesome by est31 on Sunday February 10, 2019 @09:49AM (#19127947)
NLL 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.

Re:John Carmack: writing Rust code feels wholesome by burntsushi on Sunday February 10, 2019 @09:56AM (#19127981)
> 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&editio...

See: https://rust-lang-nursery.github.io/edition-guide/rust-2018/...

Re:John Carmack: writing Rust code feels wholesome by est31 on Sunday February 10, 2019 @10:11AM (#19128051)
Oh 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
Re:John Carmack: writing Rust code feels wholesome by TheCoelacanth on Sunday February 10, 2019 @12:26PM (#19128754)
The 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

Re:John Carmack: writing Rust code feels wholesome by steveklabnik on Sunday February 10, 2019 @09:58AM (#19127989)
This is incorrect. NLL is on for Rust 2018 code.

The transition mode is for Rust 2015 code.

Re:John Carmack: writing Rust code feels wholesome by est31 on Sunday February 10, 2019 @10:07AM (#19128035)
Please see the code: 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

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.