]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoMerge #10054
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>
2 years agoAdd completion tests for cursor after items
Lukas Wirth [Fri, 27 Aug 2021 12:20:32 +0000 (14:20 +0200)]
Add completion tests for cursor after items

2 years agoMerge #10053
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>
2 years agoremove workaround from old node versions
= [Fri, 27 Aug 2021 09:31:25 +0000 (11:31 +0200)]
remove workaround from old node versions

2 years agoMerge #10049
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>
2 years agominor: nicer way to defeat disjoint closure captures
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!

2 years agoMerge #10032
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>
2 years agoFix missing unsafe block for the nightly change
oxalica [Thu, 26 Aug 2021 08:42:45 +0000 (16:42 +0800)]
Fix missing unsafe block for the nightly change

Fix #10022

2 years agoMerge #10030
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>
2 years agofix: Fix multiple derives in one attribute not expanding all in expand_macro
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

2 years agoMerge #10029
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>
2 years agoImprove expand_macro
Lukas Wirth [Thu, 26 Aug 2021 00:36:33 +0000 (02:36 +0200)]
Improve expand_macro

2 years agoMerge #10024
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>
2 years agoReduce visibility of `WorkspaceBuildScripts::run`
Jonas Schievink [Wed, 25 Aug 2021 16:02:27 +0000 (18:02 +0200)]
Reduce visibility of `WorkspaceBuildScripts::run`

2 years agoFix reporting of build script errors
Jonas Schievink [Wed, 25 Aug 2021 15:56:39 +0000 (17:56 +0200)]
Fix reporting of build script errors

2 years agoDon't fetch build script output twice
Jonas Schievink [Wed, 25 Aug 2021 15:56:24 +0000 (17:56 +0200)]
Don't fetch build script output twice

2 years agoMerge #10014
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>
2 years agoExpand derive macros under cursor in `Expand Macro Recursively`
Lukas Wirth [Tue, 24 Aug 2021 14:33:52 +0000 (16:33 +0200)]
Expand derive macros under cursor in `Expand Macro Recursively`

2 years agoMerge #9944
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>
2 years agoMerge #9993
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>
2 years agoMerge #10011
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>
2 years agominor: remove dead code
Aleksey Kladov [Tue, 24 Aug 2021 11:39:31 +0000 (14:39 +0300)]
minor: remove dead code

2 years agoMerge #10010
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>
2 years agointernal: use idiomatic form of assertions
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

2 years agoMerge #9994
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>
2 years agoMerge #10008
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>
2 years agoHighlight declarations and references for both defs in field shorthands
Lukas Wirth [Tue, 24 Aug 2021 01:14:03 +0000 (03:14 +0200)]
Highlight declarations and references for both defs in field shorthands

2 years agoMerge #10001
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>
2 years agoMerge #10004
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>
2 years ago⬆️ rowan
Lukas Wirth [Mon, 23 Aug 2021 21:22:31 +0000 (23:22 +0200)]
⬆️ rowan

2 years agoMerge #10003
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>
2 years ago:arrow_up: rowan
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

2 years agoSort enum variant
vsrs [Mon, 23 Aug 2021 17:31:54 +0000 (20:31 +0300)]
Sort enum variant

2 years agoMerge #9999
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>
2 years agointernal: use single env var to controll all benchmarks
Aleksey Kladov [Mon, 23 Aug 2021 13:39:38 +0000 (16:39 +0300)]
internal: use single env var to controll all benchmarks

2 years agoMerge #9998
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>
2 years agoBump deps
Laurențiu Nicola [Mon, 23 Aug 2021 10:25:59 +0000 (13:25 +0300)]
Bump deps

2 years agoMerge #9995
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>
2 years ago:arrow_up: rowan
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

2 years agoadd static method generation assist
mahdi-frms [Mon, 23 Aug 2021 07:30:10 +0000 (12:00 +0430)]
add static method generation assist

2 years agofeat: join lines merges assignments
unexge [Sun, 22 Aug 2021 18:28:39 +0000 (21:28 +0300)]
feat: join lines merges assignments

2 years agoMerge #9989
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>
2 years agoFix three more (reverse) “a”/“an” typos
Frank Steffahn [Sun, 22 Aug 2021 15:48:15 +0000 (17:48 +0200)]
Fix three more (reverse) “a”/“an” typos

2 years agoMerge #9988
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>
2 years agoFix two more “a”/“an” typos (this time the other way)
Frank Steffahn [Sun, 22 Aug 2021 15:35:52 +0000 (17:35 +0200)]
Fix two more “a”/“an” typos (this time the other way)

