Commit graph

14066 commits

Author SHA1 Message Date
Jonas Schievink
3ff68f25b8 Expand attribute macros on impl and trait items 2022-01-06 12:30:16 +01:00
Jonas Schievink
3eddda6f4c simplify 2022-01-05 17:26:34 +01:00
bors[bot]
c5049bdcda
Merge #11190
11190: fix(completions): improve fn_param r=dbofmmbt a=dbofmmbt

- insert commas around when necessary
- only suggest `self` completions when param list is empty
- stop suggesting completions for identifiers which are already on the param list

Closes #11085 

Co-authored-by: Eduardo Canellas <eduardocanellas98@gmail.com>
2022-01-04 22:40:10 +00:00
Eduardo Canellas
a973e5a9db refactor: apply review suggestions 2022-01-04 19:30:57 -03:00
bors[bot]
ac3ea3e81c
Merge #11112
11112: Evaluate constants in array repeat expression r=HKalbasi a=HKalbasi

cc #8655 

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2022-01-04 21:51:37 +00:00
hkalbasi
75c2acae6e Evaluate constants in array repeat expression 2022-01-05 01:17:01 +03:30
Eduardo Canellas
30b7e92afa remove forgotten dbg macro 2022-01-04 15:37:10 -03:00
Eduardo Canellas
838944b387 improve logic for trailing comma addition 2022-01-04 15:30:30 -03:00
Eduardo Canellas
a9612666f8 fix(completions): improve fn_param
- insert commas around when necessary
- only suggest `self` completions when param list is empty
- stop suggesting completions for identifiers which are already on the param list
2022-01-04 15:03:46 -03:00
Lukas Wirth
c5a9985fc5 Remove lossy Definition::from_token/Definition::from_node methods 2022-01-04 18:29:53 +01:00
bors[bot]
68bc12c3b8
Merge #11157
11157: internal: Remove `SemanticScope::speculative_resolve_as_mac` r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-04 16:49:47 +00:00
Laurențiu Nicola
c934a99fd3 Rename and use the 1.55 ABI for 1.54 2022-01-04 14:06:26 +02:00
bors[bot]
dbb1c1b4b1
Merge #11184
11184: Correctly pass through mutable parameter references when extracting a function r=Veykril a=Vannevelj

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

I have based this investigation based on my understanding of [the Borrowing chapter](https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html) but I wasn't able to debug the test runs or see it in action in an IDE. I'll try to figure out how to do that for future PRs but for now, the tests seem to confirm my understanding. I'll lay out my hypothesis below.

Here we define the parameters for the to-be-generated function: 

7409880a07/crates/ide_assists/src/handlers/extract_function.rs (L882)

Three values in particular are important here: `requires_mut`, `is_copy` and `move_local`. These will in turn be used here to determine the kind of parameter:

7409880a07/crates/ide_assists/src/handlers/extract_function.rs (L374-L381)

and then here to determine what transformation is needed for the calling argument:

7409880a07/crates/ide_assists/src/handlers/extract_function.rs (L383-L390)

which then gets transformed here:

7409880a07/crates/syntax/src/ast/make.rs (L381-L383)

What I believe is happening is that 
* `requires_mut` is `false` (it already is marked as mutable), 
* `is_copy` is `false` (`Foo` does not implement `Copy`), and 
* `move_local` is `false` (it has further usages)

According to the pattern matching in `fn kind()`, that would lead to `ParamKind::SharedRef` which in turn applies a transformation that prepends `&`.

However if I look at the chapter on borrowing then we only need to mark an argument as a reference if we actually own it. In this case the value is passed through as a reference parameter into the current function which means we never had ownership in the first place. By including the additional check for a reference parameter, `move_local` now becomes `true` and the resulting parameter is now `ParamKind::Value` which will avoid applying any transformations. This was further obscured by the fact that you need further usages of the variable or `move_local` would be considered `true` after all.

I didn't follow it in depth but it appears this idea applies for both the generated argument and the generated parameter.
There are existing tests that account for `&mut` values but they refer to local variables for which we do have ownership and as such they didn't expose this issue.

Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
2022-01-04 10:19:37 +00:00
Jeroen Vannevel
ec61abbe93 reduced the tests to their bare essence 2022-01-04 10:11:04 +00:00
bors[bot]
22edf2e8a0
Merge #11186
11186: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-04 09:57:22 +00:00
Lukas Wirth
5fbdf20765 minor: Simplify 2022-01-04 10:56:28 +01:00
Jeroen Vannevel
5beddf93e7 additional test without further usages 2022-01-04 02:12:53 +00:00
Jeroen Vannevel
95cabfd722 Correctly pass through mutable references when extracting a function 2022-01-04 01:48:08 +00:00
bors[bot]
7409880a07
Merge #11061
11061: Support "move if to guard" for if else chains r=weirane a=weirane

The idea is to first parse the if else chain into a vector of `(Condition, BlockExpr)`s until we reach an iflet branch, an else branch, or the end (the tail). Then add the match arms with guard for the vector, and add the tail with no if guard.

Because the whole original match arm is replaced and the generated code doesn't have redundent commas, I removed redundent commas in some test cases.

Closes #11033.

Co-authored-by: Wang Ruochen <wrc@ruo-chen.wang>
2022-01-03 17:59:00 +00:00
Wang Ruochen
95145d5ab6
Update generated tests 2022-01-03 09:48:50 -08:00
Wang Ruochen
a19a32488d
Don't add pattern if there is a catch all afterwards 2022-01-03 09:38:45 -08:00
bors[bot]
b14af5cc6f
Merge #11115
11115: internal: refactor: avoid separate traversal in replace filter map next with find map r=Veykril a=rainy-me

fix: #7428

