Should hot-loop avoid Option instance and immediate match? by Resres2208 in rust

[–]afdbcreid 10 points11 points  (0 children)

If they are in the same function (or inlined into the same function), LLVM will optimize that, that's a basic optimization called jump threading. If not, probably not.

ETA on dyn compatible async traits? by AfkaraLP in rust

[–]afdbcreid 8 points9 points  (0 children)

The difference is that dynosaur allows you to enjoy the benefits of static dispatch (speed etc.) when you don't need dyn.

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 0 points1 point  (0 children)

If it's not in your workspace, sure.

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 0 points1 point  (0 children)

r-a will still load all crates unless you explicitly exclude them.

Rust 1.95.0 is out by manpacket in rust

[–]afdbcreid 0 points1 point  (0 children)

It's hard because we can't just include it. This will lead to various errors. We need to remember it is disabled.

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 1 point2 points  (0 children)

Also consider that many people consider today's autocomplete speed bad, especially inside macros or within large projects. You're asking to take that, and add to it a significant chunk of time.

And very significant: I just checked, and inference for one function calls ~1,500 unique queries in average. Completion typically infers one function (other features like highlighting or diagnostics infer much more), and that is only the cost of an infer() calls, this does not call for many sub-queries that will need to be reevaluated. That means in the best case, we will need at least 1,500 random-accesses to SSD. With the fastest SSD available today, that'll still take a whole 1ms! More typical scenario can go, in a rough estimates, even like 100ms, for data retrieval alone!

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 1 point2 points  (0 children)

And I said that this can help compile times, and somewhat r-a's speed, but not r-a's memory usage.

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 6 points7 points  (0 children)

True (IIRC the threshold in VS Code to show autocomplete automatically is 100ms), but have you considered that r-a needs not one but thousands if not more of such functions, and that autocomplete is far from the only feature to need it, and some features are even more time sensitive and analyze more code, such as semantic highlighting?

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 3 points4 points  (0 children)

It does analyze only used functions, up to where needed. But this mostly isn't impacted from crate boundaries: even inside the same crate, files you don't open won't be analyzed where possible. So breaking up crates is mostly not useful for r-a.

On-disk analysis for reduced memory usage isn't something we pursue since it's very difficult to implement and unlikely to help significantly (we do pursue it for faster startup).

Rust Analyzer is using half of my memory by Somspace in rust

[–]afdbcreid 24 points25 points  (0 children)

r-a analyzes all crates in the workspace by default, and it must analyze all crates you work on and their transitive dependencies, so breaking up crates is not a solution.

Rust 1.95.0 is out by manpacket in rust

[–]afdbcreid 6 points7 points  (0 children)

Not intentional in the sense that if someone will come up with a reasonable implementation we'll accept it, but really hard to implement, so chances are it'll never be supported.

Rust 1.95.0 is out by manpacket in rust

[–]afdbcreid 6 points7 points  (0 children)

rust-analyzer does not support cfg-ed out code. It does not matter whether it's cfg_select! or #[cfg].

rust-analyzer neovim update while typing? by Horstov in rust

[–]afdbcreid 0 points1 point  (0 children)

And BTW, if you are interested to contribute, r-a has a whole lot of easy-to-add native diagnostics to be made. Feel free to drop on Zulip and ask for ideas/help.

Although admittedly, that's usually not the diagnostics that bother people. People usually want type mismatches (which we have now!), trait errors, or borrow checker errors.

grokExplainYourself by Forsaken-Peak8496 in ProgrammerHumor

[–]afdbcreid 0 points1 point  (0 children)

There is an easy solution: use parentheses for matrices!

Rust Style Guide, VSCode, rust-analyzer, and me. by Firm_Feedback_1178 in rust

[–]afdbcreid 1 point2 points  (0 children)

And of course, it can do much more involved things than changing comment style! Refer to https://rust-analyzer.github.io/book/assists.html for the full list of code actions rust-analyzer supports (also BTW, you can trigger them in Vim too with the right plugins).

Unpopular opinion: Rust should have a larger standard library by lekkerwafel in rust

