Commit graph

11754 commits

Author SHA1 Message Date
Dawer
7d675eda80 Don't panic on a pattern of unresolved ADT variant. 2021-06-01 00:08:43 +05:00
Dawer
466345ca81 Clean up, more docs. 2021-06-01 00:08:27 +05:00
Dawer
49e016169f Check pattern types. 2021-06-01 00:03:47 +05:00
Dawer
9b841a9a04 Expand binding patterns. 2021-06-01 00:03:47 +05:00
Dawer
d7239e5ab4 Fix visibility warnings 2021-06-01 00:03:47 +05:00
Dawer
a236bfa57a Lower binding pattern 2021-06-01 00:03:47 +05:00
Dawer
cf6f989a8d Lower bool literals 2021-06-01 00:03:47 +05:00
Dawer
d6d77e8a35 Treat ctor of unhandled type as non-exhaustive. 2021-06-01 00:03:47 +05:00
Dawer
e711abc290 Lower Pat::Path 2021-06-01 00:03:47 +05:00
Dawer
e50ce67631 Do not do match check if lowering failed. 2021-06-01 00:03:47 +05:00
Dawer
de6f430140 Fix panics on pattern_arena.borrow with ugly cloning 2021-06-01 00:03:46 +05:00
Dawer
975109051c Basic lowering hir_def::exrp::Pat -> typed HIR.
Pattern arena is broken
2021-06-01 00:03:46 +05:00
Dawer
2431ff5987 Handle unordered fields in struct patterns 2021-06-01 00:03:46 +05:00
Dawer
3ffcb2658c Complete field replacing 2021-06-01 00:03:46 +05:00
Dawer
3a85e47f6a Support bool literal patterns 2021-06-01 00:03:46 +05:00
Dawer
5a8a0b6269 Check enum patterns 2021-06-01 00:03:46 +05:00
Dawer
b4f4197332 Build wildcard witnesses instead of panicking 2021-06-01 00:03:46 +05:00
Dawer
678d85ca7e Implement struct ctor application 2021-06-01 00:03:46 +05:00
Dawer
062c7953a1 Add remaining Constructor variants 2021-06-01 00:03:46 +05:00
Dawer
2880fd2320 Complete usefulness::SubPatSet impl 2021-06-01 00:03:46 +05:00
Dawer
f4c3960364 List useless patterns in a useful match arm 2021-06-01 00:03:45 +05:00
Dawer
f4a95c93fe Remove unneeded indirection on PatCtxt 2021-06-01 00:03:45 +05:00
Dawer
26baab5d28 Enable generation of non-exhaustiveness witnesses 2021-06-01 00:03:45 +05:00
Dawer
c3c2893f30 Update match checking.
fn is_useful , more skeletons

Specify a lifetime on pattern references

impl PatStack

fill impl Matrix

PatStack::pop_head_constructor

Index-based approach

struct PatCtxt

fields construction fn Fields::wildcards

split wildcard

fn Constructor::is_covered_by_any(..)

fn Matrix::specialize_constructor(..)

impl Usefulness

Initial work on witness construction

Reorganize files

Replace match checking diagnostic

Handle types of expanded patterns

unit match checking go brrr
2021-06-01 00:03:45 +05:00
cynecx
759cb07891 hir_ty: use correct receiver_ty in method resolution 2021-05-31 20:26:38 +02:00
bors[bot]
7c1d8ca635
Merge #9088
9088: minor: remove debug print r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-31 17:22:09 +00:00
Aleksey Kladov
ee51bf04be minor: remove debug print 2021-05-31 20:20:30 +03:00
bors[bot]
4cb4b23dc6
Merge #9084 #9087
9084: fix: avoid panics in match case diagnostic r=matklad a=matklad

bors r+
🤖

closes #8809

9087: fix: fix shell injection in task spawning r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-31 17:12:01 +00:00
Jonas Schievink
b5fe4c6ef0 Use cargo check again 2021-05-31 18:58:36 +02:00
Aleksey Kladov
159922de93 minor: it's Parameter, not Argument 2021-05-31 19:45:50 +03:00
Aleksey Kladov
341f8bb200 fix: avoid panics in match case diagnostic 2021-05-31 19:45:50 +03:00
bors[bot]
10b15b27f2
Merge #8952
8952: add support of impl block for doctest into runnables r=matklad a=bnjjj

close #6356 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-05-31 15:48:41 +00:00
Jonas Schievink
cfcadcb295 Simplify proc_macro_srv tests 2021-05-31 17:32:56 +02:00
bors[bot]
c460baeaf3
Merge #9079
9079: Don't take the parent kind of trailing attributes in attr completion r=Veykril a=Veykril