Co-authored-by: rainy-me <github@yue.coffee>
2022-01-03 16:00:05 +00:00
Lukas Wirth
19f1ff5c70 give resolve_derive_ident a more robust api 2022-01-03 16:00:45 +01:00
bors[bot]
1ba9a924d7
Merge #11180
11180: minor: add missing test r=matklad a=matklad

This test kills the following mutant:

diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 9d2b1da9a..055d9a733 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
`@@` -134,7 +134,7 `@@` impl<'a> TtIter<'a> {
         self.inner = self.inner.as_slice()[res.len()..].iter();
         let res = match res.len() {
             1 => Some(res[0].cloned()),
-            0 => None,
+            // 0 => None,
             _ => Some(tt::TokenTree::Subtree(tt::Subtree {
                 delimiter: None,
                 token_trees: res.into_iter().map(|it| it.cloned()).collect(),

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2022-01-03 14:22:37 +00:00
Aleksey Kladov
b688d84a4b minor: add missing test
This test kills the following mutant:

diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 9d2b1da9a..055d9a733 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -134,7 +134,7 @@ impl<'a> TtIter<'a> {
         self.inner = self.inner.as_slice()[res.len()..].iter();
         let res = match res.len() {
             1 => Some(res[0].cloned()),
-            0 => None,
+            // 0 => None,
             _ => Some(tt::TokenTree::Subtree(tt::Subtree {
                 delimiter: None,
                 token_trees: res.into_iter().map(|it| it.cloned()).collect(),
2022-01-03 17:21:43 +03:00
bors[bot]
120d76e0a3
Merge #11179
11179: minor: simplify mbe matcher r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2022-01-03 13:28:56 +00:00
Aleksey Kladov
303814189a simplify 2022-01-03 16:27:16 +03:00
Aleksey Kladov
966983c707 simplify 2022-01-03 16:22:41 +03:00
Dániel Buga
2e472bb746 Fix replace_match_with_if_let removing blocks with modifiers
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2022-01-03 14:07:34 +01:00
bors[bot]
8e9ccbf97a
Merge #11177
11177: internal: dont descend into comments r=Veykril a=jhgg

fixes #11176

Co-authored-by: Jake Heinz <jh@discordapp.com>
2022-01-03 02:03:03 +00:00
Jake Heinz
04decd5e6b internal: dont descend into comments 2022-01-03 01:53:58 +00:00
bors[bot]
abbc7e3a0e
Merge #11088
11088: closes #10446 hide type inlay hints r=Veykril a=Heinenen

Passes tests as described in #10446
Works for all happy cases, there may be some cases that I forgot as I am not that familiar with Rust and r-a (yet).

Co-authored-by: Heinenen <th.m.heinen@gmail.com>
2022-01-03 00:51:08 +00:00
bors[bot]
d89a4f0e93
Merge #11173
11173: Allow adding partially resolved types r=Veykril a=SomeoneToIgnore

Sometimes when writing something like `let foo = Arc::new(Mutex::new(CrazyGenerics::new(HashMap::new())))`, I want/have to specify an explicit type for the expression.
Using turbofish isn't very readable and not always appreciated by guidelines, so `let foo: T` has to be filled.

To ease that, the PR enables the `add_explicit_type` assist on types that contain unknown types and some generics.
Fully unresolved types, arrays with unknown types and other known cases behave the same.

`_` placeholder was chosen to replace an unknown type:

```rust
let foo = HashMap::new();
// after assist usage, turns into
let foo: HashMap<_, _> = HashMap::new();
```

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2022-01-03 00:40:30 +00:00
Lukas Wirth
087122ad1a fix: Fix highlighting hack for self-params 2022-01-03 01:32:03 +01:00
Kirill Bulatov
03291db801 Allow adding partially resolved types 2022-01-03 01:34:33 +02:00
Lukas Wirth
44b0fe8ec7 cleanup 2022-01-02 23:44:26 +01:00
Lukas Wirth
aeb5d64912 Implement ToDef for ast::Attr 2022-01-02 23:44:26 +01:00
Lukas Wirth
6b7b09d329 internal: Record unresolved derive invocations in hir 2022-01-02 23:44:23 +01:00
bors[bot]
989c06b25d
Merge #11171
11171: fix: Fix tool module classification not working correctly r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-02 22:15:30 +00:00
Lukas Wirth
762a3b3030 Fix tool module classification not working correctly 2022-01-02 23:14:18 +01:00
bors[bot]
35737eb896
Merge #11170
11170: minor: Cleanup syntax highlighting r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-02 21:24:07 +00:00
Lukas Wirth
19d894cdec minor: Cleanup syntax highlighting 2022-01-02 22:23:05 +01:00
bors[bot]
e1099aaa57
Merge #11169
11169: internal: Handle macro calls better in highlighting r=Veykril a=Veykril

Introduces a new semantic highlighting tag for the `!` character of macro calls.

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-02 18:27:16 +00:00
Lukas Wirth
22160c418b fix NameRefClass misclassifying proc-macros 2022-01-02 19:20:10 +01:00
Lukas Wirth
9eed85b171 fix syntactic highlighting for macros 2022-01-02 19:10:23 +01:00
Lukas Wirth
3a525c831f internal: Handle macro calls better in highlighting 2022-01-02 19:10:10 +01:00
bors[bot]
2e7170e07b
Merge #11166
11166: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-02 16:49:40 +00:00
Lukas Wirth
f31863b189 minor: Simplify 2022-01-02 17:37:16 +01:00
Aleksey Kladov
3836b195dd minor: replace panics with types 2022-01-02 19:05:37 +03:00
Aleksey Kladov
174c439c56 minor: drop dead code 2022-01-02 19:03:38 +03:00