]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoMerge #8048
bors[bot] [Wed, 17 Mar 2021 07:20:28 +0000 (07:20 +0000)]
Merge #8048

8048: Fix missing unresolved macro diagnostic in function body r=edwin0cheng a=brandondong

This was an issue I found while working on https://github.com/rust-analyzer/rust-analyzer/pull/7970.

**Reproduction:**
1. Call a non-existent macro in a function body.
```
fn main() {
  foo!();
}
```
2. No diagnostics are raised. An unresolved-macro-call diagnostic is expected.
3. If the macro call is instead outside of the function body, this works as expected.

I believe this worked previously and regressed in https://github.com/rust-analyzer/rust-analyzer/pull/7805.

**Behavior prior to https://github.com/rust-analyzer/rust-analyzer/pull/7805:**
- The unresolved-macro-call diagnostic did not exist. Instead, a macro-error diagnostic would be raised with the text "could not resolve macro [path]".
- This was implemented by adding an error to the error sink (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8L657).
- The error was propagated through https://github.com/rust-analyzer/rust-analyzer/blob/1a82af3527e476d52410ff4dfd2fb4c57466abcb/crates/hir_def/src/body.rs#L123 eventually reaching https://github.com/rust-analyzer/rust-analyzer/blob/1a82af3527e476d52410ff4dfd2fb4c57466abcb/crates/hir_def/src/body/lower.rs#L569.