2 years agoRefactor & improve handling of overloaded binary operators
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.

2 years agoMerge #9987
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>
2 years agoFix two more “a”/“an” typos
Frank Steffahn [Sun, 22 Aug 2021 15:23:45 +0000 (17:23 +0200)]
Fix two more “a”/“an” typos

2 years agoMerge #9937 #9985
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>
2 years agointernal: incentivize rust-analyzed developers to fix panics
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.

2 years agoMerge #9972
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>
2 years agoFix another “a”/“an” typo
Frank Steffahn [Sun, 22 Aug 2021 14:45:58 +0000 (16:45 +0200)]
Fix another “a”/“an” typo

2 years agoMerge #9984
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>
2 years agoFix typos “a”→“an”
Frank Steffahn [Sun, 22 Aug 2021 12:31:37 +0000 (14:31 +0200)]
Fix typos “a”→“an”

2 years agoMerge #9979
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>
2 years agoReplace stripped derives with whitespace in process_macro_input
Lukas Wirth [Sat, 21 Aug 2021 23:43:28 +0000 (01:43 +0200)]
Replace stripped derives with whitespace in process_macro_input

2 years agoMerge #9983
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>
2 years agointernal: remove unreasonable crate dependency
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.

2 years agoMerge #9982
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>
2 years agointernal: reduce crate interdependence
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!

2 years agointernal: improve consistency
Aleksey Kladov [Sun, 22 Aug 2021 10:15:18 +0000 (13:15 +0300)]
internal: improve consistency

load and load_proc_macro do similar things

2 years agobetter assist label
mahdi-frms [Sun, 22 Aug 2021 08:01:16 +0000 (12:31 +0430)]
better assist label

2 years agoMerge #9978
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>
2 years agoExpand attributes recursively in expand_macro
Lukas Wirth [Sat, 21 Aug 2021 21:24:12 +0000 (23:24 +0200)]
Expand attributes recursively in expand_macro

2 years agoMerge #9976
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>
2 years agofix: Do not show functional update completion when already qualified
Lukas Wirth [Sat, 21 Aug 2021 18:45:15 +0000 (20:45 +0200)]
fix: Do not show functional update completion when already qualified

2 years agoMerge #9975
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>
2 years agoFix panic caused by #9966
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.

2 years agoMerge #9973
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>
2 years agoHandle coercion on binary operator RHS
Laurențiu Nicola [Sat, 21 Aug 2021 14:54:45 +0000 (17:54 +0300)]
Handle coercion on binary operator RHS

2 years agofunc gen: seperate generation form position(3)
mahdi-frms [Sat, 21 Aug 2021 14:28:29 +0000 (18:58 +0430)]
func gen: seperate generation form position(3)

2 years agoMerge #9908
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>
2 years agofunc gen: seperate generation form position(2)
mahdi-frms [Sat, 21 Aug 2021 13:01:37 +0000 (17:31 +0430)]
func gen: seperate generation form position(2)

2 years agoMerge #9966
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>
2 years agoDetermine expected parameters from expected return in calls
Florian Diebold [Thu, 15 Jul 2021 18:02:58 +0000 (20:02 +0200)]
Determine expected parameters from expected return in calls

Fixes #9560

2 years agoAdapt tests for correct behavior
Florian Diebold [Thu, 15 Jul 2021 18:02:48 +0000 (20:02 +0200)]
Adapt tests for correct behavior

2 years agoAdd another test
Florian Diebold [Thu, 5 Aug 2021 18:32:07 +0000 (20:32 +0200)]
Add another test

2 years agoMerge #9965
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>
2 years agoDon't ask for the builtin attribute input twice
Lukas Wirth [Sat, 21 Aug 2021 10:55:05 +0000 (12:55 +0200)]
Don't ask for the builtin attribute input twice

2 years agoMerge #9962
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>
2 years agoFix smaller nitpicks
elkowar [Sat, 21 Aug 2021 10:02:21 +0000 (12:02 +0200)]
Fix smaller nitpicks

2 years agoUse NameClass::classify to check for ConstReference
elkowar [Sat, 21 Aug 2021 09:11:27 +0000 (11:11 +0200)]
Use NameClass::classify to check for ConstReference

2 years agoAdd heuristic to determine type of IdentPat, make check for empty expressions correct
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

