3 ms·
> And does the compiler no longer complain about code that really should work just fine? In the general case that's theoretically impossible, and also not real
by couchand 8y ago
> And does the compiler no longer complain about code that really should work just fine?
In the general case that's theoretically impossible, and also not really a good measure anyway.
- mehrdadn 8y agoOkay, how about in the practical cases that actually come up and make you have to work around the compiler?
- Sharlin 8y agoNon-lexical lifetimes, which were just recently stabilized [1], make many of the most common cases of borrow checker frustration "just work". And now that the groundwork is done, even more cases will likely be supported in the future. [1] 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/...
- mehrdadn 8y agoConfused, how are these common use cases, and how is this "just working"? In both examples on that page there is an unused variable (seems rare to do intentionally?) and in the second case where one of them is used, it seems they just elaborated the error message.
- staticassertion 8y agoA common use case might be something along these lines: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7929c7ee98bf530888173d51a71f96a1 https://play.rust-lang.org/?version=stable&mode=debug&editio... While the `entry` API provided an ergonomic, more performant way to do this, this is an example of a common pattern one might expect from other languages that, until recently, did not compile. NLL and other ergonomics improvements have helped a lot with these paper-cuts.
- chrismorgan 8y agoIncidentally: for what that whole `match` block could be with the entry API: *example_map.entry("some_key").or_insert(0) += 1; Or, if you prefer an extra intermediate for clarity: let entry = example_map.entry("some_key").or_insert(0); *entry += 1; This is a good example of how, often, Rust’s approach of having greater underlying complexity but exposing it sanely ends up allowing you to write something that is semantically superior and easier to reason about, while being faster too. This and Rust’s ownership model (which I declare stands under the same banner) is the sort of thing that I regularly miss when working in JavaScript (and regularly missed when I used to work in Python plenty).