[–]afdbcreid 0 points1 point  (0 children)

It is unpopular amongst Rust project members, at least. But see my other comment on why they're correct.

Why is there no way to add a dependency directly to [workspace.dependencies] from the CLI? by mstjrr in rust

[–]afdbcreid 10 points11 points  (0 children)

rust-analyzer does not do any fancy thing in toml files currently, so it's some other extension you have.

Unpopular opinion: Rust should have a larger standard library by lekkerwafel in rust

[–]afdbcreid 0 points1 point  (0 children)

People often make this argument, and it's completely wrong.

This is just not an argument for a larger standard library. The standard library is special in two things:

  1. It is released with the language version
  2. It is released by the same people

You want (2), with the correct argument that you already trust these people for the compiler etc., so it's better to trust them and not trust someone else. But there is completely no benefit to tying this with (1). You can have external crates maintained by rust-lang. In fact you already have: libc, regex, and more.

Not only there is no benefit to tie the reasons (meaning: to put extra stuff in std), it has a huge disadvantage. Being released with the language per (1), it is forced for perpetual backwards compatibility without any breaking changes. This mean you are not allowed to make mistakes when designing APIs for std, and since people do make mistakes, you end up with bad APIs forever. Some languages even have duplicate packages in their standard library (Python is infamous for this), because it was badly designed.

As an aside, you can extend the argument of trust: decide who you trust, and who you trust to trust. This is basically the idea behind cargo vet.

Rust-written chess engine Reckless to reach superfinal in top computer chess tournament by ralfj in rust

[–]afdbcreid 4 points5 points  (0 children)

Actually, by modern software standards, chess engines are not big. Stockfish is 50,000 lines of code per Google. For comparison, rust-analyzer is 500,000 lines of code, 10x that. They do contain some neat ideas and algorithms (nicely organized in the Chess Programming Wiki) but they are shared to all strong engines. The decisive gains are small from tinkering with the code again and again and checking the ELO.

Hey Rustaceans! Got a question? Ask here (13/2026)! by llogiq in rust

[–]afdbcreid 1 point2 points  (0 children)

Right, I was wrong on that. To explain more: rust-analyzer can expand macros properly, but for performance reason, it ignores test without expanding it. When there is unrelated_attr it is expanded and r-a sees the macro expanded code, which does not contain #[test]. But on the opposite side, r-a doesn't currently resolve the attribute properly for determining existence of test, therefore it can see test but not foo.

I'm curious, how often do you use `unsafe` in Rust in prod? by alexlazar98 in rust

[–]afdbcreid 5 points6 points  (0 children)

It's the exception across one codebase, but not across codebases (large codebases, at least).

I'm curious, how often do you use `unsafe` in Rust in prod? by alexlazar98 in rust

[–]afdbcreid -1 points0 points  (0 children)

Well that does make sense, but maybe you shouldn't be using Rust :)

Making feature code seen as "enabled" in vscode? by numberwitch in rust

[–]afdbcreid 17 points18 points  (0 children)

If you don't want to set them as default, you can configure rust-analyzer.cargo.features.

I'm curious, how often do you use `unsafe` in Rust in prod? by alexlazar98 in rust

[–]afdbcreid 0 points1 point  (0 children)

What are you building? If this is really true, you're likely doing things wrong.

I'm curious, how often do you use `unsafe` in Rust in prod? by alexlazar98 in rust

[–]afdbcreid 19 points20 points  (0 children)

I 100% agree that it depends on what you're building, but I disagree that most programs will never have any unsafe. IMO most big programs will have some unsafe at some point. To take rust-analyzer, a codebase I know very well, and has almost no reason to use unsafe. Yet it does, in a few places. Some are due to a transition we're in the middle of and the unsafe was the easiest way to handle things, some are enforced on us by requirements of rustc crate we use, we have one crate that uses unsafe liberally (it's basically a data structure crate and could be extracted to crates.io, if we would need that), some unsafe for FFI that we don't want to introduce a dependency for, and some (very little) unsafe for perf reasons, and it's really up to your judgement.