Commit Graph

27982 Commits

Author SHA1 Message Date
Vincent Esche
ed3497883c Add public function for resolving ast::Expr to hir::Callable 2024-02-28 16:44:07 +01:00
Vincent Esche
74531e4d80 Export SemanticsImpl from ra_ap_hir crate, since it's already exposed via Semantics.deref() 2024-02-28 16:16:54 +01:00
Lukas Wirth
ab533d887d fix: Ignore generic arguments in intra doc link path resolution 2024-02-28 14:47:47 +01:00
Vincent Esche
fac8a14de8 Add a more methods for resolving definitions from AST to their corresponding HIR types 2024-02-28 10:27:28 +01:00
Vincent Esche
6112ddfabb Add prefix file_ to Semantics's to_module_defs()/to_module_def() methods 2024-02-28 10:27:28 +01:00
Vincent Esche
c061a9e84e Derive PartialEq, Eq & Hash for hir::Param 2024-02-27 20:53:29 +01:00
bors
0ac05c0527 Auto merge of #16697 - regexident:relpath-to-relpathbuf, r=Veykril
Add `to_path_buf()` method for `RelPath`

There seems to be no ergonomic way to obtain a `RelPathBuf` from a corresponding `&RelPath` at the moment, making the latter sort of a dead end.

The `AbsPath` type provides the following:

```rust
impl AbsPath {
    // ...

    /// Equivalent of [`Path::to_path_buf`] for `AbsPath`.
    pub fn to_path_buf(&self) -> AbsPathBuf {
        AbsPathBuf::try_from(self.0.to_path_buf()).unwrap()
    }

    // ...
}
```

So I took the liberty of adding a corresponding equivalent for `RelPath:

```rust
impl RelPath {
    // ...

    /// Equivalent of [`Path::to_path_buf`] for `RelPath`.
    pub fn to_path_buf(&self) -> RelPathBuf {
        RelPathBuf::try_from(self.0.to_path_buf()).unwrap()
    }

    // ...
}
```

(the change is motivated by an outside use of the `ra_ap_paths` crate that would benefit from being able to use `RelPath` and `AbsPath` over `Path`)
2024-02-27 18:19:43 +00:00
Vincent Esche
0005794770 Add to_path_buf() method for RelPath 2024-02-27 18:33:47 +01:00
bors
a41cec9f7c Auto merge of #16696 - ShoyuVanilla:fix-goto-deref-mut, r=Veykril
fix: Goto definition for `deref_mut`

Fixes #16520

a3236be9d7/crates/hir/src/source_analyzer.rs (L375-L393)

As we can see from the above, current implementation routes all dereferencing prefix operations to `Deref::deref` implementation, not regarding mutabilities.

a3236be9d7/crates/hir-ty/src/infer/mutability.rs (L134-L151)

Since we are resolving them already in mutability inferences, we can use those results for proper `deref` / `deref_mut` routing.
2024-02-27 16:01:45 +00:00
Shoyu Vanilla
612443111b Remove unused imports 2024-02-28 00:10:08 +09:00
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
Lukas Wirth
30ad0ae209 internal: Revert #16541 2024-02-27 15:48:30 +01:00
bors
a3236be9d7 Auto merge of #16630 - ShoyuVanilla:fix-closure-kind-inference, r=Veykril
fix: Wrong closure kind deduction for closures with predicates

Completes #16472, fixes #16421

The changed closure kind deduction is mostly simlar to `rustc_hir_typeck/src/closure.rs`.
Porting closure sig deduction from it seems possible too and I'm considering doing it with another PR
2024-02-27 14:41:23 +00:00
bors
c031246546 Auto merge of #16693 - Veykril:system-rustc-sysroot, r=Veykril
fix: rust-project.json projects not preferring sysroot rustc
2024-02-27 14:28:36 +00:00
roife
76b86b24bd fix: clippy and format 2024-02-27 20:53:09 +08:00
roife
ec5236f3a8 test: use 4 spaces for indetation in macro expansion 2024-02-27 20:53:07 +08:00
roife
48966268fc fix: use 4 spaces for indentation in macro expansion 2024-02-27 20:49:09 +08:00
roife
ce4ae41605 internal: simplify the process of inserting spaces after mut 2024-02-27 20:49:09 +08: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
Lukas Wirth
64c17a9b2e fix: rust-project.json projects not preferring sysroot rustc 2024-02-27 10:20:07 +01: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
Shoyu Vanilla
a4021f6ed5 Use lang-item instead of db lookup for FnTrait kind 2024-02-27 00:38:53 +09:00
Shoyu Vanilla
46cdce1b53 Update expectation tests 2024-02-27 00:18:40 +09:00
Shoyu Vanilla
e36a31bd95 Port closure kind deduction logic from rustc 2024-02-27 00:18:38 +09:00
Shoyu Vanilla
763714145a Add a new failing test 2024-02-27 00:15:25 +09:00
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