Commit Graph

27750 Commits

Author SHA1 Message Date
Shoyu Vanilla
0f4e313028 Fix goto deref_mut 2024-02-27 23:55:19 +09:00
Shoyu Vanilla
d1bdebf2b9 Add a new failing test for goto deref_mut 2024-02-27 23:54:05 +09:00
bors
6b250a22c4 Auto merge of #16687 - kilpkonn:master, r=Veykril
feat: Add "make tuple" tactic to term search

Follow up to https://github.com/rust-lang/rust-analyzer/pull/16092

Now term search also supports tuples.
```rust
let a: i32 = 1;
let b: f64 = 0.0;
let c: (i32, (f64, i32)) = todo!(); // Finds (a, (b, a))
```
In addition to new tactic that handles tuples I changed how the generics are handled.
Previously it tried all possible options from types we had in scope but now it only tries useful ones that help us directly towards the goal or at least towards calling some other function.
This changes O(2^n) to O(n^2) where n is amount of rounds which in practice allows using types that take generics for multiple rounds (previously limited to 1). Average case that also used to be exponential is now roughly linear.
This means that deeply nested generics also work.
````rust
// Finds all valid combos, including `Some(Some(Some(...)))`
let a: Option<Option<Option<bool>>> = todo!();
````

_Note that although the complexity is smaller allowing more types with generics the search overall slows down considerably. I hope it's fine tho as the autocomplete is disabled by default and for code actions it's not super slow. Might have to tweak the depth hyper parameter tho_

This resulted in a huge increase of results found (benchmarks on `ripgrep` crate):
Before
````
Tail Expr syntactic hits: 149/1692 (8%)
Tail Exprs found: 749/1692 (44%)
Term search avg time: 18ms
```
After
```
Tail Expr syntactic hits: 291/1692 (17%)
Tail Exprs found: 1253/1692 (74%)
Term search avg time: 139ms
````

Most changes are local to term search except some tuple related stuff on `hir::Type`.
2024-02-27 09:41:14 +00:00
bors
d8c5a6128f Auto merge of #16651 - dfireBird:new_assist_fill_fields, r=Veykril
Add assist for filling fields by replacing ellipsis in record syntax

I'm not sure if the tests cover the most cases, I'll add more if suggested.
2024-02-27 09:28:23 +00:00
bors
ea82cc47b9 Auto merge of #16692 - Veykril:methres, r=Veykril
internal: Remove dead branches in `method_resolution::is_valid_candidate`
2024-02-27 09:03:21 +00:00
Lukas Wirth
3a1b4c29b3 internal: Remove dead branches in method_resolutiopn::is_valid_candidate 2024-02-27 10:00:45 +01:00
bors
d4d9d0c85a Auto merge of #16691 - Veykril:completion-analysis-panic, r=Veykril
fix: Fix completions panicking with certain macro setups

Unable to figure out a test case for this but managed to run into it in r-a reproducably.

Fixes https://github.com/rust-lang/rust-analyzer/issues/16266 Fixes https://github.com/rust-lang/rust-analyzer/issues/13255
2024-02-27 08:39:34 +00:00
Lukas Wirth
cc7fe32ba3 fix: Fix completions panicking with certain macro setups 2024-02-27 09:35:57 +01:00
Tavo Annus
a2bf15eede Filter out false positive errors 2024-02-26 20:17:09 +02:00
Tavo Annus
be6f8e2648 Add make_tuple tactic 2024-02-26 20:17:09 +02:00
Tavo Annus
8bd30e9b3f Improve generics handling in term search 2024-02-26 20:17:09 +02:00
bors
5fead606bc Auto merge of #16555 - davidbarsky:david/speedup-completions-by-exploiting-orphan-rules, r=Veykril
performance: Speed up Method Completions By Taking Advantage of Orphan Rules

