]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoMerge #11107
bors[bot] [Sat, 8 Jan 2022 09:05:09 +0000 (09:05 +0000)]
Merge #11107

11107: Fix generic type substitution in impl trait with assoc type r=pnevyk a=pnevyk

Fixes #11045

The path transform now detects if a type parameter that is being substituted has an associated type. In that case it is necessary (or safe in general case) to fully qualify the substitution with a trait which the associated type belongs to.

This PR also fixes the previous wrong behavior of the substitution that could create an invalid tree `PATH_TYPE -> PATH_TYPE -> ...`.

Co-authored-by: Petr Nevyhoštěný <petr.nevyhosteny@gmail.com>
2 years agoMerge #11232
bors[bot] [Fri, 7 Jan 2022 20:52:57 +0000 (20:52 +0000)]
Merge #11232

11232: Filter out macro calls by file id in when building DynMap r=Veykril a=Veykril

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoSimplify
Lukas Wirth [Fri, 7 Jan 2022 20:51:59 +0000 (21:51 +0100)]
Simplify

2 years agoFilter out macro calls by file id in when building DynMap
Lukas Wirth [Fri, 7 Jan 2022 20:31:08 +0000 (21:31 +0100)]
Filter out macro calls by file id in when building DynMap

2 years agoMerge #11230
bors[bot] [Fri, 7 Jan 2022 18:06:33 +0000 (18:06 +0000)]
Merge #11230

11230: fix: Fix attribute stripping ignoring doc comments r=Veykril a=Veykril

Follow up to https://github.com/rust-analyzer/rust-analyzer/pull/11225#pullrequestreview-846779237

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofix: Fix attribute stripping ignoring doc comments
Lukas Wirth [Fri, 7 Jan 2022 17:51:10 +0000 (18:51 +0100)]
fix: Fix attribute stripping ignoring doc comments

2 years agoFix generic type substitution in impl trait with assoc const
Petr Nevyhoštěný [Fri, 7 Jan 2022 15:41:39 +0000 (16:41 +0100)]
Fix generic type substitution in impl trait with assoc const

2 years agoMerge #11145
bors[bot] [Fri, 7 Jan 2022 14:10:11 +0000 (14:10 +0000)]
Merge #11145

11145: feat: add config to use reasonable default expression instead of todo! when filling missing fields r=Veykril a=bnjjj

Use `Default::default()` in struct fields when we ask to fill it instead of putting `todo!()` for every fields

before:

```rust
pub enum Other {
    One,
    Two,
}

pub struct Test {
    text: String,
    num: usize,
    other: Other,
}

fn t_test() {
    let test = Test {<|>};
}
```

after:

```rust
pub enum Other {
    One,
    Two,
}

pub struct Test {
    text: String,
    num: usize,
    other: Other,
}

fn t_test() {
    let test = Test {
        text: String::new(),
        num: 0,
        other: todo!(),
    };
}
```

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2 years agoMerge #11220
bors[bot] [Fri, 7 Jan 2022 14:02:01 +0000 (14:02 +0000)]
Merge #11220

11220: Turbo fish assist: don't include lifetime parameters r=Veykril a=Vannevelj

Fixes #11219

The issue talks about three different types of params: type, const & lifetime. I wasn't entirely sure which ones are intended to be included here so I've gone for the type & const params (i.e. exclude lifetime).

I've added a test case for both a lifetime param and a const param. I'm still making my way through the rust book (chapter 7, yay) so I'm not too sure yet what these are but my testing shows that this approach generates code that compiles.

Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
2 years agofeat(diagnostics): use default expression instead of todo! when missing fields
Benjamin Coenen [Fri, 7 Jan 2022 14:01:37 +0000 (15:01 +0100)]
feat(diagnostics): use default expression instead of todo! when missing fields

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2 years agosuccinct code
Jeroen Vannevel [Fri, 7 Jan 2022 13:53:42 +0000 (13:53 +0000)]
succinct code

2 years agoMerge #11225
bors[bot] [Fri, 7 Jan 2022 13:38:23 +0000 (13:38 +0000)]
Merge #11225

11225: internal: Cleanup doc and attribute handling r=Veykril a=Veykril

