]>
git.lizzy.rs Git - rust.git/log
Aleksey Kladov [Sat, 28 Aug 2021 19:03:06 +0000 (22:03 +0300)]
internal: improve compilation critical path a bit
Aleksey Kladov [Sat, 28 Aug 2021 17:41:22 +0000 (20:41 +0300)]
remove unused serde feature from smol_str
Aleksey Kladov [Sat, 28 Aug 2021 17:36:41 +0000 (20:36 +0300)]
internal: more production-ready proc-macro RPC deserialization
* avoid arbitrary nested JSON tree (danger of stack overflow)
* use more compact representation.
bors[bot] [Fri, 27 Aug 2021 21:22:35 +0000 (21:22 +0000)]
Merge #10059
10059: feat: Enable diagnostics in `const` and `static` items r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Jonas Schievink [Fri, 27 Aug 2021 21:21:21 +0000 (23:21 +0200)]
Enable diagnostics in `const` and `static` items
bors[bot] [Fri, 27 Aug 2021 20:19:56 +0000 (20:19 +0000)]
Merge #10044
10044: minor: Ignore text and bench attributes again r=Veykril a=Veykril
Reverts part of #9943
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Thu, 26 Aug 2021 13:11:55 +0000 (15:11 +0200)]
Ignore text and bench attributes again
bors[bot] [Fri, 27 Aug 2021 19:30:36 +0000 (19:30 +0000)]
Merge #9970
9970: feat: Implement attribute input token mapping, fix attribute item token mapping r=Veykril a=Veykril
![image](https://user-images.githubusercontent.com/
3757771 /
130328577 -
4c1ad72c -51b1-47c3-8d3d-
3242ec44a355 .png)
The token mapping for items with attributes got overwritten partially by the attributes non-item input, since attributes have two different inputs, the item and the direct input both.
This PR gives attributes a second TokenMap for its direct input. We now shift all normal input IDs by the item input maximum(we maybe wanna swap this see below) similar to what we do for macro-rules/def. For mapping down we then have to figure out whether we are inside the direct attribute input or its item input to pick the appropriate mapping which can be done with some token range comparisons.
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9867
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
bors[bot] [Fri, 27 Aug 2021 18:00:37 +0000 (18:00 +0000)]
Merge #10057
10057: fix: Remove incorrect assertion in extract_function r=Veykril a=Veykril
This assertion is actually just wrong
Fixes #10056
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Fri, 27 Aug 2021 17:58:50 +0000 (19:58 +0200)]
Remove incorrect assertion in extract_function
bors[bot] [Fri, 27 Aug 2021 13:11:34 +0000 (13:11 +0000)]
Merge #10055
10055: fix: Don't use fake text range in original node search as is in completions r=Veykril a=Veykril
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10042
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Fri, 27 Aug 2021 13:10:42 +0000 (15:10 +0200)]
Don't use fake text range in original node search as is in completions
bors[bot] [Fri, 27 Aug 2021 12:21:46 +0000 (12:21 +0000)]
Merge #10054
10054: minor: Ignore text and bench attributes again r=Veykril a=Veykril
cc https://github.com/rust-analyzer/rust-analyzer/issues/8518#issuecomment-
907039593
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Fri, 27 Aug 2021 12:20:32 +0000 (14:20 +0200)]
Add completion tests for cursor after items
bors[bot] [Fri, 27 Aug 2021 09:46:25 +0000 (09:46 +0000)]
Merge #10053
10053: Remove old workaround in vscode extension r=lnicola a=Azorlogh
See #3167.
Co-authored-by: = <bott.alix@gmail.com>
= [Fri, 27 Aug 2021 09:31:25 +0000 (11:31 +0200)]
remove workaround from old node versions
bors[bot] [Thu, 26 Aug 2021 19:14:09 +0000 (19:14 +0000)]
Merge #10049
10049: minor: nicer way to defeat disjoint closure captures r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Thu, 26 Aug 2021 19:11:54 +0000 (22:11 +0300)]
minor: nicer way to defeat disjoint closure captures
Thanks https://internals.rust-lang.org/t/feature-idea-edition-dependent-names-replacing-standard-library-items/15198/27?u=matklad!
bors[bot] [Thu, 26 Aug 2021 09:33:12 +0000 (09:33 +0000)]
Merge #10032
10032: Fix missing unsafe block for the nightly change r=lnicola a=oxalica
Fix #10022
Tested via vscode extension.
Co-authored-by: oxalica <oxalicc@pm.me>
oxalica [Thu, 26 Aug 2021 08:42:45 +0000 (16:42 +0800)]
Fix missing unsafe block for the nightly change
Fix #10022
bors[bot] [Thu, 26 Aug 2021 01:34:30 +0000 (01:34 +0000)]
Merge #10030
10030: fix: Fix multiple derives in one attribute not expanding all in expand_macro r=Veykril a=Veykril
It's probably better to only expand the exact derive the cursor is on(if possible) instead of all derives in the attribute the cursor is one.
follow up to #10029
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Thu, 26 Aug 2021 01:32:34 +0000 (03:32 +0200)]
fix: Fix multiple derives in one attribute not expanding all in expand_macro
bors[bot] [Thu, 26 Aug 2021 00:39:00 +0000 (00:39 +0000)]
Merge #10029
10029: internal: Improve expand_macro r=Veykril a=Veykril
- Adds a few more newlines to the output making it more readable
- Fixes a bug with multiple derives not being expandable
There seems to be an issue with multiple derives in one attribute only showing the expansion of the last derive which I'll have to investigate.
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Thu, 26 Aug 2021 00:36:33 +0000 (02:36 +0200)]
Improve expand_macro
bors[bot] [Wed, 25 Aug 2021 17:40:57 +0000 (17:40 +0000)]
Merge #10024
10024: fix: Fix reporting of build script errors r=matklad a=jonas-schievink
r? `@matklad` (mostly to double-check that the redundant code I removed was, in fact, redundant)
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9864
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10023
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Jonas Schievink [Wed, 25 Aug 2021 16:02:27 +0000 (18:02 +0200)]
Reduce visibility of `WorkspaceBuildScripts::run`
Jonas Schievink [Wed, 25 Aug 2021 15:56:39 +0000 (17:56 +0200)]
Fix reporting of build script errors
Jonas Schievink [Wed, 25 Aug 2021 15:56:24 +0000 (17:56 +0200)]
Don't fetch build script output twice
bors[bot] [Tue, 24 Aug 2021 14:58:02 +0000 (14:58 +0000)]
Merge #10014
10014: feat: Expand derive macros under cursor in `Expand Macro Recursively` r=Veykril a=Veykril
Expands the derive macros under the cursor if it is one a derive attribute, with this the feature should be basically feature complete I believe(except for the whitespace problem ofc)?
Actually this might interact a bit funky with items that have attributes ***and*** derives since we don't descend the cursor token into macro invocations first, for obvious reasons. So I expected trying to expand a derive in that case will either just expand the attributes on the item or fail in general.
Closes https://github.com/rust-analyzer/rust-analyzer/issues/4005
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Tue, 24 Aug 2021 14:33:52 +0000 (16:33 +0200)]
Expand derive macros under cursor in `Expand Macro Recursively`
bors[bot] [Tue, 24 Aug 2021 13:11:50 +0000 (13:11 +0000)]
Merge #9944
9944: internal: introduce in-place indenting API r=matklad a=iDawer
Introduce `edit_in_place::Indent` that uses mutable tree API and intended to replace `edit::AstNodeEdit`.
Closes #9903
Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
bors[bot] [Tue, 24 Aug 2021 12:14:25 +0000 (12:14 +0000)]
Merge #9993
9993: feat: join lines merges assignments r=matklad a=unexge
Closes https://github.com/rust-analyzer/rust-analyzer/issues/9967.
![Peek 2021-08-22 21-46](https://user-images.githubusercontent.com/
16212576 /
130366571 -
3ebb1753 -f8d5-4884-be8f-
222cda71a2a7 .gif)
Co-authored-by: unexge <unexge@gmail.com>
bors[bot] [Tue, 24 Aug 2021 11:39:49 +0000 (11:39 +0000)]
Merge #10011
10011: minor: remove dead code r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Tue, 24 Aug 2021 11:39:31 +0000 (14:39 +0300)]
minor: remove dead code
bors[bot] [Tue, 24 Aug 2021 11:10:09 +0000 (11:10 +0000)]
Merge #10010
10010: internal: use idiomatic form of assertions r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Tue, 24 Aug 2021 10:13:38 +0000 (13:13 +0300)]
internal: use idiomatic form of assertions
Ideally, we should just return an InvalidParameter dialog here, but that
shows error message to the end user, and we generally avoid that
bors[bot] [Tue, 24 Aug 2021 09:26:52 +0000 (09:26 +0000)]
Merge #9994
9994: add static method generation assist r=matklad a=mahdi-frms
Adds feature: #9948
Will soon send a GIF for the changelog.
Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
bors[bot] [Tue, 24 Aug 2021 01:16:44 +0000 (01:16 +0000)]
Merge #10008
10008: feat: Highlight declarations and references for both defs in field shorthands r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Tue, 24 Aug 2021 01:14:03 +0000 (03:14 +0200)]
Highlight declarations and references for both defs in field shorthands
bors[bot] [Mon, 23 Aug 2021 22:19:50 +0000 (22:19 +0000)]
Merge #10001
10001: Sort enum variant r=Veykril a=vsrs
A small fix to the problem noted by `@lnicola` :
> ![sort-fields](https://user-images.githubusercontent.com/308347/
129513196 -
4ffc7937 -be58-44d4-9ec7-
ba8745dcb460 .gif)
>
> (note the slight inconsistency here: to sort the variants of `Animal` I have to select the enum name, but to sort the fields of `Cat` I have to select the fields themselves)
Co-authored-by: vsrs <vit@conrlab.com>
bors[bot] [Mon, 23 Aug 2021 21:23:17 +0000 (21:23 +0000)]
Merge #10004
10004: ⬆️ rowan r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Mon, 23 Aug 2021 21:22:31 +0000 (23:22 +0200)]
⬆️ rowan
bors[bot] [Mon, 23 Aug 2021 18:19:42 +0000 (18:19 +0000)]
Merge #10003
10003: :arrow_up: rowan r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Mon, 23 Aug 2021 18:07:23 +0000 (21:07 +0300)]
:arrow_up: rowan
This pulls in https://github.com/rust-analyzer/rowan/pull/111, which
fixes a bug in green node hash, making it more efficient.
On analysis stats, total memory goes from 1271mb to 1244mb, instructions
from 358ginstr to 353ginstr (not 100% clear on this one -- for some
reasons instruction counts are not stable for me anymore).
The counts are (before, than after):
rowan::green::node::GreenNode 11_490_596 2_357_063 2_233_347
rowan::green::token::GreenToken 5_010_401 994_281 991_920
rowan::green::node::GreenNode 9_738_085 1_988_164 1_890_549
rowan::green::token::GreenToken 3_353_409 687_333 685_831
total max_live live
vsrs [Mon, 23 Aug 2021 17:31:54 +0000 (20:31 +0300)]
Sort enum variant
bors[bot] [Mon, 23 Aug 2021 13:41:12 +0000 (13:41 +0000)]
Merge #9999
9999: internal: use single env var to controll all benchmarks r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Mon, 23 Aug 2021 13:39:38 +0000 (16:39 +0300)]
internal: use single env var to controll all benchmarks
bors[bot] [Mon, 23 Aug 2021 10:27:21 +0000 (10:27 +0000)]
Merge #9998
9998: Bump deps r=lnicola a=lnicola
bors r+
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Laurențiu Nicola [Mon, 23 Aug 2021 10:25:59 +0000 (13:25 +0300)]
Bump deps
bors[bot] [Mon, 23 Aug 2021 09:11:32 +0000 (09:11 +0000)]
Merge #9995
9995: :arrow_up: rowan r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Mon, 23 Aug 2021 09:10:49 +0000 (12:10 +0300)]
:arrow_up: rowan
Just so we don't live on a per-release
mahdi-frms [Mon, 23 Aug 2021 07:30:10 +0000 (12:00 +0430)]
add static method generation assist
unexge [Sun, 22 Aug 2021 18:28:39 +0000 (21:28 +0300)]
feat: join lines merges assignments
Lukas Wirth [Sun, 22 Aug 2021 17:12:45 +0000 (19:12 +0200)]
Respect attributes in Hygiene token up-mapping
bors[bot] [Sun, 22 Aug 2021 16:10:48 +0000 (16:10 +0000)]
Merge #9989
9989: Fix two more “a”/“an” typos (this time the other way) r=lnicola a=steffahn
Follow-up to #9987
you guys are still merging these fast :sweat_smile:
_this time I thought – for sure – that I’d get this commit into #9987 before it’s merged…_
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
Frank Steffahn [Sun, 22 Aug 2021 15:48:15 +0000 (17:48 +0200)]
Fix three more (reverse) “a”/“an” typos
bors[bot] [Sun, 22 Aug 2021 15:37:06 +0000 (15:37 +0000)]
Merge #9988
9988: fix: Refactor & improve handling of overloaded binary operators r=flodiebold a=flodiebold
Fixes #9971. Also records them as method resolutions, which we could use later.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Frank Steffahn [Sun, 22 Aug 2021 15:35:52 +0000 (17:35 +0200)]
Fix two more “a”/“an” typos (this time the other way)
Florian Diebold [Sun, 22 Aug 2021 15:21:47 +0000 (17:21 +0200)]
Refactor & improve handling of overloaded binary operators
Fixes #9971. Also records them as method resolutions, which we could use
later.
bors[bot] [Sun, 22 Aug 2021 15:27:39 +0000 (15:27 +0000)]
Merge #9987
9987: Fix two more “a”/“an” typos r=lnicola a=steffahn
Follow-up to #9985
you guys are merging these fast 😅
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
Frank Steffahn [Sun, 22 Aug 2021 15:23:45 +0000 (17:23 +0200)]
Fix two more “a”/“an” typos
bors[bot] [Sun, 22 Aug 2021 15:01:15 +0000 (15:01 +0000)]
Merge #9937 #9985
9937: internal: incentivize rust-analyzed developers to fix panics r=matklad a=matklad
9985: minor: Fix another “a”/“an” typo r=Veykril a=steffahn
Follow-up to #9984.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
Aleksey Kladov [Sun, 22 Aug 2021 14:41:09 +0000 (17:41 +0300)]
internal: incentivize rust-analyzed developers to fix panics
It's good that rust-analyzer doesn't belly-up on a panic in some random
assist.
It is less good that rust-analyzer devs only know that the assists are
buggy when they are actively looking at the logs.
bors[bot] [Sun, 22 Aug 2021 14:53:41 +0000 (14:53 +0000)]
Merge #9972
9972: refactor : function generation assists r=Veykril a=mahdi-frms
Separated code generation from finding position for generated code. This will be ground work for introducing static associated function generation.
Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
Frank Steffahn [Sun, 22 Aug 2021 14:45:58 +0000 (16:45 +0200)]
Fix another “a”/“an” typo
bors[bot] [Sun, 22 Aug 2021 13:06:34 +0000 (13:06 +0000)]
Merge #9984
9984: Fix typos “a”→“an” r=Veykril a=steffahn
See rust-lang/rust#88230
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
Frank Steffahn [Sun, 22 Aug 2021 12:31:37 +0000 (14:31 +0200)]
Fix typos “a”→“an”
bors[bot] [Sun, 22 Aug 2021 12:25:18 +0000 (12:25 +0000)]
Merge #9979
9979: fix: Incorrect up-mapping for tokens in derive attributes r=Veykril a=Veykril
Merely detaching the attributes causes incorrect spans to appear when mapping tokens up as the token ids resolve to the ranges of the stripped item so all the text ranges of its tokens are actually lower than the non-stripped ones.
Same fix as with attributes can be applied here, just replace the derive attribute with an equal amount of whitespace.
Fixes #9387
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Sat, 21 Aug 2021 23:43:28 +0000 (01:43 +0200)]
Replace stripped derives with whitespace in process_macro_input
bors[bot] [Sun, 22 Aug 2021 11:06:07 +0000 (11:06 +0000)]
Merge #9983
9983: internal: remove unreasonable crate dependency r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Sun, 22 Aug 2021 11:05:12 +0000 (14:05 +0300)]
internal: remove unreasonable crate dependency
Proc macro expansion shouldn't know about salsa at all.
bors[bot] [Sun, 22 Aug 2021 10:45:01 +0000 (10:45 +0000)]
Merge #9982
9982: internal: reduce crate interdependence r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Aleksey Kladov [Sun, 22 Aug 2021 10:32:00 +0000 (13:32 +0300)]
internal: reduce crate interdependence
I don't think there's anything wrong with project_model depending on
proc_macro_api directly -- fundamentally, both are about gluing our pure
data model to the messy outside world.
However, it's easy enough to avoid the dependency, so why not.
As an additional consideration, `proc_macro_api` now pulls in `base_db`.
project_model should definitely not depend on that!
Aleksey Kladov [Sun, 22 Aug 2021 10:15:18 +0000 (13:15 +0300)]
internal: improve consistency
load and load_proc_macro do similar things
mahdi-frms [Sun, 22 Aug 2021 08:01:16 +0000 (12:31 +0430)]
better assist label
bors[bot] [Sat, 21 Aug 2021 21:26:00 +0000 (21:26 +0000)]
Merge #9978
9978: fix: Expand attributes recursively in expand_macro r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Sat, 21 Aug 2021 21:24:12 +0000 (23:24 +0200)]
Expand attributes recursively in expand_macro
bors[bot] [Sat, 21 Aug 2021 18:45:50 +0000 (18:45 +0000)]
Merge #9976
9976: fix: Do not show functional update completion when already qualified r=Veykril a=Veykril
Fixes #9964
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Sat, 21 Aug 2021 18:45:15 +0000 (20:45 +0200)]
fix: Do not show functional update completion when already qualified
bors[bot] [Sat, 21 Aug 2021 18:07:36 +0000 (18:07 +0000)]
Merge #9975
9975: minor: Fix panic caused by #9966 r=flodiebold a=flodiebold
Chalk can introduce new type variables when doing lazy normalization, so we have to do the proper 'fudging' after all.
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Florian Diebold [Sat, 21 Aug 2021 17:47:06 +0000 (19:47 +0200)]
Fix panic caused by #9966
Chalk can introduce new type variables when doing lazy normalization, so
we have to do the proper 'fudging' after all.
Lukas Wirth [Sat, 21 Aug 2021 16:19:18 +0000 (18:19 +0200)]
Remove MappedSubtree
Lukas Wirth [Sat, 21 Aug 2021 16:06:03 +0000 (18:06 +0200)]
Map attribute input tokens correctly
bors[bot] [Sat, 21 Aug 2021 16:10:04 +0000 (16:10 +0000)]
Merge #9973
9973: Handle coercion on binary operator RHS r=flodiebold a=lnicola
Closes #9968
CC #8961
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Laurențiu Nicola [Sat, 21 Aug 2021 14:54:45 +0000 (17:54 +0300)]
Handle coercion on binary operator RHS
mahdi-frms [Sat, 21 Aug 2021 14:28:29 +0000 (18:58 +0430)]
func gen: seperate generation form position(3)
bors[bot] [Sat, 21 Aug 2021 13:41:09 +0000 (13:41 +0000)]
Merge #9908
9908: fix check of the toolchain's path r=lnicola a=gfreezy
fixed #9907
Co-authored-by: Alex.F <gfreezy@gmail.com>
mahdi-frms [Sat, 21 Aug 2021 13:01:37 +0000 (17:31 +0430)]
func gen: seperate generation form position(2)
bors[bot] [Sat, 21 Aug 2021 12:35:26 +0000 (12:35 +0000)]
Merge #9966
9966: fix: Determine expected parameters from expected return in calls r=flodiebold a=flodiebold
Second attempt :sweat_smile:
Fixes #9560
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Florian Diebold [Thu, 15 Jul 2021 18:02:58 +0000 (20:02 +0200)]
Determine expected parameters from expected return in calls
Fixes #9560
Florian Diebold [Thu, 15 Jul 2021 18:02:48 +0000 (20:02 +0200)]
Adapt tests for correct behavior
Florian Diebold [Thu, 5 Aug 2021 18:32:07 +0000 (20:32 +0200)]
Add another test
bors[bot] [Sat, 21 Aug 2021 10:56:09 +0000 (10:56 +0000)]
Merge #9965
9965: minor: Don't ask for the builtin attribute input twice r=Veykril a=Veykril
`tt` and `item` here were the same, I misunderstood what the main input for attributes was in #9943
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Lukas Wirth [Sat, 21 Aug 2021 10:55:05 +0000 (12:55 +0200)]
Don't ask for the builtin attribute input twice
bors[bot] [Sat, 21 Aug 2021 10:12:17 +0000 (10:12 +0000)]
Merge #9962
9962: Add empty-body check to replace_match_with_if_let and re-prioritize choices r=elkowar a=elkowar
This PR changes some behaviour of the `replace_match_with_if_let` ide-assist.
Concretely, it makes two changes:
it introduces a check for empty expression bodies. This means that checks of the shape
```rs
match x {
A => {}
B => {
println!("hi");
}
}
```
will prefer to use the B branch as the first (and only) variant.
It also reprioritizes the importance of "happy" and "sad" patterns.
Concretely, if there are reasons to prefer having the sad pattern be the first (/only) pattern,
it will follow these.
This means that in the case of
```rs
match x {
Ok(_) => {
println!("Success");
}
Err(e) => {
println!("Failure: {}", e);
}
}
```
the `Err` variant will correctly be used as the first expression in the generated if.
Up until now, the generated code was actually invalid, as it would generate
```rs
if let Ok(_) = x {
println!("Success");
} else {
println!("Failure: {}", e);
}
```
where `e` in the else branch is not defined.
Co-authored-by: elkowar <5300871+elkowar@users.noreply.github.com>
elkowar [Sat, 21 Aug 2021 10:02:21 +0000 (12:02 +0200)]
Fix smaller nitpicks
elkowar [Sat, 21 Aug 2021 09:11:27 +0000 (11:11 +0200)]
Use NameClass::classify to check for ConstReference
elkowar [Sat, 21 Aug 2021 09:00:43 +0000 (11:00 +0200)]
Add heuristic to determine type of IdentPat, make check for empty expressions correct
mahdi-frms [Sat, 21 Aug 2021 08:59:15 +0000 (13:29 +0430)]
func gen: seperate generation form position(1)
mahdi-frms [Sat, 21 Aug 2021 07:22:07 +0000 (11:52 +0430)]
simplify