2 years agofunc gen: seperate generation form position(1)
mahdi-frms [Sat, 21 Aug 2021 08:59:15 +0000 (13:29 +0430)]
func gen: seperate generation form position(1)

2 years agosimplify
mahdi-frms [Sat, 21 Aug 2021 07:22:07 +0000 (11:52 +0430)]
simplify

2 years agoMerge #9963
bors[bot] [Fri, 20 Aug 2021 14:02:08 +0000 (14:02 +0000)]
Merge #9963

9963: fix: resolve core::arch module r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 years agofix: resolve core::arch module
Aleksey Kladov [Fri, 20 Aug 2021 13:56:02 +0000 (16:56 +0300)]
fix: resolve core::arch module

See https://users.rust-lang.org/t/rust-analyzer-unable-to-resolve-target-specific-module/63797/4?u=matklad

The fix is to put all sysroot crates into the same source root

2 years agoAdd empty-body check to replace_match_with_if_let and re-prioritize choices
elkowar [Fri, 20 Aug 2021 13:20:54 +0000 (15:20 +0200)]
Add empty-body check to replace_match_with_if_let and re-prioritize choices

2 years agoMerge #9961
bors[bot] [Fri, 20 Aug 2021 13:20:43 +0000 (13:20 +0000)]
Merge #9961

9961: internal: prep to 2021 edition r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 years agointernal: prep to 2021 edition
Aleksey Kladov [Fri, 20 Aug 2021 13:20:18 +0000 (16:20 +0300)]
internal: prep to 2021 edition

2 years agoMerge #9960
bors[bot] [Fri, 20 Aug 2021 12:36:36 +0000 (12:36 +0000)]
Merge #9960

9960: internal: Use ExpandResult in all TokenExpanders r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoSwitch AstDatabase::exapnd_proc_macro to ExpandResult
Lukas Wirth [Fri, 20 Aug 2021 12:34:46 +0000 (14:34 +0200)]
Switch AstDatabase::exapnd_proc_macro to ExpandResult

2 years agoSwitch BuiltinDeriveExpander::expand to ExpandResult
Lukas Wirth [Fri, 20 Aug 2021 12:28:36 +0000 (14:28 +0200)]
Switch BuiltinDeriveExpander::expand to ExpandResult

2 years agoMerge #9943
bors[bot] [Fri, 20 Aug 2021 11:57:28 +0000 (11:57 +0000)]
Merge #9943

9943: fix: Do not replace items annotated with builtin attrs with the attr input r=Veykril a=Veykril

