Conceptually, using a *message* here is wrong, because this is a
"status", rather than "point in time" thing. But statuses are an LSP
extension, while messages are stable. As a compromise, send message only
for more critical `metadata` failures, and only once per state change.
This condition should always be true for *valid* code, but of course
there might be invalid code or things that we can't currently resolve.
Fixes#8464.
8463: Support macros in pattern position r=jonas-schievink a=jonas-schievink
This was fairly easy, because patterns are limited to bodies, so almost all changes were inside body lowering.
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
8436: Fix extract function's mutability of variables outliving the body r=matklad a=brandondong
**Reproduction:**
```rust
fn main() {
let mut k = 1;
let mut j = 2;
j += 1;
k += j;
}
```
1. Select the first to third lines of the main function. Use the "Extract into function" code assist.
2. The output is the following which does not compile because the outlived variable `k` is declared as immutable:
```rust
fn main() {
let (k, j) = fun_name();
k += j;
}
fn fun_name() -> (i32, i32) {
let mut k = 1;
let mut j = 2;
j += 1;
(k, j)
}
```
3. We would instead expect the output to be:
```rust
fn main() {
let (mut k, j) = fun_name();
k += j;
}
```
**Fix:**
- Instead of declaring outlived variables as immutable unconditionally, check for any mutable usages outside of the extracted function.
Co-authored-by: Brandon <brandondong604@hotmail.com>
8410: Use CompletionTextEdit::InsertAndReplace if supported by the client r=Veykril a=Veykril
Fixes#8404, Fixes#3130
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
8443: Rewrite `#[derive]` removal code to be based on AST r=jonas-schievink a=jonas-schievink
We now remove any `#[derive]` before and including the one we want to expand, in the `macro_arg` query.
The same infra will be needed by attribute macros (except we only remove the attribute we're expanding, not any preceding ones).
Part of https://github.com/rust-analyzer/rust-analyzer/issues/8434 (doesn't implement the cfg-expansion yet, because that's more difficult)
8446: Undo path resolution hack for extern prelude r=jonas-schievink a=jonas-schievink
Reverts the change made in https://github.com/rust-analyzer/rust-analyzer/pull/7959
We don't populate the extern prelude for block DefMaps anymore,
so this is unnecessary
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
8445: `hir_ty` cleanup r=flodiebold a=flodiebold
Move lots of things around within `hir_ty`. Most notably, all the Chalk-related stuff moves from within `traits/` to the top-level, since Chalk isn't purely a "traits thing" anymore.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
8406: Improve indexing of impls r=flodiebold a=flodiebold
Store impls for e.g. &Foo with the ones for Foo instead of the big "other" bucket. This can improve performance and simplifies the HIR impl search a bit.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Store impls for e.g. &Foo with the ones for Foo instead of the big
"other" bucket. This can improve performance and simplifies the HIR impl
search a bit.
If we get lifetime variables back in autoderef, just immediately replace
them by static lifetimes for now. Method resolution doesn't really deal
correctly with new variables being introduced (this needs to be fixed
more properly).
This fixes `rust-analyzer analysis-stats --with-deps` crashing in the RA
repo.
8429: 8425: Added documentation for on enter covering //! doc comments. r=jonas-schievink a=chetankhilosiya
Also added passing test case.
Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
Fix#8417. Also makes it less noisy about no_mangle annotated stuff the
user can do nothing about.
Note: this still is broken with bitfield! macros. A repro in an ignore
test is included here. I believe this bug is elsewhere, and I don't
think I can work around it here.
8419: Move hir_ty to Chalk IR r=flodiebold a=flodiebold
Closes#8313.
There's some further cleanups to do:
- we're still using our `TypeWalk` in lots of places (not for mutating/folding though, just for walking)
- we're still using our own canonicalization and unification and our `InferenceTable`
- ~`ToChalk` still exists and gets called, it's just the identity in most cases now (I'll probably clean those up before merging this)~
8423: Bump lsp-types and syn r=kjeremy a=kjeremy
This lsp-types now supports a default InsertTextMode for completion and a per-completion item commit_characters
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Co-authored-by: kjeremy <kjeremy@gmail.com>
8408: Update `OUT_DIR` diagnostic to match setting r=jonas-schievink a=jonas-schievink
The setting was renamed, so the diagnostic should follow
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
I'd prefer getting rid of it, but it's used in the impl search and not
super easy to replace there (I think ideally the impl search would do
proper unification, but that's a bit more complicated).
8402: Remove Ty::substs{_mut} r=flodiebold a=flodiebold
Almost all uses actually only care about ADT substs, so it's better to be explicit. The methods were a bad abstraction anyway since they already didn't include the inner types of e.g. `TyKind::Ref` anymore.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Almost all uses actually only care about ADT substs, so it's better to
be explicit. The methods were a bad abstraction anyway since they
already didn't include the inner types of e.g. `TyKind::Ref` anymore.
8397: Return proper error code when server is loading r=matklad a=ceronman
When requests are made to rust-analyzer and the server is still loading, a response error is returned with the code `ContentModified` and text `"Rust Analyzer is still loading..."`. This error code doesn't seem to be the more appropriate for this situation. Using `ServerNotInitialized` seems better.
As this is such a small change, I have not created an issue for it.
Co-authored-by: Manuel Ceron <manuel.ceron@jetbrains.com>
8386: Avoid O(n²) when constructing AttrSourceMap r=jonas-schievink a=jonas-schievink
Brings https://github.com/rust-analyzer/rust-analyzer/issues/8377 down to 2.52s on my machine. Not quite back to where it was before, so I'll leave that issue open for now.
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
8371: Don't use HirDisplayWrapper when displaying SourceCode r=matklad a=Veykril
The issue was basically that when displaying for `DisplayTarget::SourceCode` some `hir_fmt` functions would create `HirDisplayWrapper`s which would then `fmt` these triggering the Display panic since `fmt::Display` can't fail the same way as `HirDisplay`. Simple fix is to just use `hir_fmt` directly. Should probably write that down somewhere in source, looking for a good spot to put that right now.
Fixes#8077, Fixes#8370
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
8375: feat: show errors from `cargo metadata` and initial `cargo check` in the status bar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
8364: Memory usage improvements r=jonas-schievink a=alexmaco
These are mostly focused on splitting up enum variants with large size differences between variants by `Box`-ing things up.
In my testing this reduces the memory usage somewhere in the low percentages, even though the measurements are quite noisy.
Co-authored-by: Alexandru Macovei <alexnmaco@gmail.com>
Rationale: only a minority of variants used almost half the size.
By keeping large members (especially in Option) behind a box
the memory cost is only payed when the large variants are needed.
This reduces the size Vec<Expr> needs to allocate.
8355: internal: do not drop errors from cargo metadata/check r=matklad a=matklad
Work towards #3155
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>