(Continues https://github.com/rust-lang/rust-analyzer/pull/16498)

This PR speeds up method completions by doing two things without regressing `analysis-stats`[^1]:
- Filter candidate traits prior to calling `iterate_path_candidates` by relying on orphan rules (see below for a slightly more in-depth explanation). When generating completions [on `slog::Logger`](5e9e59c312/common/src/ledger.rs (L78)) in `oxidecomputer/omicron` as a test, this PR halved my completion times—it's now 454ms cold and 281ms warm. Before this PR, it was 808ms cold and 579ms warm.
- Inline some of the method candidate checks into `is_valid_method_candidate` and remove some unnecessary visibility checks. This was suggested by `@Veykril` in [this comment](https://github.com/rust-lang/rust-analyzer/pull/16498#issuecomment-1929864427).

We filter candidate traits by taking advantage of orphan rules. For additional details, I'll rely on `@WaffleLapkin's` explanation  [from Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/420942417):

> A type `A` can only implements traits which
> 1. Have a blanket implementation (`impl<T> Trait for T {}`)
> 2. Have implementation for `A` (`impl Trait for A {}`)
>
> Blanket implementation can only exist in `Trait`'s crate. Implementation for `A` can only exist in `A`'s or `Trait`'s crate.

Big thanks to Waffle for its keen observation!

---

I think some additional improvements are possible:
- `for_trait_and_self_ty` seemingly does not distinguish between `&T`, `&mut T`, or `T`, resulting in seemingly irrelevant traits like `tokio::io::AsyncWrite` being being included for, e.g., `&slog::Logger`. I don't know they're being considered due to the [autoref/autoderef behavior](a02a219773/crates/hir-ty/src/method_resolution.rs (L945-L962)), but I wonder if it'd make sense to filter by mutability earlier and not consider trait implementations that require `&mut T` when we only have a `&T`.
- The method completions [spend a _lot_ of time in unification](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/421072356), and while there might be low-hanging fruit there, it might make more sense to wait for the new trait solver in `rustc`. I dunno.

[^1]: The filtering occurs outside of typechecking, after all.
2024-02-26 18:05:52 +00:00
David Barsky
c246a93046 completions: speed up completions by filtering non-applicable traits 2024-02-26 12:49:11 -05:00
bors
1d3558bfe1 Auto merge of #16684 - Veykril:synthetic-fmt-args, r=Veykril
fix: Don't panic on synthetic syntax in inference diagnostics

Temporary fix for https://github.com/rust-lang/rust-analyzer/issues/16682

We ought to rethink how we attach diagnostics to things, as IDs don't work for `format_args` like that!
2024-02-26 16:47:57 +00:00
Lukas Wirth
3856648b52 fix: Don't panic on synthetic syntax in inference diagnostics 2024-02-26 17:46:03 +01:00
dfireBird
8fa903a447
add test for checking struct generated through macro 2024-02-26 21:32:59 +05:30
dfireBird
2ea70662f0
make assist not applicable if there is no missing field 2024-02-26 21:21:56 +05:30
bors
96505787b4 Auto merge of #16678 - roife:fix-issue-16660, r=lnicola
fix: panic when inlining callsites inside macros' parameters

Close #16660, #12429, #10695.

When `inline_into_callers` encounters callsites in macros parameters, it can lead to panics. Since there is no perfect way to handle macros, this PR directly filters out these cases.
2024-02-26 14:44:22 +00:00
roife
61b576c5ab fix: fmt 2024-02-26 22:36:47 +08:00
bors
f7f63ccd8d Auto merge of #16680 - lnicola:salsa-doc-test, r=Veykril
internal: Remove salsa compile_fail tests

I can't figure out how to reproduce them, but hopefully fixes these:

![image](https://github.com/rust-lang/rust-analyzer/assets/308347/462dbfc3-5414-42fd-b81d-a3d699fa9a8d)
2024-02-26 14:08:38 +00:00
bors
40bf8bf757 Auto merge of #16679 - Veykril:block-mod, r=Veykril
fix: Fix modules in blocks not resolving in ide layer

Fixes https://github.com/rust-lang/rust-analyzer/issues/16511
2024-02-26 13:56:01 +00:00
Lukas Wirth
91554e0ae7 fix: Fix modules in blocks not resolving in ide layer 2024-02-26 14:54:47 +01:00
bors
2251d06200 Auto merge of #16673 - szepeviktor:patch-1, r=lnicola
Narrow down typos ignores

- remove ignored files
- check dotfiles
- reorder config sections: files, regexp, words, IDs
- remove non-existent ignores
2024-02-26 13:41:48 +00:00
Viktor Szépe
18801171b2 Narrow down typos ignores 2024-02-26 13:40:01 +00:00
Laurențiu Nicola
1ef7a9971d Remove salsa compile_fail tests 2024-02-26 15:26:55 +02:00
roife
38a50cf1a4 test: callsites inside inline_into_callers 2024-02-26 20:24:44 +08:00
roife
36298c622e fix:do not handle callsites in macros' parameters 2024-02-26 20:23:36 +08:00
bors
8929853df7 Auto merge of #16647 - Young-Flash:fix_replace_filter_map_next_with_find_map, r=Veykril
fix: replace_filter_map_next_with_find_map shouldn't work for dyn trait

close https://github.com/rust-lang/rust-analyzer/issues/16596
2024-02-26 11:31:44 +00:00
Young-Flash
7a58a23f16 internal: format code 2024-02-26 19:10:50 +08:00
Young-Flash
fd0cddf655 internal: move strip_references into dyn trait check 2024-02-26 18:57:46 +08:00
bors
e1983d2b90 Auto merge of #16669 - ShoyuVanilla:merge-borrow-kind-unique, r=Veykril
Merge `BorrowKind::Unique` into `BorrowKind::Mut`

Resolves #15170
2024-02-26 10:57:42 +00:00
bors
6903a5c7d6 Auto merge of #16665 - MabezDev:prio-rustup-when-searching, r=Veykril
Prioritise rustup sysroots over system ones

`get_path_for_executable` will now first check `$CARGO_HOME` before falling back to searching `$PATH`.

`rustup` is the recommended way to manage rust toolchains, therefore should be picked before the system toolchain.

Closes #16661
2024-02-26 10:45:11 +00:00
bors
4585b461e5 Auto merge of #16670 - rikhuijzer:rh/inlay-hints-nvim, r=Veykril
Document nvim 0.10 `inlay_hint`

It took me a few hours to figure out how to enable inlay type hints on Nvim 0.10 with `lspconfig`. `rustaceanvim` has already dropped support for them (https://github.com/mrcjkb/rustaceanvim/discussions/46#discussioncomment-7518669) and most other plugins, like `rust-tools`, are depreciated in favor of `rustaceanvim`.

This PR documents how to enable the inlay hints on Neovim 0.10 and later. I've tested this and changing the `on_attach` function is the only step that is required.
2024-02-26 10:32:30 +00:00
bors
309e087426 Auto merge of #16627 - Young-Flash:issue_template, r=Veykril
update bug report issue template
2024-02-26 10:18:15 +00:00
Rik Huijzer
4060377c07 Add note 2024-02-25 18:05:52 +01:00
Rik Huijzer
ea837d181e Document nvim 0.10 inlay_hint 2024-02-25 17:59:19 +01:00
Shoyu Vanilla
a336bdc142 Merge BorrowKind::Unique into BorrowKind::Mut 2024-02-26 01:57:03 +09:00
bors
5346002d07 Auto merge of #16668 - lnicola:sync-from-rust, r=lnicola
internal: sync from downstream
2024-02-25 16:29:22 +00:00
Laurențiu Nicola
fb31610ae8 Merge branch 'master' into sync-from-rust 2024-02-25 18:27:30 +02:00
Scott Mabin
9f1d4aa4b9 prioritise rustup sysroots over system ones
`get_path_for_executable` will now first check `$CARGO_HOME` before falling back to searching `$PATH`.

rustup is the recommended way to manage rust toolchains, therefore should be picked before the
system toolchain.
2024-02-24 21:19:10 +00:00
bors
4a8d0f7f56 Auto merge of #16654 - graemer957:feature/short_version_flag, r=lnicola
Add short flag -V for consistency with other rust tooling

Minor change to add the `-V` short flag to `rust-analyzer` to bring it in-line with other rust tooling such as:

> rustc -V
```bash
rustc 1.76.0 (07dca489a 2024-02-04)
```

> rustup -V
```bash
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.76.0 (07dca489a 2024-02-04)`
```

> cargo -V
```bash
cargo 1.76.0 (c84b36747 2024-01-18)
```
2024-02-24 09:51:32 +00:00
Graeme Read
30429f8ece
feat: Add short flag -V for consistency with other rust tooling 2024-02-24 06:45:00 +00:00
dfireBird
6f4354f6ad
add assist for filling fields by replacing ellipsis in record syntax 2024-02-24 11:59:48 +05:30
bors
03b3cb6be9 Auto merge of #16652 - davidbarsky:david/deadlock-fix-for-16643, r=Veykril
internal: fix deadlock introduced by #16643

This fixes a deadlock introduced by #16643 ([backtrace](https://gist.github.com/davidbarsky/00f17598f5496a9c41aff31fec1c42d6)). `maybe_changed_after` calls back into other queries, so the cloning here is unfortunately inevitable.

(Zulip conversation: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Fixing.20proc-macro.20dirtying.20with.20unindexed.20projects)
2024-02-23 20:39:13 +00:00
David Barsky
64779737db internal: fix deadlock introduced by #16643 2024-02-23 15:34:23 -05:00
bors
12144045fe Auto merge of #16650 - Veykril:metrics-rustc, r=Veykril
Fix: Fix metrics CI failing
2024-02-23 19:23:45 +00:00
Lukas Wirth
0c3a524acb Fix: Fix metrics CI failing 2024-02-23 20:22:01 +01:00
bors
838523dcc2 Auto merge of #16621 - txase:no-build-with-bootstrap, r=Veykril
fix: Recompiles due to RUSTC_BOOTSTRAP

Some packages (e.g. thiserror) force a recompile if the value of the `RUSTC_BOOTSTRAP` env var changes. RA sets the variable to 1 in order to enable rustc / cargo unstable options. This causes flapping recompiles when building outside of RA.

Fixes #15057
2024-02-23 18:46:33 +00:00
bors
c45b3550c3 Auto merge of #16649 - Veykril:metrics-rustc, r=Veykril
internal: Disable rustc test metrics

The CI job for them frequently gets stuck and I am unsure why
2024-02-23 18:33:46 +00:00
Lukas Wirth
d9a08624aa internal: Disable rustc test metrics 2024-02-23 19:31:53 +01:00