bors r+
fixes https://github.com/rust-analyzer/rust-analyzer/issues/9076

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-31 13:38:32 +00:00
Lukas Wirth
741b2f531f Don't take the parent kind of trailing attributes in attr completion 2021-05-31 15:35:22 +02:00
bors[bot]
e6ec860363
Merge #9039
9039: feat: Complete fields and methods with `self.` prefixed when inside methods r=matklad a=Veykril


![w65NbjkZiG](https://user-images.githubusercontent.com/3757771/119984385-a0111700-bfc1-11eb-9dbf-52fdaa4d72b5.gif)
Closes #7173

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-31 13:21:31 +00:00
Lukas Wirth
fb7105a580 Add config setting for self-on-the-fly 2021-05-31 15:14:56 +02:00
Lukas Wirth
4507382f2e Move unprefixed field/method completion to dot 2021-05-31 15:10:20 +02:00
Lukas Wirth
d346f5bf75 Less strings, more hir::Names 2021-05-31 14:55:16 +02:00
Lukas Wirth
ca49fbe0a1 Complete self. prefixed fields and methods inside methods 2021-05-31 14:52:55 +02:00
bors[bot]
e9a797748d
Merge #8866
8866: Update salsa r=matklad a=jonas-schievink

This updates salsa to include https://github.com/salsa-rs/salsa/pull/265, and removes all cancellation-related code from rust-analyzer

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-31 12:42:32 +00:00
bors[bot]
b8d269990c
Merge #9060
9060: feat: Diagnose unimplemented built-in macros r=matklad a=jonas-schievink

A number of built-in attribute macros are unsupported, I thought it might be useful to put a diagnostic on their definition in libcore. Not sure.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-31 12:34:01 +00:00
Lukas Wirth
971b0836ef Use Names instead of Strings in the completion rendering api 2021-05-31 14:15:15 +02:00
bors[bot]
3cb3f1d17b
Merge #9025
9025: internal: Display unknown types in `analysis-stats` r=flodiebold a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-31 08:20:28 +00:00
bors[bot]
92b9e5ef3c
Merge #9068
9068: Move more `CompletinoContext` fields to `ImmediateLocation` r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-30 19:37:29 +00:00
Lukas Wirth
5660408f0a Move more fields to ImmediateLocation 2021-05-30 21:35:01 +02:00
cynecx
51cbcc5346 hir_ty: don't pass where clauses of associated types down to chalk (temp. fix #9052) 2021-05-30 19:21:08 +02:00
Lukas Wirth
c5cd25d755 Fix incorrect prefer_inner calls on some attribute completions 2021-05-30 17:13:00 +02:00
bors[bot]
f41b68637a
Merge #9062
9062: internal: Bump deps r=lnicola a=lnicola

Fixes #9061

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-30 11:48:59 +00:00
Laurențiu Nicola
36567eb9be Bump deps 2021-05-30 14:48:10 +03:00
Jonas Schievink
cb5454db86 Diagnose unimplemented built-in macros 2021-05-30 04:19:47 +02:00
Jonas Schievink
39533ad7dd Only complete derive proc macros in #[derive] 2021-05-29 21:18:14 +02:00
Jonas Schievink
acb5c227ed Update to prerelease 2021-05-29 21:10:00 +02:00
Jonas Schievink
8c639a87bd Thread proc-macro types through the HIR 2021-05-29 20:32:57 +02:00
bors[bot]
f6da603c7f
Merge #9050
9050: hir_ty: use async ret type for inference inside async bodies r=flodiebold a=cynecx

Fixes #9004.

Co-authored-by: cynecx <me@cynecx.net>
2021-05-29 17:39:15 +00:00
bors[bot]
0438e2ceaa
Merge #9054
9054: fix: fix `matches!` macro on nightly toolchains r=jonas-schievink a=jonas-schievink

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

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-29 16:33:20 +00:00
Jonas Schievink
4c4bcaebbe Treat pat_param like pat fragments 2021-05-29 18:32:32 +02:00
bors[bot]
11a1bd3259
Merge #9051
9051: Fix incorrect setting descriptions r=lnicola a=sclu1034

Descriptions for diagnostic warning hint and info display were swapped.

Fixes #8485.

Co-authored-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-05-29 16:23:59 +00:00
cynecx
54d60fdee9 hir_ty: use async ret type for inference inside async bodies 2021-05-29 18:17:45 +02:00
Lucas Schwiderski
9a057c0ff4
Fix incorrect setting descriptions
Descriptions for diagnostic warning hint and info display were swapped.

Fixes #8485.

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
2021-05-29 18:08:14 +02:00
bors[bot]
3fa3343e47
Merge #9048
9048: Add some lint completion tests r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-29 15:33:57 +00:00
Lukas Wirth
c9598a4cbf Add some lint completion tests 2021-05-29 17:19:49 +02:00
Jonas Schievink
31588aea04 Remove fragment kind knowledge from builtin macros 2021-05-29 17:17:08 +02:00
bors[bot]
247faf271b
Merge #9027
9027: feat: Attribute completion is context aware r=Veykril a=Veykril

This splits off the `lint` and `derive` completions into their own submodules of `attribute`.

The idea is to create a lazy global hashmap that maps `SyntaxKind` to attribute names(`&[&str]`) in which we index with the syntax kind of the "thing" we are attributing giving us the attributes back that are valid for this kind. Then we use this name to do a binary search on the attribute list to fetch and build the corresponding completion item.


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-29 12:14:16 +00:00
Lukas Wirth
c9f0f47bbb simplify 2021-05-29 14:02:06 +02:00
Lukas Wirth
e42c448077 More completion pattern tests 2021-05-28 22:19:52 +02:00
Lukas Wirth
47ad752e6c Implement prev sibling determination for CompletionContext 2021-05-28 22:03:31 +02:00
Lukas Wirth
a6b92a8cc0 simplify 2021-05-28 20:46:09 +02:00
bors[bot]
d5f7b2e52a
Merge #9028
9028: only advertise range formatting support if enabled r=Veykril a=euclio

Fixes #9009.

Co-authored-by: Andy Russell <arussell123@gmail.com>
2021-05-28 15:26:20 +00:00
bors[bot]
2968731fd5
Merge #9040
9040: Don't label derive macros with their banged_name r=Veykril a=Veykril

cc https://github.com/rust-analyzer/rust-analyzer/issues/7072#issuecomment-850396203
This doesn't fix it non builtin derives yet I think cause of a FIXME somewhere that doesn't categorize proc-macro derives as derives yet
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-28 12:59:54 +00:00
Lukas Wirth
439ae17e1b Don't label derive macros with their banged_name 2021-05-28 14:59:24 +02:00
bors[bot]
b5d41ba0e2
Merge #9038
9038: Folding range for return types r=Veykril a=MozarellaMan

For issue #8957 

![return type fold](https://user-images.githubusercontent.com/48062697/119979082-5c62e100-bfb2-11eb-9729-1dea1ce74de1.gif)


Co-authored-by: Ayomide Bamidele <48062697+MozarellaMan@users.noreply.github.com>
2021-05-28 12:16:18 +00:00
Ayomide Bamidele
b4e936f8f0 Test for correct amount of emitted folds 2021-05-28 13:10:41 +01:00
Ayomide Bamidele
156d995423 Folding range for return types 2021-05-28 12:39:02 +01:00
Lukas Wirth
61b4456752 Move runnable lenses below attributes 2021-05-28 13:02:42 +02:00
Laurențiu Nicola
2dee5930e0 Remove undocumented TextDocumentSyncKind::Full support 2021-05-28 13:01:04 +03:00
bors[bot]
bca00ac340
Merge #9033
9033: Complete keywords in (Assoc)ItemList with leading attribute r=Veykril a=Veykril

Fixes #7673
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-28 01:21:45 +00:00
Lukas Wirth
1894db49b1 Complete keywords in (Assoc)ItemList with leading attribute 2021-05-28 03:20:55 +02:00
bors[bot]
3a1598c3bc
Merge #9032
9032: Only complete modules in empty use-statements r=Veykril a=Veykril

bors r+
Part of #8518

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-28 00:43:16 +00:00
Lukas Wirth
9e71dd9799 Only complete modules in empty use-statements 2021-05-28 02:42:47 +02:00
Lukas Wirth
411eee7614 Add another attribute completion test 2021-05-28 01:09:22 +02:00
Lukas Wirth
0724bd0f21 Add attribute completion tests 2021-05-28 01:02:41 +02:00
bors[bot]
5b4589f474
Merge #9029
9029: minor: test that `ItemTree` makes `hir_def` queries syntax-independent r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-27 22:47:04 +00:00
Jonas Schievink
55f3ca2b74 Test that ItemTree works as intended 2021-05-28 00:46:05 +02:00
Lukas Wirth
594270be49 tt muncher time 2021-05-28 00:35:21 +02:00
Lukas Wirth
ab9c6ea4dd Split attribute completion module into attribute, derive and lint modules 2021-05-27 23:40:33 +02:00
Andy Russell
a0cd7fe242
only advertise range formatting support if enabled 2021-05-27 17:36:13 -04:00
Lukas Wirth
fc37e2f953 Attribute completion is context aware 2021-05-27 23:28:14 +02:00
bors[bot]
01bfc5f5c0
Merge #9026
9026: Complete modules in assoc item lists r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-27 19:13:34 +00:00
Lukas Wirth
ea251cbd4a Complete modules in item lists 2021-05-27 21:12:50 +02:00
Lukas Wirth
7ad378fec0 Complete modules in assoc item lists 2021-05-27 20:53:38 +02:00
Jonas Schievink
26b4777e1f Move hir_ty incremental test to its own file 2021-05-27 20:21:52 +02:00
bors[bot]
a2940c42c0
Merge #9020
9020: fix: Don't complete non-macro item paths in impls and modules r=Veykril a=Veykril

Part of #8518
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-27 16:34:46 +00:00
Laurențiu Nicola
aabbc84957 Display unknown types in analysis-stats 2021-05-27 19:30:28 +03:00
Lukas Wirth
3a16950fd9 Cleanup ImmediateLocation determination 2021-05-27 18:16:39 +02:00
Laurențiu Nicola
2268a220e4 Don't store supertraits in ItemTree 2021-05-27 16:52:30 +03:00
Jonas Schievink
33debc4065 Update salsa 2021-05-27 15:05:41 +02:00
bors[bot]
d0a4ba294c
Merge #8997
8997: internal: stop expanding UseTrees during ItemTree lowering r=jonas-schievink a=jonas-schievink

Closes https://github.com/rust-analyzer/rust-analyzer/issues/8908

Messy diff, but `ItemTree` lowering got simpler, since we now have a strict 1-to-1 mapping between `ast::Item` and `ModItem`.

The most messy part is mapping a single `UseTree` back to its `ast::UseTree` counterpart for diagnostics, but I think the ad-hoc source map built during lowering does the job.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-27 11:56:26 +00:00
Jonas Schievink
196cb65ead Drop ignore from doctests 2021-05-27 13:55:31 +02:00
Lukas Wirth
f41c983424 Don't complete non-macro item paths in impls and modules 2021-05-27 12:23:36 +02:00
bors[bot]
7d1653dcdc
Merge #9005
9005: internal: Document semantic token tags r=matklad a=Veykril

Closes #6457

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-27 07:04:15 +00:00
Lukas Wirth
30948e1ecb simplify 2021-05-27 03:47:20 +02:00
Lukas Wirth
6ec4ea8d9e simplify 2021-05-27 03:15:48 +02:00
Lukas Wirth
7de925b8ab Collapse more CompletionContext booleans into enums 2021-05-27 02:54:49 +02:00
bors[bot]
d6ed315806
Merge #9017
9017: internal: Reduce the number of traits passed through chalk during applicable trait lookup r=SomeoneToIgnore a=SomeoneToIgnore

Inherent traits can be omitted before trait solving, presumably slightly helping https://github.com/rust-analyzer/rust-analyzer/issues/7542 and slightly simplifying the code.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-05-26 23:06:59 +00:00
Kirill Bulatov
050c592b8c Exclude inherent traits more eagerly 2021-05-27 02:00:23 +03:00
Lukas Wirth
1f897f7319 Set record_pat_syntax more precisely in CompletionContext 2021-05-26 23:46:00 +02:00
bors[bot]
666fc1cec1
Merge #9015
9015: Merge pattern completion related bools into an enum r=Veykril a=Veykril

The two bools can never both be set so this is basically just a tri-state enum.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-26 20:43:53 +00:00
Lukas Wirth
7d865ef071 Merge pattern completion related bools into an enum 2021-05-26 22:39:47 +02:00
bors[bot]
8389510f8d
Merge #9012
9012: feat: add tab stops for keyword completions r=matklad a=eduardocanellas

Add tab stops for all the keywords that I judged fit. I also introduced some line breaks and spaces, following the pattern I saw in the `postfix` module.

Co-authored-by: Eduardo Canellas <eduardocanellas98@gmail.com>
2021-05-26 20:29:52 +00:00
Lukas Wirth
26e784a575 simplify 2021-05-26 21:09:27 +02:00
Eduardo Canellas
052df3deb7 feat: add tab stops for keyword completions 2021-05-26 14:24:54 -03:00
bors[bot]
bb1c7fc0cf
Merge #9008
9008: fix: remove undesired completions from trait/impl blocks r=Veykril a=eduardocanellas

Related to #8518


Co-authored-by: Eduardo Canellas <eduardocanellas98@gmail.com>
2021-05-26 17:04:09 +00:00
Eduardo Canellas
ce36746035 fix: remove undesired completions from trait/impl blocks 2021-05-26 13:21:27 -03:00
bors[bot]
f3aaae6555
Merge #9007
9007: Internal: `clippy::redundant_clone` fixes r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-26 15:36:14 +00:00
Laurențiu Nicola
8206939fed clippy::redundant_clone fixes 2021-05-26 18:34:50 +03:00
Lukas Wirth
7ebfc3d410 Document semantic token tags 2021-05-26 15:23:05 +02:00
bors[bot]
5a1fd05760
Merge #9003
9003: minor: Document semantic token modifiers r=Veykril a=Veykril

Part of #6457

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-26 12:08:56 +00:00
Lukas Wirth
887dd2d5bb Document semantic token modifiers 2021-05-26 13:37:54 +02:00
bors[bot]
5701c553cb
Merge #9002
9002: Move annotations below item attributes r=Veykril a=Veykril

This moves annotations/code lenses below attributes in items, bringing them inline with functions where this is already the case. This is done by changing the annotations covering range to just the name node's range which is also more inline with what the lsp expects which is that the range should ideally only cover a single line. 

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9000
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-26 10:26:19 +00:00
Lukas Wirth
dfa47eaadb Move annotations below item attributes 2021-05-26 12:23:51 +02:00
bors[bot]
8483fb0f26
Merge #8996
8996: Fix bug where library functions were not highlighted as such r=arzg a=arzg

Sorry about forgetting to test this in my last PR.

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-05-25 23:28:02 +00:00
Jonas Schievink
fe910c7bc4 Reduce memory usage a bit 2021-05-26 01:26:16 +02:00
Aramis Razzaghipour
8960a08951
Fix bug where library functions were not highlighted as such 2021-05-26 09:26:13 +10:00
Jonas Schievink
356dd3d909 Clean up ItemTree lowering now that it's 1:1 2021-05-26 01:09:31 +02:00
Jonas Schievink
b52df91877 Stop expanding UseTrees during ItemTree lowering 2021-05-26 01:01:58 +02:00
bors[bot]
5587d0a3e3
Merge #8973
8973: internal: move diagnostics to hir r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-25 20:33:21 +00:00
bors[bot]
e23083f398
Merge #8993
8993: fix: don't show pd/ppd completions where it shouldn't be r=flodiebold a=eduardocanellas

Closes #8992


Co-authored-by: Eduardo Canellas <eduardocanellas98@gmail.com>
2021-05-25 19:58:49 +00:00
bors[bot]
3b10f9e714
Merge #8994
8994: Check for subdirs in vfs loader exclusions. r=matklad a=ammkrn

The current logic used to transfer global_excludes into vfs exclusions
only transfers global_excludes that are the parent of an item in
dirs.include.
This commit additionally adds an item from global_exclude to the vfs
exclusions if the global_exclude is a child of an included item.

Co-authored-by: ammkrn <ammkrn@tuta.io>
2021-05-25 16:40:57 +00:00
ammkrn
96ee19851b Check for subdirs in vfs loader exclusions.
The current logic used to transfer global_excludes into vfs exclusions
only transfers global_excludes that are the parent of an item in
dirs.include.
This commit additionally adds an item from global_exclude to the vfs
exclusions if the global_exclude is a child of an included item.
2021-05-25 11:35:39 -05:00
Eduardo Canellas
e31a762c63 fix: don't show pd/ppd completions where it shouldn't be 2021-05-25 11:53:11 -03:00
Aleksey Kladov
5c9f31d4c2 internal: move diagnostics to hir
The idea here is to eventually get rid of `dyn Diagnostic` and
`DiagnosticSink` infrastructure altogether, and just have a `enum
hir::Diagnostic` instead.

The problem with `dyn Diagnostic` is that it is defined in the lowest
level of the stack (hir_expand), but is used by the highest level (ide).

As a first step, we free hir_expand and hir_def from `dyn Diagnostic`
and kick the can up to `hir_ty`, as an intermediate state. The plan is
then to move DiagnosticSink similarly to the hir crate, and, as final
third step, remove its usage from the ide.

One currently unsolved problem is testing. You can notice that the test
which checks precise diagnostic ranges, unresolved_import_in_use_tree,
was moved to the ide layer. Logically, only IDE should have the infra to
render a specific range.

At the same time, the range is determined with the data produced in
hir_def and hir crates, so this layering is rather unfortunate. Working
on hir_def shouldn't require compiling `ide` for testing.
2021-05-25 17:49:59 +03:00
Lukas Wirth
28ca371755 Consider trait to be in scope for trait-impl 2021-05-25 16:16:29 +02:00
bors[bot]
35db5e99f6
Merge #8990
8990: feat: Also do goto implementation on assoc consts r=lnicola a=lf-

I forgot to put this into #8988, sorry.

Goto implementation on a const on the trait will go to the
implementations with their respective definitions of the const, if
present.

Co-authored-by: Jade <software@lfcode.ca>
2021-05-25 13:33:07 +00:00
Jade
0292efd363 Also do goto implementation on assoc consts
I forgot to put this into #8988, sorry.

Goto implementation on a const on the trait will go to the
implementations with their respective definitions of the const, if
present.
2021-05-25 06:27:41 -07:00
bors[bot]
33fdd512e3
Merge #8987
8987: Fix lowering of FnOnce() without return type r=flodiebold a=flodiebold

This should result in an implicit `-> ()`, not leaving out the binding.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-05-25 13:25:15 +00:00
Florian Diebold
7c6f764ad6 Hide -> () in Fn traits 2021-05-25 15:23:52 +02:00
bors[bot]
f3cfd8afb6
Merge #8988
8988: feat: go to implementation on trait functions r=matklad a=lf-

Fix #8537.

GIF:
![output](https://user-images.githubusercontent.com/6652840/119501981-45a45c00-bd1e-11eb-8336-9145f2888643.gif)

Co-authored-by: Jade <software@lfcode.ca>
2021-05-25 13:14:34 +00:00
Lukas Wirth
3ee4e6c54c Fix type inference not working for new Try trait 2021-05-25 14:59:54 +02:00
Jade
3e4dfaf97a feat: go to implementation on trait functions
Fix #8537.

GIF:
https://user-images.githubusercontent.com/6652840/119501981-45a45c00-bd1e-11eb-8336-9145f2888643.gif
2021-05-25 05:46:15 -07:00
Florian Diebold
35c948ff4a Fix lowering of FnOnce() without return type
This should result in an implicit `-> ()`, not leaving out the binding.
2021-05-25 14:29:53 +02:00
bors[bot]
835cf55887
Merge #8767
8767: implement range formatting r=matklad a=euclio

Fixes #7580.

This PR implements the `textDocument/rangeFormatting` request using `rustfmt`'s `--file-lines` option.

Still needs some tests. What I want to know is how I should handle the instability of the `--file-lines` option. It's still unstable in rustfmt, so it's only available on nightly, and needs a special flag to enable. Is there a way for `rust-analyzer` to detect if it's using nightly rustfmt, or for users to opt-in?

Co-authored-by: Andy Russell <arussell123@gmail.com>
2021-05-25 12:15:48 +00:00
bors[bot]
b7414fa14a
Merge #8986
8986: Add go to type definition for struct fields within struct r=matklad a=lf-

Example:

```rust
struct A;

struct B {
    a/*<- cursor*/: A,
}
```

Go to type definition used to not work on this position. It now goes to
`A` as expected.

Co-authored-by: Jade <software@lfcode.ca>
2021-05-25 11:25:00 +00:00
Florian Diebold
c33ee36d2a Minor test fixes / new tests 2021-05-25 13:07:18 +02:00
Jade
ff585e4730 Add go to type definition for struct fields within struct
Example:

```rust
struct A;

struct B {
    a/*<- cursor*/: A,
}
```

Go to type definition used to not work on this position. It now goes to
`A` as expected.
2021-05-25 04:06:54 -07:00
Florian Diebold
b26a472ccb Fix type mismatch caused by macros
MacroStmts should be completely transparent, but it prevented
coercion. (I should maybe give `infer_expr` and `infer_expr_inner`
better names.)
2021-05-25 11:15:02 +02:00
bors[bot]
8b049ec393
Merge #8942
8942: Add `library` semantic token modifier to items from other crates r=arzg a=arzg

Closes #5772.

A lot of code here is pretty repetitive; please let me know if you have any ideas how to improve it, or whether it’s fine as-is.

Side-note: How can I add tests for this? I don’t see a way for the test Rust code in `test_highlighting` to reference other crates to observe the new behaviour.


Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-05-25 02:30:47 +00:00
Aramis Razzaghipour
d75277b66b
Refactor application of library semantic token modifier 2021-05-25 12:20:12 +10:00
bors[bot]
6d473c0a8f
Merge #8979
8979: minor: update `CrateGraph` comment r=jonas-schievink a=jonas-schievink

`cfg` flags are now implemented, and crates *may* have names, it doesn't
doesn't matter for name resolution

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-24 22:58:43 +00:00
Jonas Schievink
13b8449a11 Update CrateGraph comment
`cfg` flags are now implemented, and crates *may* have names, it doesn't
doesn't matter for name resolution
2021-05-25 00:56:24 +02:00
Jonas Schievink
31175a7f88 internal: intern AttrInput 2021-05-25 00:50:19 +02:00
bors[bot]
86ca1764b6
Merge #8975
8975: Use todo!() as placeholder body for generated match arms r=matklad a=jDomantas

`todo!()` seems to be a better fit for this than `{}`. Seeing that this assist predates stabilization of `todo` my guess is that simply no one bothered to change it yet.

Also fixed the issue where if the last arm was not block-like, rust-analyzer would not add a comma after it and would generate invalid code.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-05-24 19:59:51 +00:00
bors[bot]
f5f24a9a2c
Merge #8977
8977: internal: minor `TokenMap` cleanups r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-24 19:52:01 +00:00
Jonas Schievink
c8f40b1503 Fixup 2021-05-24 21:47:01 +02:00
Aleksey Kladov
45112aa8c0 internal: rename hypothetical -> speculative
Lets steal this good naming from Roslyn before I forget about it yet
again.
2021-05-24 22:21:25 +03:00
Domantas Jadenkus
3641abc0c3 add test that it does not create extraneous commas 2021-05-24 22:17:16 +03:00
Domantas Jadenkus
8d2e3816bc tidy 2021-05-24 22:17:16 +03:00
Domantas Jadenkus
22e5194396 generate match arms with todo!() as placeholder body 2021-05-24 22:17:16 +03:00
Jonas Schievink
489ae7a800 Make TokenTextRange private 2021-05-24 20:29:48 +02:00
Benjamin Coenen
629ab18994 add support of impl block for doctest into runnables
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-05-24 19:17:25 +02:00
Jonas Schievink
27bf62b70e Move TokenMap to its own file 2021-05-24 18:43:42 +02:00
bors[bot]
3926f60cb5
Merge #8970
8970: fix: duplicate dependencies that have multiple DepKinds r=jonas-schievink a=jonas-schievink

Cargo collapses identical dependencies that are listed under `[dependencies]` and `[build-dependencies]` into a single `NodeDep`. We have to undo that by duplicating the dependency for each of its listed `DepKind`s.

Not doing that would incorrectly treat a dependency as `DepKind::Normal`, even though it is *also* meant to be a `DepKind::Build`.

Fixes https://github.com/rust-analyzer/rust-analyzer/pull/8812#issuecomment-847125395

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-24 16:38:15 +00:00
Jonas Schievink
518d39cd2f Duplicate dependencies that have multiple DepKinds 2021-05-24 18:31:43 +02:00
bors[bot]
c139eff5b8
Merge #8963
8963: Bump deps r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-24 15:34:52 +00:00
Laurențiu Nicola
741f47f208 Update test fixtures 2021-05-24 18:18:05 +03:00
Laurențiu Nicola
b43bc61981 Bump rustc_lexer 2021-05-24 16:39:19 +03:00
Laurențiu Nicola
f1cfbe6ffc Disable unaliged feature of object 2021-05-24 16:35:52 +03:00
Jonas Schievink
533e9207d3 Intern GenericArgs
This shaves off another ~4 mb or so
2021-05-24 15:35:46 +02:00
Laurențiu Nicola
d525cfc85a Bump object 2021-05-24 16:35:23 +03:00
Laurențiu Nicola
47afa4a5fc Bump misc deps 2021-05-24 16:31:54 +03:00
Laurențiu Nicola
74f1b21b08 Bump chalk 2021-05-24 16:27:24 +03:00
Jonas Schievink
8ebb8d29e1 internal: intern TypeBounds
Doesn't save much memory (~2 mb), but interning things is generally a
good pattern to follow
2021-05-24 15:13:23 +02:00
bors[bot]
05fc97e31b
Merge #8955
8955: feature: Support standalone Rust files r=matklad a=SomeoneToIgnore

![standalone](https://user-images.githubusercontent.com/2690773/119277037-0b579380-bc26-11eb-8d77-20d46ab4916a.gif)

Closes https://github.com/rust-analyzer/rust-analyzer/issues/6388

Caveats: 

* I've decided to support multiple detached files in the code (anticipating the scratch files), but I found no way to open multiple files in VSCode at once: running `code *.rs` makes the plugin to register in the `vscode.workspace.textDocuments` only the first file, while code actually displays all files later.
Apparently what happens is the same as when you have VSCode open at some workplace already and then run `code some_other_file.rs`: it gets opened in the same workspace of the same VSCode with no server to support it.
If there's a way to override it, I'd appreciate the pointer.

* No way to toggle inlay hints, since the setting is updated for the workspace (which does not exist for a single file opened)
> [2021-05-24 00:22:49.100] [exthost] [error] Error: Unable to write to Workspace Settings because no workspace is opened. Please open a workspace first and try again.

* No runners/lens to run or check the code are implemented for this mode. 
In theory, we can detect `rustc`, run it on a file and run the resulting binary, but not sure if worth doing it at this stage.

Otherwise imports, hints, completion and other features work.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-05-24 12:40:25 +00:00
Kirill Bulatov
5c0369b1d0 Add a FIXME 2021-05-24 14:52:57 +03:00
Kirill Bulatov
d8c36029cc
Small file error display fix
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-24 14:47:20 +03:00
Aramis Razzaghipour
eca4b764e4
Remove superfluous early-returns 2021-05-24 14:54:48 +10:00
Aramis Razzaghipour
e51188cd09
Rename ‘foreign’ semantic token modifier to ‘library’ 2021-05-24 14:54:48 +10:00
Aramis Razzaghipour
fa0d0bfb7f
Add testing of foreign item highlighting 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
b4cddc0705
Highlight foreign modules as such 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
c32428571c
Remove hir krate methods 2021-05-24 14:54:16 +10:00
Aramis Razzaghipour
4fd5248749
Add highlighting of items from other crates 2021-05-24 14:53:48 +10:00
bors[bot]
495c9586ec
Merge #8945
8945: fix: Make expected type work in more situations r=flodiebold a=flodiebold

Also makes call info show the correct types for generic methods.

![2021-05-23-182952_1134x616_scrot](https://user-images.githubusercontent.com/906069/119269023-dd5a5b00-bbf5-11eb-993a-b6e122c3b9a6.png)
![2021-05-23-183117_922x696_scrot](https://user-images.githubusercontent.com/906069/119269025-dfbcb500-bbf5-11eb-983c-fc415b8428e0.png)


Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-05-23 21:55:51 +00:00
Florian Diebold
b8262099cc Get rid of field_type again 2021-05-23 23:54:35 +02:00
bors[bot]
a2ce091fd7
Merge #8953
8953: feat: generate getter avoids generating types like `&Vec<T>` r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-23 21:17:20 +00:00
Aleksey Kladov
479a7387c2 feat: generate getter avoids generating types like &Vec<T> 2021-05-24 00:15:23 +03:00
Jonas Schievink
693325fc39 internal: document ItemTree design 2021-05-23 23:09:38 +02:00
Kirill Bulatov
b5f524c7ff Don't discover workspaces when detached files are given 2021-05-24 00:09:24 +03:00
bors[bot]
951c0e95f4
Merge #8948
8948: feat: generate getter assist places the cursor at the generated function r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-23 20:48:35 +00:00
Aleksey Kladov
8696c82777 feat: generate getter assist places the cursor at the generated function 2021-05-23 23:43:33 +03:00
Aleksey Kladov
8d5f59e0f1 minor: align import style with styleguide 2021-05-23 23:40:19 +03:00
Kirill Bulatov
72594beca4 Deal with todos 2021-05-23 23:37:59 +03:00
Aleksey Kladov
af54b1e248 minimize tests 2021-05-23 23:19:00 +03:00
Aleksey Kladov
c06599504b remove duplicate tests 2021-05-23 23:15:54 +03:00
Aleksey Kladov
4c8259e210 reduce duplication 2021-05-23 23:13:35 +03:00
Kirill Bulatov
2ca2e24a39 Do not add cargo target for detached files only project 2021-05-23 23:10:05 +03:00
Andy Russell
a90b9a5872
implement range formatting 2021-05-23 15:50:36 -04:00
Kirill Bulatov
de090749d9 Drag detached files towards loading 2021-05-23 22:46:20 +03:00
Kirill Bulatov
695569d978 Draft detached files retrieval 2021-05-23 22:46:20 +03:00
Lukas Tobias Wirth
da74c66947 Correctly resolve crate name in use paths when import shadows itself 2021-05-23 19:37:01 +02:00
Aleksey Kladov
7283163bb9 Minor: fix comment style
See https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#documentation
2021-05-23 19:50:23 +03:00