This causes runnables to work for paths that actually resolve to the `test` attribute now.
![Code_aUhX1KQfw3](https://user-images.githubusercontent.com/3757771/129917168-bd9ed3f8-3a08-49d2-930a-4b93efaa8acf.png)

Prior to this we replaced items annotated with builtin attributes by the attribute input instead of the item in our dummy expansion which is why the fully written path didn't work as we actually discarded the item while `test` was just ignored.

Fixes #9935

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoUse correct HirFileId in find_related_test
Lukas Wirth [Fri, 20 Aug 2021 11:49:28 +0000 (13:49 +0200)]
Use correct HirFileId in find_related_test

2 years agoFix runnables not seeing test and bench attributes
Lukas Wirth [Wed, 18 Aug 2021 14:30:09 +0000 (16:30 +0200)]
Fix runnables not seeing test and bench attributes

2 years agoDo not replace items annotated with builtin attrs with the attr input
Lukas Wirth [Wed, 18 Aug 2021 13:35:14 +0000 (15:35 +0200)]
Do not replace items annotated with builtin attrs with the attr input

2 years agoMerge #9955
bors[bot] [Thu, 19 Aug 2021 22:13:09 +0000 (22:13 +0000)]
Merge #9955

9955: fix: Rename fails on renaming definitions created by macros instead of renaming the macro invocation r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoRename fails on renaming definitions created by macros
Lukas Wirth [Thu, 19 Aug 2021 20:53:00 +0000 (22:53 +0200)]
Rename fails on renaming definitions created by macros

2 years agoMerge #9855
bors[bot] [Thu, 19 Aug 2021 15:19:06 +0000 (15:19 +0000)]
Merge #9855

9855: feature: Destructure Tuple Assist r=Veykril a=Booksbaum

Part of #8673. This PR only handles tuples, not TupleStruct and RecordStruct.

Code Assist to destructure a tuple into its items:
![Destructure_Tuple_Assist](https://user-images.githubusercontent.com/15612932/129020107-775d7c94-dca7-4d1f-a0a2-cd63cabf4132.gif)

* Should work in nearly all pattern positions, like let assignment, function parameters, match arms, for loops, and nested variables (`if let Some($0t) = Some((1,2))`)
  -> everywhere `IdentPat` is allowed
  * Exception: If there's a sub-pattern (``@`):`
    ```rust
    if let t @ (1..=3, 1..=3) = ... {}
    //     ^
    ```
    -> `t` must be a `Name`; `TuplePat` (`(_0, _1)`) isn't allowed
    * inside subpattern is ok:
      ```rust
      let t @ (a, _) = ((1,2), 3);
      //       ^
      ```
      ->
      ```rust
      let t @ ((_0, _1), _) = ((1,2), 3);
      ```
* Assist triggers only at tuple declaration, not tuple usage.
  (might be useful especially when it creates a sub-pattern (after ``@`)` and only changes the usage under cursor -- but not part of this PR).

### References
References can be destructured:
```rust
let t = &(1,2);
//  ^
let v = t.0;
```
->
```rust
let (_0, _1) = &(1,2);
let v = _0;
```
BUT: `t.0` and `_0` have different types (`i32` vs. `&i32`) -> `v` has now a different type.

I think that's acceptable: I think the destructure assist is mostly used in simple, immediate scopes and not huge existing code.

Additional Notes:
* `ref` has same behaviour (-> `ref` is kept for items)
  ```rust
  let ref t = (1,2);
  //      ^
  ```
  ->
  ```rust
  let (ref _0, ref _1) = (1,2);
  ```
* Rust IntelliJ Plugin: doesn't trigger with `&` or `ref` at all

### mutable
```rust
let mut t = (1,2);
//      ^
```
->
```rust
let (mut _0, mut _1) = (1,2);
```
and
```rust
let t = &mut (1,2);
//  ^
```
->
```rust
let (_0, _1) = &mut (1,2);
```
Again: with reference (`&mut`), `t.0` and `_0` have different types (`i32` vs `&mut i32`).
And there's an additional issue with `&mut` and assignment:
```rust
let t = &mut (1,2);
//  ^
t.0 = 9;
```
->
```rust
let (_0, _1) = &mut (1,2);
_0 = 9;
//   ^
//   mismatched types
//   expected `&mut {integer}`, found integer
//   consider dereferencing here to assign to the mutable borrowed piece of memory
```
But I think that's quite a niche use case, so I don't catch that (`*_0 = 9;`)

Additional Notes:
* Rust IntelliJ Plugin: removes the `mut` (`let mut t = ...` -> `let (_0, _1) = ...`), doesn't trigger with `&mut`

### Binding after ``@``
Destructure tuple in sub-pattern is implemented:
```rust
let t = (1,2);
//  ^
let v = t.0;
let f = t.into();
```
->
```rust
let t @ (_0, _1) = (1,2);
let v = _0;
let f = t.into();
```
BUT: Bindings after ``@`` aren't currently in stable and require `#![feature(bindings_after_at)]` (though should be generally [available quite soon](https://github.com/rust-lang/rust/pull/85305#event-5072889913) (with `1.56.0`)).
But I don't know how to check for an enabled feature -> Destructure tuple in sub-pattern [isn't enabled](https://github.com/Booksbaum/rust-analyzer/blob/a4ee6c7954f910da3ca74fc0e25edda9077ad184/crates/ide_assists/src/handlers/destructure_tuple_binding.rs#L32) yet.

* When Destructure in sub-pattern is enabled there are two assists:
  * `Destructure tuple in place`:
    ```rust
    let t = (1,2);
    //  ^
    ```
    ->
    ```rust
    let (_0, _1) = (1,2);
    let v = _0;
    let f = /*t*/.into();
    ```
  * `Destructure tuple in sub-pattern`:
    ```rust
    let t = (1,2);
    //  ^
    let v = t.0;
    let f = t.into();
    ```
    ->
    ```rust
    let t @ (_0, _1) = (1,2);
    let v = _0;
    let f = t.into();
    ```
* When Destructure in sub-pattern is disabled, only the first one is available and just named `Destructure tuple`

<br/>
<br/>

### Caveats
* Unlike in #8673 or IntelliJ rust plugin, I'm not leaving the previous tuple name at function calls.
  **Reasoning**: It's not too unlikely the tuple variable shadows another variable. Destructuring the tuple while leaving the function call untouched, results in still a valid function call -- but now with another variable:
  ```rust
  let t = (8,9);
  let t = (1,2);
  //  ^
  t.into()
  ```
  => Destructure Tuple
  ```rust
  let t = (8,9);
  let (_0, _1) = (1,2);
  t.into()
  ```
  `t.into()` is still valid -- using the first tuple.
  Instead I comment out the tuple usage, which results in invalid code -> must be handled by user:
  ```rust
  /*t*/.into()
  ```
  * (though that might be a biased decision: For testing I just declared a lot of `t`s and quite ofen in lines next to each other...)
  * Issue: there are some cases that results in still valid code:
    * macro that accept the tuple as well as no arguments:
      ```rust
      macro_rules! m {
          () => { "foo" };
          ($e:expr) => { $e; "foo" };
      }
      let t = (1,2);
      m!(t);
      m!(/*t*/);
      ```
      -> both calls are valid ([test](https://github.com/Booksbaum/rust-analyzer/blob/a4ee6c7954f910da3ca74fc0e25edda9077ad184/crates/ide_assists/src/handlers/destructure_tuple_binding.rs#L1474))
    * Probably with tuple as return value. Changing the return value most likely results in an error -- but in another place; not where the tuple usage was.

  -> not sure that's the best way....
  Additional the tuple name surrounded by comment is more difficult to edit than just the name.
* Code Assists don't support snippet placeholder, and rust analyzer just the first `$0` -> unfortunately no editing of generated tuple item variables. Cursor (`$0`) is placed on first generated item.

<br/>
<br/>

### Issues
* Tuple index usage in macro calls aren't converted:
  ```rust
  let t = (1,2);
  //  ^
  let v = t.0;
  println!("{}", t.0);
  ```
  ->
  ```rust
  let (_0, _1) = (1,2);
  let v = _0;
  println!("{}", /*t*/.0);
  ```
  ([tests](https://github.com/Booksbaum/rust-analyzer/blob/a4ee6c7954f910da3ca74fc0e25edda9077ad184/crates/ide_assists/src/handlers/destructure_tuple_binding.rs#L1294))
  * Issue is:
    [name.syntax()](https://github.com/Booksbaum/rust-analyzer/blob/a4ee6c7954f910da3ca74fc0e25edda9077ad184/crates/ide_assists/src/handlers/destructure_tuple_binding.rs#L242-L244) in each [usage](https://github.com/Booksbaum/rust-analyzer/blob/a4ee6c7954f910da3ca74fc0e25edda9077ad184/crates/ide_assists/src/handlers/destructure_tuple_binding.rs#L108-L113) of a tuple is syntax & text_range in its file.
    EXCEPT when tuple usage is in a macro call (`m!(t.0)`), the macro is expanded and syntax (and range) is based on that expanded macro, not in actual file.
    That leads to several things:
    * I cannot differentiate between calling the macro with the tuple or with tuple item:
      ```rust
      macro_rules! m {
          ($t:expr, $i:expr) => { $t.0 + $i };
      }
      let t = (1,2);
      m!(t, t.0);
      ```
      -> both `t` usages are resolved as tuple index usage
    * Range of resolved tuple index usage is in expanded macro, not in actual file
     -> don't know where to replace index usage

    -> tuple items passed into a macro are ignored, and only the tuple name itself is handled (uncommented)
* I'm not checking if the generated names conflict with already existing variables.
  ```rust
  let _0 = 42;            // >-|
  let t = (1,2);          //   |
  let v = _0;             // <-|
  //  ^ 42
  ```
  => deconstruct tuple
  ```rust
  let _0 = 42;
  let (_0, _1) = (1,2);     // >-|
  let v = _0;               // <-|
  //  ^ now 1
  ```
  * I tried to get the scope at tuple declaration and its usages. And then iterate all names with [`process_all_names`](https://github.com/rust-analyzer/rust-analyzer/blob/145b51f9daf5371f1754c09eb2e3a77e0a24a0dc/crates/hir/src/semantics.rs#L935). But that doesn't find all local names for declarations (`let t = (1,2)`) (for usages it does)
  * This isn't unique to this Code Assist, but happen in others too (like `extract into variable` or `extract into function`). But here a name conflict is more likely (when destructuring multiple tuples, for examples nested ones (`let t = ((1,2),3)` -> `let (_0, _1) = ...` -> `let ((_0, _1), _1) = ...` -> error))
  * IntelliJ rust plugin does handle this (-> name is `_00`)

Co-authored-by: BooksBaum <15612932+Booksbaum@users.noreply.github.com>