(very vague PR title but as I tried to fix the mentioned issue I ran into more and more subtle things that were interwoven)
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11215

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoUpdate item tree test output
Lukas Wirth [Fri, 7 Jan 2022 13:29:58 +0000 (14:29 +0100)]
Update item tree test output

2 years agoMerge #11194
bors[bot] [Fri, 7 Jan 2022 13:24:58 +0000 (13:24 +0000)]
Merge #11194

11194: fix(gen-doc-assist): remove lifetimes in description of `new` r=Veykril a=numero-744

From wrong behavior:

```rust
/// Creates a new [`MyGenericStruct<'a, T>`].
```

to correct behavior:

```rust
/// Creates a new [`MyGenericStruct<T>`].
```

But I feel like there is a better way to implement it. Do you know if there is an existing function that could do the work of `lifetimes_removed()` below?

Co-authored-by: Côme ALLART <come.allart@etu.emse.fr>
2 years agoUse `FileAstId<ast::Adt>` in nameres where appropriate instead
Lukas Wirth [Fri, 7 Jan 2022 13:19:11 +0000 (14:19 +0100)]
Use `FileAstId<ast::Adt>` in nameres where appropriate instead

2 years agoinclude tabstops
Jeroen Vannevel [Fri, 7 Jan 2022 13:17:21 +0000 (13:17 +0000)]
include tabstops

2 years agoBetter interface for doc comment and attribute processing
Lukas Wirth [Fri, 7 Jan 2022 13:14:33 +0000 (14:14 +0100)]
Better interface for doc comment and attribute processing

2 years agofeat(diagnostics): use default expression instead of todo! when missing fields
Benjamin Coenen [Fri, 7 Jan 2022 13:13:34 +0000 (14:13 +0100)]
feat(diagnostics): use default expression instead of todo! when missing fields

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2 years agorefactor: apply suggestions
Côme ALLART [Fri, 7 Jan 2022 13:04:03 +0000 (14:04 +0100)]
refactor: apply suggestions

See PR #11194

2 years agoUpdate crates/rust-analyzer/src/config.rs
Coenen Benjamin [Fri, 7 Jan 2022 13:07:02 +0000 (14:07 +0100)]
Update crates/rust-analyzer/src/config.rs

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofmt
Jeroen Vannevel [Fri, 7 Jan 2022 12:40:41 +0000 (12:40 +0000)]
fmt

2 years agoconcise filtering
Jeroen Vannevel [Fri, 7 Jan 2022 12:34:03 +0000 (12:34 +0000)]
concise filtering

2 years agoGenerate `AnyHasDocComments` node
Lukas Wirth [Fri, 7 Jan 2022 11:37:58 +0000 (12:37 +0100)]
Generate `AnyHasDocComments` node

2 years agosupport const params
Jeroen Vannevel [Fri, 7 Jan 2022 01:09:32 +0000 (01:09 +0000)]
support const params

2 years agoCount the type parameters only
Jeroen Vannevel [Fri, 7 Jan 2022 01:02:16 +0000 (01:02 +0000)]
Count the type parameters only

2 years agoMerge #11218
bors[bot] [Thu, 6 Jan 2022 23:17:51 +0000 (23:17 +0000)]
Merge #11218

11218: fix: Correct has_ref detection, avoiding duplicate &mut insertion on parameter completion r=Veykril a=weirane

The original code fails to detect there's a ref in scenarios such as `&mut s` and `& s` because `WHITESPACE` and `IDENT` got reversed.

Closes #11199.

Co-authored-by: Wang Ruochen <wrc@ruo-chen.wang>
2 years agoCorrect has_ref detection
Wang Ruochen [Thu, 6 Jan 2022 19:45:09 +0000 (11:45 -0800)]
Correct has_ref detection

2 years agoadd better default behavior on fill struct fields diagnostic
Benjamin Coenen [Thu, 6 Jan 2022 14:42:29 +0000 (15:42 +0100)]
add better default behavior on fill struct fields diagnostic

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2 years agoMerge #11217
bors[bot] [Thu, 6 Jan 2022 14:39:34 +0000 (14:39 +0000)]
Merge #11217

11217: minor: Move pretty-printing test out of assist r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2 years agoMove pretty-printing test out of assist
Laurențiu Nicola [Thu, 6 Jan 2022 14:38:25 +0000 (16:38 +0200)]
Move pretty-printing test out of assist

2 years agoMerge #11216
bors[bot] [Thu, 6 Jan 2022 13:57:17 +0000 (13:57 +0000)]
Merge #11216

11216: internal: Support registered tools and attributes in ide layer r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agointernal: Support registered tools and attributes in ide layer
Lukas Wirth [Thu, 6 Jan 2022 13:56:50 +0000 (14:56 +0100)]
internal: Support registered tools and attributes in ide layer

2 years agoMerge #11214
bors[bot] [Thu, 6 Jan 2022 13:24:43 +0000 (13:24 +0000)]
Merge #11214

11214: feat: poke user when supplying faulty configurations r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofeat: poke user when supplying faulty configurations
Lukas Wirth [Thu, 6 Jan 2022 13:23:35 +0000 (14:23 +0100)]
feat: poke user when supplying faulty configurations

2 years agoMerge #11193
bors[bot] [Thu, 6 Jan 2022 12:53:49 +0000 (12:53 +0000)]
Merge #11193

11193: feat: Add config to replace specific proc-macros with dummy expanders r=Veykril a=Veykril

With this one can specify proc-macros from crates to expand into their input as a (temporary) workaround for the current completion problems with some of the bigger attribute proc-macros like `async_trait`.

This could've been done by just not expanding these macros, but that would require fiddling with nameres. I felt like this approach was simpler to pull off while also keeping the behaviour of the attributes/proc-macro in that they still expand instead of being dead syntax to us.

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

Usage(`async_trait` as example):
```jsonc
    "rust-analyzer.procMacro.dummies": {
        "async-trait": [ // crate name(as per its cargo.toml definition, not the dependency name)
            "async_trait" // exported proc-macro name
        ]
    },
