Rust Analyzer: Next few years
rust-analyzer.github.io
rust-analyzer.github.io
One question I’ve had for some time: what exactly is the relationship between Ferrous Systems and the Rust core team? The most important part of this article - the call for sponsors - calls out the former, but I would think Mozilla would also be greatly motivated to sponsor this work. (If they haven’t already?)
It's generally thought in the Rust community that the community benefits from diversifying the pool of stakeholders and also commercial players. Rust doesn't want to identify too hard as "Mozilla's language".
Edit: Forgot to mention: There isn't currently any legal body such as "Rust foundation" so it's hard for the Rust project itself financially sponsor this kind of project. It's mostly either Mozilla or then some "third party" player.
http://smallcultfollowing.com/babysteps/blog/2020/01/09/towa...
For me, this (coupled with non-lexical lifetimes and error handling improvements) made the difference between "I can't justify using Rust because I can't be sufficiently productive" and "the productivity hit is sufficiently small that it makes good sense to use Rust for some of the applications I write, especially factoring in its rate of improvement".
I imagine that it's evolving quite quickly, and it's also the sort of thing where it's probably both fun and fine to stay close to the bleeding edge. Should I just periodically download the latest released binary, or is it worth building from master?
My other goals for 2030:
- RISC-V ubiquity
- RedoxOS on all major archs
- Linux kernel maintenance shifting to at least 25% Rust code
Rust Analyzer is one of the biggest pieces that I think will get us there as far as compile times and beating out C++ ubiquity that is already in this space.
Did I mess this up?
The rust-analyzer docs show how to wire it up to VIM a few different ways: https://rust-analyzer.github.io/manual.html#installation
You both should file bugs!
I can't speak to your experiences obviously, but based on mine I would recommend that anyone on VSCode gives it a shot immediately.
Also compared to RLS it works much better on code with errors in, at least in my experience.
(1) cargo on the command line
(2) sublime text
(3) Rust analyzer
So the "move from" didn't really make sense to me. You wouldn't stop using cargo (rust's package manager) to use rust analyzer (a code analysis / code completion tool).
In addition, this provides type annotations inline and other IDE features like go-to-definition and find-usages.
If you’re using Sublime Text 3, it’s essentially an alternative to RustEnhanced[0].
Source: me, a contributor to both RustEnhanced and Sublime-LSP
Out of interest, is there a page anywhere explaining the difference between RustEnhanced and Sublime-LSP + Rust Analyzer? I’ve got both installed, but when I enable Sublime-LSP + RustAnalyzer the experience and functionality is different enough that I assumed it was overriding RustEnhanced.
Rant: In my ideal world editors would allow me to write a plugin that mimics the current cli output fairly close, with overlays and tooltips fully controlled by the plugin. Imagine clicking on the red squiggles and a pop-up with the cli output, but with syntax highlighting, editable and click to go to line.
If you look at the structured suggestions that rustc gives, the message succinctly explains what concept you're changing, giving you some keywords that you can Google for, and the transformed code allowing you to continue without having to consider the implications necessarily. You can't get that immediacy from a book.
For example, the following code
fn foo() -> Iterator {
vec![1, 2, 3].into_iter()
}
will tell you that Iterator is a trait (so you should use the appropriate style and mark it with dyn to make it clear) and that it has an associated type that must be specified (showing you the syntax you'd need) warning: trait objects without an explicit `dyn` are deprecated
--> src/main.rs:1:13
|
1 | fn foo() -> Iterator {
| ^^^^^^^^ help: use `dyn`: `dyn Iterator`
|
= note: `#[warn(bare_trait_objects)]` on by default
error[E0191]: the value of the associated type `Item` (from trait `std::iter::Iterator`) must be specified
--> src/main.rs:1:13
|
1 | fn foo() -> Iterator {
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
If you follow it's advice fn foo() -> dyn Iterator<Item = i32> {
vec![1, 2, 3].into_iter()
}
Then it will tell you that you cannot ever return a trait directly, because its unsized (?Sized), but the compiler peeks at the function body and checks which of the 3 solutions could apply. In this case, it introduces you to the impl Trait feature (opaque type that implements a given trait): error[E0746]: return type cannot have an unboxed trait object
--> src/main.rs:1:13
|
1 | fn foo() -> dyn Iterator<Item = usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
help: use `impl Iterator<Item = usize>` as the return type, as all return paths are of type `std::vec::IntoIter<{integer}>`, which implements `Iterator<Item = usize>`
|
1 | fn foo() -> impl Iterator<Item = usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
But if the implementation were different it would show you how to use boxed trait objects: error[E0746]: return type cannot have an unboxed trait object
--> src/main.rs:1:13
|
1 | fn foo() -> dyn Iterator<Item = usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
= note: if all the returned values were of the same type you could use `impl Iterator<Item = usize>` as the return type
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
= note: you can create a new `enum` with a variant for each returned type
help: return a boxed trait object instead
|
1 | fn foo() -> Box<dyn Iterator<Item = usize>> {
2 | if true {
3 | Box::new(vec![1, 2, 3].into_iter())
4 | } else {
5 | Box::new(None.into_iter())
This is not perfect, as it is a complex topic and its done in the cli output, but there's no reason that having this level of interactive learning in rust-analyzer wouldn't be a net positive.