**Behavior after:**
- Instead of writing to the error sink, an UnresolvedMacro error is now returned (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R631).
- The parent caller throws away the error as its function signature is `Option<MacroCallId>` (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R604).
- We instead now reach the warn condition (https://github.com/rust-analyzer/rust-analyzer/blob/1a82af3527e476d52410ff4dfd2fb4c57466abcb/crates/hir_def/src/body.rs#L124) and no diagnostics are created in https://github.com/rust-analyzer/rust-analyzer/blob/1a82af3527e476d52410ff4dfd2fb4c57466abcb/crates/hir_def/src/body/lower.rs#L575.

**Fix:**
- Make sure to propagate the UnresolvedMacro error. Report the error using the new unresolved-macro-call diagnostic.

Co-authored-by: Brandon <brandondong604@hotmail.com>
3 years agoFollow established ErrorEmitted pattern
Brandon [Wed, 17 Mar 2021 06:31:14 +0000 (23:31 -0700)]
Follow established ErrorEmitted pattern

3 years agoMerge #8062
bors[bot] [Tue, 16 Mar 2021 20:01:20 +0000 (20:01 +0000)]
Merge #8062

8062: pit-of-successify tree editor r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agopit-of-successify tree editor
Aleksey Kladov [Tue, 16 Mar 2021 19:59:57 +0000 (22:59 +0300)]
pit-of-successify tree editor

3 years agoMerge #8061
bors[bot] [Tue, 16 Mar 2021 19:53:01 +0000 (19:53 +0000)]
Merge #8061

8061: Auto-magical whitespace r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAuto-magical whitespace
Aleksey Kladov [Tue, 16 Mar 2021 19:51:37 +0000 (22:51 +0300)]
Auto-magical whitespace

3 years agoMerge #8042
bors[bot] [Tue, 16 Mar 2021 19:36:55 +0000 (19:36 +0000)]
Merge #8042

8042: Add perf_revision to benchmark results r=lnicola a=d2weber

I gave it a try to add the hash as described in #8031
Feel free to tell me if there is something I could improve.

Co-authored-by: Douglas Weber <douglas.web@web.de>
3 years agoMerge #8060
bors[bot] [Tue, 16 Mar 2021 19:28:47 +0000 (19:28 +0000)]
Merge #8060

8060: Move more bounds r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoMove more bounds
Aleksey Kladov [Tue, 16 Mar 2021 19:28:04 +0000 (22:28 +0300)]
Move more bounds

changelog: skip

3 years agoMerge #8041
bors[bot] [Tue, 16 Mar 2021 16:58:48 +0000 (16:58 +0000)]
Merge #8041

8041: Rename Substs -> Substitution r=flodiebold a=flodiebold

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
3 years agoRename Substs -> Substitution
Florian Diebold [Mon, 15 Mar 2021 20:02:34 +0000 (21:02 +0100)]
Rename Substs -> Substitution

3 years agoMerge #8055
bors[bot] [Tue, 16 Mar 2021 15:48:35 +0000 (15:48 +0000)]
Merge #8055

8055: Implement HirDisplay for some more types r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #8053
bors[bot] [Tue, 16 Mar 2021 15:40:06 +0000 (15:40 +0000)]
Merge #8053

8053: Remove ShortLabel r=Veykril a=Veykril

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoImplement HirDisplay for some more types
Lukas Wirth [Tue, 16 Mar 2021 15:36:34 +0000 (16:36 +0100)]
Implement HirDisplay for some more types

3 years agoMerge #8034
bors[bot] [Tue, 16 Mar 2021 14:54:12 +0000 (14:54 +0000)]
Merge #8034

8034: Implement Crate::transitive_reverse_dependencies r=matklad a=Veykril

changelog internal Implement Crate::transitive_reverse_dependencies

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoDon't repeat work in transitive_reverse_dependencies
Lukas Wirth [Tue, 16 Mar 2021 14:53:34 +0000 (15:53 +0100)]
Don't repeat work in transitive_reverse_dependencies

3 years agoRemove ShortLabel
Lukas Wirth [Tue, 16 Mar 2021 14:44:31 +0000 (15:44 +0100)]
Remove ShortLabel

3 years agoAdd new_source_root meta to test fixtures
Lukas Wirth [Tue, 16 Mar 2021 14:28:02 +0000 (15:28 +0100)]
Add new_source_root meta to test fixtures

3 years agoMerge #8052
bors[bot] [Tue, 16 Mar 2021 13:56:53 +0000 (13:56 +0000)]
Merge #8052

8052: minor style fixes per feedback on #8036 r=JoshMcguigan a=JoshMcguigan

cc @matklad  - this PR addresses your comments in #8036.

changelog fixup #8036

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
3 years agominor style fixes per feedback on #8036
Josh Mcguigan [Tue, 16 Mar 2021 13:54:17 +0000 (06:54 -0700)]
minor style fixes per feedback on #8036

3 years agoMerge #8051
bors[bot] [Tue, 16 Mar 2021 13:35:26 +0000 (13:35 +0000)]
Merge #8051

8051: Fix more unused wariable warnings r=lnicola a=lnicola

bors r+

changelog skip

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
3 years agoFix more unused wariable warnings
Laurențiu Nicola [Tue, 16 Mar 2021 13:34:19 +0000 (15:34 +0200)]
Fix more unused wariable warnings

3 years agoMerge #7498
bors[bot] [Tue, 16 Mar 2021 13:14:48 +0000 (13:14 +0000)]
Merge #7498

7498: Clone for update r=matklad a=matklad

rowan counterpart https://github.com/rust-analyzer/rowan/pull/93

#6857

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoUpgrade rowan
Aleksey Kladov [Sat, 30 Jan 2021 15:19:21 +0000 (18:19 +0300)]
Upgrade rowan

Notably, new rowan comes with support for mutable syntax trees.

3 years agoMerge #7900 #8000
bors[bot] [Tue, 16 Mar 2021 08:05:24 +0000 (08:05 +0000)]
Merge #7900 #8000

7900: show function params in completion detail r=matklad a=JoshMcguigan

This resolves #7842 by updating the detail for function completions from `-> T` to `fn(T, U) -> V`. I added an expicit unit test for this, `ide_completion::render::fn_detail_includes_args_and_return_type`, which passes.

Lots of other unit tests fail (~60 of them) due to this change, although I believe the failures are purely cosmetic (they were testing the exact format of this output). I'm happy to go update those tests, but before I do that I'd like to make sure this is in fact the format we want for the detail?

edit - I realized `UPDATE_EXPECT=1 cargo test` automatically updates `expect!` tests. Big :+1: to whoever worked on that! So I'll go ahead and update all these tests soon. But I still would like to confirm `fn(T, U) -> V` is the desired content in the `detail` field.

8000: Use hir formatter for hover text r=matklad a=oxalica

Fix #2765 , (should) fix #4665

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: oxalica <oxalicc@pm.me>
3 years agoMerge #8036 #8046
bors[bot] [Tue, 16 Mar 2021 07:57:33 +0000 (07:57 +0000)]
Merge #8036 #8046

8036: completions: provide relevance bonus for enum types, and suggest ref matches for fn and enum r=matklad a=JoshMcguigan

This PR makes several improvements to completions and completion sorting:

1. Provide exact match type relevance score bonus for enum variants
2. Suggest `&Foo` (ref_match) for enums if that is an exact type match
3. Suggest `&foo()` (ref_match) if `foo` returns a type which would be an exact match either with the reference or due to a `Deref` impl

### Before

![pre-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189377-3f05a580-8573-11eb-89be-58a45cb7f829.png)

### After

![post-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189395-45941d00-8573-11eb-871b-09186b35cbb9.png)

### Caveats

I think generic types will require some kind of fancier logic when testing for `exact_type_match`, so for now `Option`/`Result`/etc unfortunately still don't have great completions.

### Implementation

I implemented this in a way that I think makes it most likely for each completion type to be handled consistently. Just replace `CompletionItem::new` with `CompletionItem::new_with_type_info` and `exact_type_match`/`exact_name_match`/`ref_match` are all handled for you, in a way which is sure to be consistent across completion types.

This approach does introduce some coupling/plumbing that didn't exist before. Notice for example `set_is_local` on the builder, because `set_relevance` was removed from the builder to enforce that the relevance was built "properly" with `CompletionItem::new_with_type_info`. But I think there are benefits to this approach, like `CompletionRelevance` should probably consider deprecation status, and we already tell the builder about that, so in the (likely near term) future we can just pass that information along to `CompletionRelevance` when the user calls `set_deprecated` rather than the user having to manually set it in two places. This basically just hides `CompletionRelevance` from the individual completions, so they only worry about the `CompletionItem` interface. At the moment this seems like a cleaner approach to me, but I'm open to feedback here.

edit - I've reimplemented this in a simpler way, per feedback below.

8046: Prefer match to if let else r=matklad a=matklad

bors r+
🤖

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoFix missing unresolved macro diagnostic in function body
Brandon [Tue, 16 Mar 2021 07:46:57 +0000 (00:46 -0700)]
Fix missing unresolved macro diagnostic in function body

3 years agoPrefer match to if let else
Aleksey Kladov [Tue, 16 Mar 2021 07:51:05 +0000 (10:51 +0300)]
Prefer match to if let else

3 years agoMerge #8045
bors[bot] [Tue, 16 Mar 2021 07:50:04 +0000 (07:50 +0000)]
Merge #8045

8045: Increase fetch-depth to make `git describe` work r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
3 years agoIncrease fetch-depth to make `git describe` work
Laurențiu Nicola [Tue, 16 Mar 2021 07:48:50 +0000 (09:48 +0200)]
Increase fetch-depth to make `git describe` work

3 years agoMerge #8040
bors[bot] [Tue, 16 Mar 2021 07:41:58 +0000 (07:41 +0000)]
Merge #8040

8040: 7709: Added the check for return type of len function. r=Veykril a=chetankhilosiya

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
3 years agoMerge #8044
bors[bot] [Tue, 16 Mar 2021 05:48:05 +0000 (05:48 +0000)]
Merge #8044

8044: Fix macro expansion for statements w/o semicolon r=edwin0cheng a=edwin0cheng

Fixes  #7845

And up `ungrammer` to  1.12.

cc @jonas-schievink

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoFix macro expansion for statements w/o semicolon
Edwin Cheng [Tue, 16 Mar 2021 05:44:50 +0000 (13:44 +0800)]
Fix  macro expansion for statements w/o semicolon

3 years agocompletions: centralize calculation of relevance and ref matches
Josh Mcguigan [Tue, 16 Mar 2021 02:26:59 +0000 (19:26 -0700)]
completions: centralize calculation of relevance and ref matches

3 years agoAdd perf_revision to benchmark results
Douglas Weber [Mon, 15 Mar 2021 21:21:02 +0000 (22:21 +0100)]
Add perf_revision to benchmark results

3 years ago7709: Import changes.
Chetan Khilosiya [Mon, 15 Mar 2021 20:28:21 +0000 (01:58 +0530)]
7709: Import changes.

3 years ago7709: Added the check for return type of len function.
Chetan Khilosiya [Mon, 15 Mar 2021 19:46:59 +0000 (01:16 +0530)]
7709: Added the check for return type of len function.

3 years agoMerge #8039
bors[bot] [Mon, 15 Mar 2021 18:49:07 +0000 (18:49 +0000)]
Merge #8039

8039: Use SmallVec for Substs r=flodiebold a=flodiebold

Doesn't help as much as I hoped, but it helps a bit and I also did some
refactorings that were necessary anyway.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
3 years agoUse SmallVec for Substs
Florian Diebold [Mon, 15 Mar 2021 18:13:49 +0000 (19:13 +0100)]
Use SmallVec for Substs

Doesn't help as much as I hoped, but it helps a bit and I also did some
refactorings that were necessary anyway.

3 years agoMerge #7970
bors[bot] [Mon, 15 Mar 2021 18:24:22 +0000 (18:24 +0000)]
Merge #7970

7970: Fix incorrect diagnostics for failing built in macros r=jonas-schievink a=brandondong

**Reproduction:**
1. Use a built in macro in such a way that rust-analyzer fails to expand it. For example:

**lib.rs**
```
include!("<valid file but without a .rs extension so it is not indexed by rust-analyzer>");
```
2. rust-analyzer highlights the macro call and says the macro itself cannot be resolved even though include! is in the standard library (unresolved-macro-call diagnostic).
3. No macro-error diagnostic is raised.

**Root cause for incorrect unresolved-macro-call diagnostic:**
1. collector:collect_macro_call is able to resolve include! in legacy scope but the expansion fails. Therefore, it's pushed into unexpanded_macros to be retried with module scope.
2. include! fails at the resolution step in collector:resolve_macros now that it's using module scope. Therefore, it's retained in unexpanded_macros.
3. Finally, collector:finish tries resolving the remaining unexpanded macros but only with module scope. include! again fails at the resolution step so a diagnostic is created.

**Root cause for missing macro-error diagnostic:**
1. In collector:resolve_macros, directive.legacy is None since eager expansion failed in collector:collect_macro_call. The macro_call_as_call_id fails to resolve since we're retrying in module scope. Therefore, collect_macro_expansion is not called for the macro and no macro-error diagnostic is generated.

**Fix:**
- In collector:collect_macro_call, do not add failing built-in macros to the unexpanded_macros list and immediately raise the macro-error diagnostic. This is in contrast to lazy macros which are resolved in collector::resolve_macros and later expanded in collect_macro_expansion where a macro-error diagnostic may be raised.

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: brandondong <brandondong604@hotmail.com>
3 years agoUpdate crates/hir_def/src/nameres/collector.rs
brandondong [Mon, 15 Mar 2021 18:16:58 +0000 (11:16 -0700)]
Update crates/hir_def/src/nameres/collector.rs

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoMerge #8038
bors[bot] [Mon, 15 Mar 2021 18:14:49 +0000 (18:14 +0000)]
Merge #8038

8038: Fix unification logic r=flodiebold a=flodiebold

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
3 years agoFix unification logic
Florian Diebold [Mon, 15 Mar 2021 17:22:25 +0000 (18:22 +0100)]
Fix unification logic

3 years agoMerge #8028
bors[bot] [Mon, 15 Mar 2021 17:50:20 +0000 (17:50 +0000)]
Merge #8028

8028: Return multiple modules in `parent_module` feature r=matklad a=Veykril

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #8037
bors[bot] [Mon, 15 Mar 2021 17:40:14 +0000 (17:40 +0000)]
Merge #8037

8037: Assist is empty 7709 r=Veykril a=chetankhilosiya

Updated the implementation to get the function from implementation

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
3 years agoImplement Crate::transitive_reverse_dependencies
Lukas Wirth [Mon, 15 Mar 2021 16:43:46 +0000 (17:43 +0100)]
Implement Crate::transitive_reverse_dependencies

3 years agoUpdate tests
oxalica [Mon, 15 Mar 2021 17:24:26 +0000 (01:24 +0800)]
Update tests

3 years agoPretty print root module of extern crates
oxalica [Mon, 15 Mar 2021 17:24:21 +0000 (01:24 +0800)]
Pretty print root module of extern crates

3 years ago7709: Updated the implementation.
Chetan Khilosiya [Mon, 15 Mar 2021 17:18:50 +0000 (22:48 +0530)]
7709: Updated the implementation.

The get function from impl method is updated.
and now same method used to get len and is_empty function.

3 years agoClean usage of ShortLabel
oxalica [Mon, 15 Mar 2021 16:58:42 +0000 (00:58 +0800)]
Clean usage of ShortLabel

3 years agoFix trait type parameter
oxalica [Mon, 15 Mar 2021 16:58:29 +0000 (00:58 +0800)]
Fix trait type parameter

3 years agoUse hir formatter more
oxalica [Mon, 15 Mar 2021 16:05:03 +0000 (00:05 +0800)]
Use hir formatter more

3 years agoImpl HirDisplay for function hover message
oxalica [Sun, 14 Mar 2021 12:03:39 +0000 (20:03 +0800)]
Impl HirDisplay for function hover message

3 years agoIntroduce FunctionQualifier for hir::FunctionData
oxalica [Sun, 14 Mar 2021 10:00:11 +0000 (18:00 +0800)]
Introduce FunctionQualifier for hir::FunctionData

3 years agoCollect HirDisplay impls to a single file
oxalica [Sun, 14 Mar 2021 09:36:04 +0000 (17:36 +0800)]
Collect HirDisplay impls to a single file

3 years agoAdd test for hover of macro expanded function
oxalica [Sat, 13 Mar 2021 17:07:05 +0000 (01:07 +0800)]
Add test for hover of macro expanded function

3 years agoMerge #8035
bors[bot] [Mon, 15 Mar 2021 16:51:53 +0000 (16:51 +0000)]
Merge #8035

8035: unqualfied_path completions aren't responsible for variant pattern completions r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agounqualfied_path completions aren't responsible for pattern completions
Lukas Wirth [Mon, 15 Mar 2021 16:23:08 +0000 (17:23 +0100)]
unqualfied_path completions aren't responsible for pattern completions

3 years ago7709: Added the assist to generate is_empty function
Chetan Khilosiya [Thu, 11 Mar 2021 18:55:22 +0000 (00:25 +0530)]
7709: Added the assist to generate is_empty function

the assist will be shown when the len function is implemented.
is_empty internally uses len function.

3 years agoMerge #7992
bors[bot] [Mon, 15 Mar 2021 15:53:15 +0000 (15:53 +0000)]
Merge #7992

7992: improved completion sorting for functions and methods r=JoshMcguigan a=JoshMcguigan

This PR improves completion sorting for functions and methods. Related to #7935.

### Before

The methods are being sorted by `coc` by closeness in file.

![pre-fn-relevance](https://user-images.githubusercontent.com/22216761/111018669-fe3d3f00-836e-11eb-9607-cc05af080a6a.png)

### After

Notice `bbb()` on top (type + name match), followed by `ddd()` (type match).

![image](https://user-images.githubusercontent.com/22216761/111018680-0e551e80-836f-11eb-94b1-c88336ecbc6e.png)

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
3 years agoMerge #8033
bors[bot] [Mon, 15 Mar 2021 15:39:34 +0000 (15:39 +0000)]
Merge #8033

8033: Add test for proc-macro meta info retrieval r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoAdd test for proc-macro meta info retrieval
Edwin Cheng [Mon, 15 Mar 2021 15:38:22 +0000 (23:38 +0800)]
Add test for proc-macro meta info retrieval

3 years agoimplement function completion scoring
Josh Mcguigan [Fri, 12 Mar 2021 23:06:17 +0000 (15:06 -0800)]
implement function completion scoring

3 years agoMerge #8032
bors[bot] [Mon, 15 Mar 2021 15:21:42 +0000 (15:21 +0000)]
Merge #8032

8032: Enable proc-macros by default r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoEnable proc-macros by default
Aleksey Kladov [Mon, 15 Mar 2021 15:19:08 +0000 (18:19 +0300)]
Enable proc-macros by default

3 years agoSupport multiple parents in parentModule in vscode-client
Lukas Wirth [Mon, 15 Mar 2021 14:49:20 +0000 (15:49 +0100)]
Support multiple parents in parentModule in vscode-client

3 years agoMerge #8029
bors[bot] [Mon, 15 Mar 2021 14:42:26 +0000 (14:42 +0000)]
Merge #8029

8029: Enable thread-local coverage marks r=JoshMcguigan a=lnicola

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
3 years agoMerge #8030
bors[bot] [Mon, 15 Mar 2021 14:34:23 +0000 (14:34 +0000)]
Merge #8030

8030: Add diesel to the benchmark suite r=lnicola a=weiznich

This commit adds diesel to the continuosly run benchmark suite. Diesel
heavily relies internally on macro generated code. Additionally there
are lots of complicated trait releations used as part of their API.
Therefore this benchmark will be quite sensitive to:
* Performance related changes in the macro expanding code
* Performance related changes while resolving trait bounds

CC #7950

cc @lnicola

Co-authored-by: Georg Semmler <github@weiznich.de>
3 years agoAdd diesel to the benchmark suite
Georg Semmler [Mon, 15 Mar 2021 14:19:16 +0000 (15:19 +0100)]
Add diesel to the benchmark suite

This commit adds diesel to the continuosly run benchmark suite. Diesel
heavily relies internally on macro generated code. Additionally there
are lots of complicated trait releations used as part of their API.
Therefore this benchmark will be quite sensitive to:
* Performance related changes in the macro expanding code
* Performance related changes while resolving trait bounds

CC #7950

3 years agoReturn multiple modules in `parent_module`
Lukas Wirth [Mon, 15 Mar 2021 13:51:20 +0000 (14:51 +0100)]
Return multiple modules in `parent_module`

3 years agoMerge #8020
bors[bot] [Mon, 15 Mar 2021 14:08:26 +0000 (14:08 +0000)]
Merge #8020

8020: Power up goto_implementation r=matklad a=Veykril

by allowing it to be invoked on references of names, now showing all (trait)
implementations of the given type in all crates instead of just the defining
crate as well as including support for builtin types

![image](https://user-images.githubusercontent.com/3757771/111144403-52bb0700-8587-11eb-9205-7a2a5b8b75a3.png)
Example screenshot of `impl`s of Box in `log`, `alloc`, `std` and the current crate. Before you had to invoke it on the definition where it would only show the `impls` in `alloc`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoDrop non-working mark
Laurențiu Nicola [Mon, 15 Mar 2021 14:05:16 +0000 (16:05 +0200)]
Drop non-working mark

3 years agoEnable thread-local coverage marks
Laurențiu Nicola [Mon, 15 Mar 2021 14:02:50 +0000 (16:02 +0200)]
Enable thread-local coverage marks

3 years agoMerge #8027
bors[bot] [Mon, 15 Mar 2021 13:42:12 +0000 (13:42 +0000)]
Merge #8027

8027: Completion context remove exact match method in favor of fields r=JoshMcguigan a=JoshMcguigan

This is a minor cleanup PR following #8008. It removes the `expected_name_and_type` method on completion context in favor of using the fields.

I thought this method was used in more places, or else it may have just made sense to make this change directly in #8008 :shrug:

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
3 years agogoto_implementation: Look at the entire crate graph for trait impls
Lukas Wirth [Mon, 15 Mar 2021 13:31:55 +0000 (14:31 +0100)]
goto_implementation: Look at the entire crate graph for trait impls

3 years agoremove expected_name_and_type method on completion context in favor of using fields...
Josh Mcguigan [Mon, 15 Mar 2021 13:25:39 +0000 (06:25 -0700)]
remove expected_name_and_type method on completion context in favor of using fields added in #8008

3 years agoMerge #8015
bors[bot] [Mon, 15 Mar 2021 13:18:26 +0000 (13:18 +0000)]
Merge #8015

8015:  Introduce Semantics::visit_file_defs r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/issues/3538#issuecomment-798920601

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #8008
bors[bot] [Mon, 15 Mar 2021 12:59:47 +0000 (12:59 +0000)]
Merge #8008

8008: Completion context expected type r=matklad a=JoshMcguigan

Currently there are two ways completions use to determine the expected type. There is the `expected_type` field on the `CompletionContext`, as well as the `expected_name_and_type` method on the `RenderContext`. These two things returned slightly different results, and their results were only valid if you had pre-checked some (undocumented) invariants. A simple combination of the two approaches doesn't work because they are both too willing to go far up the syntax tree to find something that fits what they are looking for.

This PR makes the following changes:

1. Updates the algorithm that sets `expected_type` on `CompletionContext`
2. Adds `expected_name` field to `CompletionContext`
3. Re-writes the `expected_name_and_type` method to simply return the underlying fields from `CompletionContext` (I'd like to save actually removing this method for a follow up PR just to keep the scope of the changes down)
4. Adds unit tests for the `expected_type`/`expected_name` fields

All the existing unit tests still pass (unmodified), but this new algorithm certainly has some gaps (although I believe all the `FIXME` introduced in this PR are also flaws in the current code). I wanted to stop here and get some feedback though - is this approach fundamentally sound?

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
3 years agoMerge #8018
bors[bot] [Mon, 15 Mar 2021 12:51:27 +0000 (12:51 +0000)]
Merge #8018

8018: Make Ty wrap TyKind in an Arc r=flodiebold a=flodiebold

... to further move towards Chalk.

This is a bit of a slowdown (218ginstr vs 213ginstr for inference on RA), even though it allows us to unwrap the Substs in `TyKind::Ref` etc..

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
3 years agoSpeedup trait impl search for goto_implementation
Lukas Wirth [Mon, 15 Mar 2021 12:49:21 +0000 (13:49 +0100)]
Speedup trait impl search for goto_implementation

3 years agoMerge #8026
bors[bot] [Mon, 15 Mar 2021 12:39:24 +0000 (12:39 +0000)]
Merge #8026

8026: Simplify source maps for fields r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoSimplify source maps for fields
Aleksey Kladov [Mon, 15 Mar 2021 12:38:50 +0000 (15:38 +0300)]
Simplify source maps for fields

3 years agoupdate algorithm for determining expected type of completion
Josh Mcguigan [Sun, 14 Mar 2021 04:30:14 +0000 (20:30 -0800)]
update algorithm for determining expected type of completion

3 years agoMerge #8025
bors[bot] [Mon, 15 Mar 2021 12:13:01 +0000 (12:13 +0000)]
Merge #8025

8025: Goto definition works for `S { a: }` case r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoGoto definition works for `S { a: }` case
Aleksey Kladov [Mon, 15 Mar 2021 12:02:48 +0000 (15:02 +0300)]
Goto definition works for `S { a: }` case

What happens here is that we lower `: ` to a missing expression, and
then correctly record that the corresponding field expression resolves
to a specific field. Where we fail is in the mapping of syntax to this
missing expression. Doing it via `ast_field.expr()` fails, as that
expression is `None`. Instead, we go in the opposite direcition and ask
each lowered field about its source.

This works, but has wrong complexity `O(N)` and, really, the
implementation is just too complex. We need some better management of
data here.

3 years agomove Semantics::visit_file_defs to ide_db::helpers
Lukas Wirth [Mon, 15 Mar 2021 11:18:52 +0000 (12:18 +0100)]
move Semantics::visit_file_defs to ide_db::helpers

3 years agoIntroduce Semantics::visit_file_defs
Lukas Wirth [Sun, 14 Mar 2021 15:12:38 +0000 (16:12 +0100)]
Introduce Semantics::visit_file_defs

3 years agoPower up goto_implementation
Lukas Wirth [Mon, 15 Mar 2021 09:11:48 +0000 (10:11 +0100)]
Power up goto_implementation

by allowing it to be invoked on references of names, showing all (trait)
implementations of the given type in all crates including builtin types

3 years agoMerge #8021 #8022
bors[bot] [Mon, 15 Mar 2021 10:05:49 +0000 (10:05 +0000)]
Merge #8021 #8022

8021: Enable searching for builtin types r=matklad a=Veykril

Not too sure how useful this is for reference search overall, but for completeness sake it should be there
![image](https://user-images.githubusercontent.com/3757771/111132711-f69db600-8579-11eb-8c90-22fd6862d11f.png)

Also enables document highlighting for them.

8022: some clippy::performance fixes r=matklad a=matthiaskrgr

use vec![] instead of Vec::new() + push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unnecessary resizing

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Matthias KrĂĽger <matthias.krueger@famsik.de>
3 years agoMerge #8023
bors[bot] [Mon, 15 Mar 2021 09:58:25 +0000 (09:58 +0000)]
Merge #8023

8023: Move code to the appropriate layer r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoMove code to the appropriate layer
Aleksey Kladov [Mon, 15 Mar 2021 09:55:27 +0000 (12:55 +0300)]
Move code to the appropriate layer

StructureNodeKind is a type which is specific to a particular feature,
file_structure. It shouldn't be in the "code shared by all ide features"
part.

3 years agoMerge #7975
bors[bot] [Mon, 15 Mar 2021 09:26:58 +0000 (09:26 +0000)]
Merge #7975

7975: Provide regions in file structure r=ivan770 a=ivan770

Closes #7913

https://user-images.githubusercontent.com/14003886/110819163-96b3c080-8296-11eb-993e-a7cdb574a12d.mp4

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
3 years agosome clippy::performance fixes
Matthias KrĂĽger [Mon, 15 Mar 2021 09:15:08 +0000 (10:15 +0100)]
some clippy::performance fixes

use vec![] instead of Vec::new() +  push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unneccessary resizing

3 years agoEnable searching for builtin types
Lukas Wirth [Mon, 15 Mar 2021 08:32:06 +0000 (09:32 +0100)]
Enable searching for builtin types

3 years agoMerge #7966
bors[bot] [Mon, 15 Mar 2021 01:23:29 +0000 (01:23 +0000)]
Merge #7966

7966: Diagnose files that aren't in the module tree r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6377

I'm not sure if this is the best way to do this. It will cause false positives for all `include!`d files (though I'm not sure how much IDE functionality we have for these).

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoAdd module comment
Jonas Schievink [Mon, 15 Mar 2021 01:23:00 +0000 (02:23 +0100)]
Add module comment

3 years agoUse pub(crate)
Jonas Schievink [Mon, 15 Mar 2021 00:46:59 +0000 (01:46 +0100)]
Use pub(crate)

3 years agoRedo it properly and add a quickfix
Jonas Schievink [Mon, 15 Mar 2021 00:39:23 +0000 (01:39 +0100)]
Redo it properly and add a quickfix

3 years agoMerge #8017
bors[bot] [Sun, 14 Mar 2021 19:46:49 +0000 (19:46 +0000)]
Merge #8017

8017: Don't drop type params in doc-test paths r=Veykril a=Veykril

Closes #7995

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoDon't drop type params in doc-test paths
Lukas Wirth [Sun, 14 Mar 2021 19:16:02 +0000 (20:16 +0100)]
Don't drop type params in doc-test paths