```

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoAdjust config name
Lukas Wirth [Thu, 6 Jan 2022 12:44:21 +0000 (13:44 +0100)]
Adjust config name

2 years agoRegenrate docs and package.json
Lukas Wirth [Wed, 5 Jan 2022 18:35:48 +0000 (19:35 +0100)]
Regenrate docs and package.json

2 years agofeat: Add config to replace specific proc-macros with dummy expanders
Lukas Wirth [Tue, 4 Jan 2022 19:40:16 +0000 (20:40 +0100)]
feat: Add config to replace specific proc-macros with dummy expanders

2 years agoMerge #11211
bors[bot] [Thu, 6 Jan 2022 12:41:02 +0000 (12:41 +0000)]
Merge #11211

11211: fix: Fix parsing of `#[derive]` paths r=jonas-schievink a=jonas-schievink

Currently this code produces an empty derive path for every `,`, which makes the IDE layer resolve derive paths to the wrong derive macro in the list. Skip `,`s to fix that. (nameres just ignored them, so it didn't cause problems there)

bors r+

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2 years agoFix parsing of `#[derive]` paths
Jonas Schievink [Thu, 6 Jan 2022 12:39:20 +0000 (13:39 +0100)]
Fix parsing of `#[derive]` paths

2 years agoMerge #11209
bors[bot] [Thu, 6 Jan 2022 11:56:29 +0000 (11:56 +0000)]
Merge #11209

11209: minor: Use`const _` instead of `mod __` r=jonas-schievink a=jonas-schievink

We now handle it correctly

bors r+

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2 years agoUse`const _` instead of `mod __`
Jonas Schievink [Thu, 6 Jan 2022 11:55:33 +0000 (12:55 +0100)]
Use`const _` instead of `mod __`

2 years agoMerge #11208
bors[bot] [Thu, 6 Jan 2022 11:31:19 +0000 (11:31 +0000)]
Merge #11208

11208: feat: expand attribute macros on impl and trait items r=jonas-schievink a=jonas-schievink

fixes https://github.com/rust-analyzer/rust-analyzer/issues/11104

bors r+

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2 years agoExpand attribute macros on impl and trait items
Jonas Schievink [Thu, 6 Jan 2022 11:30:16 +0000 (12:30 +0100)]
Expand attribute macros on impl and trait items

2 years agoMerge #11207
bors[bot] [Thu, 6 Jan 2022 10:48:54 +0000 (10:48 +0000)]
Merge #11207

11207: Always put a space after impl in macro pretty-printing r=Veykril a=jplatte

… regardless of whether the next symbol is punctuation or not.

Followup to #11200.

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2 years agoAlways put a space after impl in macro pretty-printing
Jonas Platte [Thu, 6 Jan 2022 10:08:32 +0000 (11:08 +0100)]
Always put a space after impl in macro pretty-printing

… regardless of whether the next symbol is punctuation or not.

2 years agofix: remove brackets if no generic types
Côme ALLART [Thu, 6 Jan 2022 00:51:04 +0000 (01:51 +0100)]
fix: remove brackets if no generic types

2 years agoMerge #11204
bors[bot] [Wed, 5 Jan 2022 22:47:30 +0000 (22:47 +0000)]
Merge #11204

11204: fix: `replace_qualified_name_with_use` does not use full item path for replacements r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofix: `replace_qualified_name_with_use` does not use full item path for replacements
Lukas Wirth [Wed, 5 Jan 2022 22:46:58 +0000 (23:46 +0100)]
fix: `replace_qualified_name_with_use` does not use full item path for replacements

2 years agoMerge #11195 #11202
bors[bot] [Wed, 5 Jan 2022 21:30:50 +0000 (21:30 +0000)]
Merge #11195 #11202

11195: Correctly pass through reference modifiers when extracting a variable r=Veykril a=Vannevelj

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

This will parse the field expression and look at whether it is marked `&` or `&mut` and include a modifier if appropriate. The original issue only mentions `&mut params` but I've found that this issue also occurs for `&mut locals` as well as `&params` and `&locals` so I've also added tests for them.

I'd definitely be interested in hearing where I can make my code more idiomatic for Rust.

11202: fix: Fix `apply_demorgan` assist hanging for certain binary expressions r=Veykril a=Veykril

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

Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofix: Fix `apply_demorgan` assist hanging for certain binary expressions
Lukas Wirth [Wed, 5 Jan 2022 21:30:19 +0000 (22:30 +0100)]
fix: Fix `apply_demorgan` assist hanging for certain binary expressions

2 years agoremoved double matching
Jeroen Vannevel [Wed, 5 Jan 2022 21:16:24 +0000 (21:16 +0000)]
removed double matching

2 years agono PathExpr arm
Jeroen Vannevel [Wed, 5 Jan 2022 21:12:09 +0000 (21:12 +0000)]
no PathExpr arm

2 years ago.clone() over .to_owned()
Jeroen Vannevel [Wed, 5 Jan 2022 21:10:03 +0000 (21:10 +0000)]
.clone() over .to_owned()

2 years agoless wordy ref_kind assignment
Jeroen Vannevel [Wed, 5 Jan 2022 21:08:46 +0000 (21:08 +0000)]
less wordy ref_kind assignment

2 years agoMerge #11201
bors[bot] [Wed, 5 Jan 2022 20:45:27 +0000 (20:45 +0000)]
Merge #11201

11201: fix: Fix completions not considering ancestor items for attribute search r=Veykril a=Veykril

Turns out we never filled the `CompletionContext` with the attribute expansion of attributed impls and traits when typing in the assoc items, as we were only considering the assoc item to have an attribute to expand.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agofix: Fix completions not considering ancestor items for attribute search
Lukas Wirth [Wed, 5 Jan 2022 20:12:36 +0000 (21:12 +0100)]
fix: Fix completions not considering ancestor items for attribute search

2 years agoMerge #11200
bors[bot] [Wed, 5 Jan 2022 20:04:49 +0000 (20:04 +0000)]
Merge #11200

11200: Always put a space after dyn in macro pretty-printing r=Veykril a=jplatte

Fixes #11100.

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2 years agoMerge #11198
bors[bot] [Wed, 5 Jan 2022 18:08:09 +0000 (18:08 +0000)]
Merge #11198

11198: Remove unused lifetime r=lnicola a=Aaron1011

Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
2 years agoAlways put a space after `dyn` in macro pretty-printing
Jonas Platte [Wed, 5 Jan 2022 17:04:44 +0000 (18:04 +0100)]
Always put a space after `dyn` in macro pretty-printing

… regardless of whether the next symbol is punctuation or not.
Fixes issue 11100.

2 years agoAdd failing test case for issue 11100
Jonas Platte [Wed, 5 Jan 2022 17:04:36 +0000 (18:04 +0100)]
Add failing test case for issue 11100

2 years agosimplify
Jonas Schievink [Wed, 5 Jan 2022 16:26:34 +0000 (17:26 +0100)]
simplify

2 years agoRemove unused lifetime
Aaron Hill [Wed, 5 Jan 2022 15:19:10 +0000 (10:19 -0500)]
Remove unused lifetime

2 years agoremoved trailing whitespace
Jeroen Vannevel [Wed, 5 Jan 2022 02:16:22 +0000 (02:16 +0000)]
removed trailing whitespace

2 years agocomment
Jeroen Vannevel [Wed, 5 Jan 2022 01:48:57 +0000 (01:48 +0000)]
comment

2 years agoadditional test for a reference local (on top of mutable reference local)
Jeroen Vannevel [Wed, 5 Jan 2022 01:36:04 +0000 (01:36 +0000)]
additional test for a reference local (on top of mutable reference local)

2 years agofailing test for a reference local
Jeroen Vannevel [Wed, 5 Jan 2022 01:27:15 +0000 (01:27 +0000)]
failing test for a reference local

2 years agoDon't include a ref if none was declared
Jeroen Vannevel [Wed, 5 Jan 2022 01:18:55 +0000 (01:18 +0000)]
Don't include a ref if none was declared

2 years agosupport ref params as well
Jeroen Vannevel [Wed, 5 Jan 2022 01:15:54 +0000 (01:15 +0000)]
support ref params as well

2 years agocorrectly handle mutable references
Jeroen Vannevel [Wed, 5 Jan 2022 01:03:27 +0000 (01:03 +0000)]
correctly handle mutable references

2 years agofix(gen-doc-assist): remove lifetimes in description of `new`
Côme ALLART [Tue, 4 Jan 2022 23:23:36 +0000 (00:23 +0100)]
fix(gen-doc-assist): remove lifetimes in description of `new`

2 years agoMerge #11190
bors[bot] [Tue, 4 Jan 2022 22:40:10 +0000 (22:40 +0000)]
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>
2 years agorefactor: apply review suggestions
Eduardo Canellas [Tue, 4 Jan 2022 22:30:57 +0000 (19:30 -0300)]
refactor: apply review suggestions

2 years agoMerge #11112
bors[bot] [Tue, 4 Jan 2022 21:51:37 +0000 (21:51 +0000)]
Merge #11112

11112: Evaluate constants in array repeat expression r=HKalbasi a=HKalbasi

cc #8655

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2 years agoEvaluate constants in array repeat expression
hkalbasi [Thu, 23 Dec 2021 17:49:18 +0000 (21:19 +0330)]
Evaluate constants in array repeat expression

2 years agoremove forgotten dbg macro
Eduardo Canellas [Tue, 4 Jan 2022 18:37:10 +0000 (15:37 -0300)]
remove forgotten dbg macro

2 years agoimprove logic for trailing comma addition
Eduardo Canellas [Tue, 4 Jan 2022 18:30:30 +0000 (15:30 -0300)]
improve logic for trailing comma addition

2 years agofix(completions): improve fn_param
Eduardo Canellas [Tue, 4 Jan 2022 18:03:46 +0000 (15:03 -0300)]
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

2 years agoMerge #11189
bors[bot] [Tue, 4 Jan 2022 17:30:43 +0000 (17:30 +0000)]
Merge #11189

11189: internal: Remove lossy `Definition::from_token`/`Definition::from_node` methods r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agoRemove lossy `Definition::from_token`/`Definition::from_node` methods
Lukas Wirth [Tue, 4 Jan 2022 17:29:20 +0000 (18:29 +0100)]
Remove lossy `Definition::from_token`/`Definition::from_node` methods

2 years agoMerge #11157
bors[bot] [Tue, 4 Jan 2022 16:49:47 +0000 (16:49 +0000)]
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>
2 years agoMerge #11187
bors[bot] [Tue, 4 Jan 2022 16:10:56 +0000 (16:10 +0000)]
Merge #11187

11187: Rename and use the 1.55 ABI for 1.54 r=lnicola a=lnicola

It seems that what we used to call the 1.55 ABI was actually introduced in 1.54.

CC #10799

Thanks to `@danielframpton` for finding it.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2 years agoadd better default behavior on fill struct fields diagnostic
Benjamin Coenen [Tue, 4 Jan 2022 14:59:00 +0000 (15:59 +0100)]
add better default behavior on fill struct fields diagnostic

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2 years agoRename and use the 1.55 ABI for 1.54
Laurențiu Nicola [Tue, 4 Jan 2022 11:13:09 +0000 (13:13 +0200)]
Rename and use the 1.55 ABI for 1.54

2 years agoMerge #11184
bors[bot] [Tue, 4 Jan 2022 10:19:37 +0000 (10:19 +0000)]
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:

https://github.com/rust-analyzer/rust-analyzer/blob/7409880a07803c34590ad162d7854061145c6eae/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:

https://github.com/rust-analyzer/rust-analyzer/blob/7409880a07803c34590ad162d7854061145c6eae/crates/ide_assists/src/handlers/extract_function.rs#L374-L381

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

https://github.com/rust-analyzer/rust-analyzer/blob/7409880a07803c34590ad162d7854061145c6eae/crates/ide_assists/src/handlers/extract_function.rs#L383-L390

which then gets transformed here:

https://github.com/rust-analyzer/rust-analyzer/blob/7409880a07803c34590ad162d7854061145c6eae/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>
2 years agoreduced the tests to their bare essence
Jeroen Vannevel [Tue, 4 Jan 2022 10:11:04 +0000 (10:11 +0000)]
reduced the tests to their bare essence

2 years agoMerge #11186
bors[bot] [Tue, 4 Jan 2022 09:57:22 +0000 (09:57 +0000)]
Merge #11186

11186: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 years agominor: Simplify
Lukas Wirth [Tue, 4 Jan 2022 09:56:17 +0000 (10:56 +0100)]
minor: Simplify

2 years agoadditional test without further usages
Jeroen Vannevel [Tue, 4 Jan 2022 02:12:53 +0000 (02:12 +0000)]
additional test without further usages

2 years agoCorrectly pass through mutable references when extracting a function
Jeroen Vannevel [Tue, 4 Jan 2022 01:48:08 +0000 (01:48 +0000)]
Correctly pass through mutable references when extracting a function

2 years agoMerge #11061
bors[bot] [Mon, 3 Jan 2022 17:59:00 +0000 (17:59 +0000)]
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>
2 years agoUpdate generated tests
Wang Ruochen [Mon, 3 Jan 2022 17:48:50 +0000 (09:48 -0800)]
Update generated tests

2 years agoDon't add pattern if there is a catch all afterwards
Wang Ruochen [Mon, 3 Jan 2022 17:37:29 +0000 (09:37 -0800)]
Don't add pattern if there is a catch all afterwards

2 years agoMerge #11115
bors[bot] [Mon, 3 Jan 2022 16:00:05 +0000 (16:00 +0000)]
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>
2 years agogive `resolve_derive_ident` a more robust api
Lukas Wirth [Mon, 3 Jan 2022 15:00:45 +0000 (16:00 +0100)]
give `resolve_derive_ident` a more robust api

2 years agoMerge #11180
bors[bot] [Mon, 3 Jan 2022 14:22:37 +0000 (14:22 +0000)]
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>
2 years agominor: add missing test
Aleksey Kladov [Mon, 3 Jan 2022 14:21:18 +0000 (17:21 +0300)]
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(),

2 years agoMerge #11179
bors[bot] [Mon, 3 Jan 2022 13:28:56 +0000 (13:28 +0000)]
Merge #11179

11179: minor: simplify mbe matcher r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 years agosimplify
Aleksey Kladov [Mon, 3 Jan 2022 13:27:16 +0000 (16:27 +0300)]
simplify

2 years agosimplify
Aleksey Kladov [Mon, 3 Jan 2022 13:22:41 +0000 (16:22 +0300)]
simplify