]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoremove unnecessary
Sahandevs [Sun, 7 Feb 2021 17:45:13 +0000 (21:15 +0330)]
remove unnecessary

3 years agoMerge #7587
bors[bot] [Sun, 7 Feb 2021 11:15:26 +0000 (11:15 +0000)]
Merge #7587

7587: AdtDef -> Adt r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdtDef -> Adt
Aleksey Kladov [Sun, 7 Feb 2021 11:15:02 +0000 (14:15 +0300)]
AdtDef -> Adt

3 years agoMerge #7586
bors[bot] [Sun, 7 Feb 2021 07:59:24 +0000 (07:59 +0000)]
Merge #7586

7586: Add a section on entry points r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd a section on entry points
Aleksey Kladov [Sun, 7 Feb 2021 07:49:45 +0000 (10:49 +0300)]
Add a section on entry points

3 years agoFixing architecture image on dark theme
Erick Tovar [Sat, 6 Feb 2021 20:52:38 +0000 (12:52 -0800)]
Fixing architecture image on dark theme

3 years agoMerge #7585
bors[bot] [Sun, 7 Feb 2021 04:54:31 +0000 (04:54 +0000)]
Merge #7585

7585: More information for mbe in architecture.md r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoRemove redunacny
Edwin Cheng [Sun, 7 Feb 2021 04:53:54 +0000 (12:53 +0800)]
Remove redunacny

3 years agoMore information for mbe
Edwin Cheng [Sun, 7 Feb 2021 04:49:02 +0000 (12:49 +0800)]
More information for mbe

3 years agoMerge #7584
bors[bot] [Sun, 7 Feb 2021 04:33:15 +0000 (04:33 +0000)]
Merge #7584

7584: Update architecture.md for mbe and proc-macro r=edwin0cheng a=edwin0cheng

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoUpdate architecture.md for mbe and proc-macro
Edwin Cheng [Sun, 7 Feb 2021 04:31:33 +0000 (12:31 +0800)]
Update architecture.md for mbe and proc-macro

3 years agoMerge #7583
bors[bot] [Sat, 6 Feb 2021 22:52:42 +0000 (22:52 +0000)]
Merge #7583

7583: Update architecture.md r=bjorn3 a=aTuck

Typo

Co-authored-by: Adam Tuck <tuckaet@gmail.com>
3 years agoUpdate architecture.md
Adam Tuck [Sat, 6 Feb 2021 22:40:23 +0000 (14:40 -0800)]
Update architecture.md

Typo

3 years agoMerge #7578
bors[bot] [Sat, 6 Feb 2021 00:25:23 +0000 (00:25 +0000)]
Merge #7578

7578: Add a semantic token type for char literals r=Veykril a=petr-tik

Fixes #7530

The LSP spec doesn't recognise character literals, so
had to extend the suported types to our own custom type

Co-authored-by: petr-tik <petr-tik@users.noreply.github.com>
3 years agoAdd a semantic token type for char literals
petr-tik [Fri, 5 Feb 2021 23:46:39 +0000 (23:46 +0000)]
Add a semantic token type for char literals

The LSP spec doesn't recognise character literals, so
had to extend the suported types to our own custom type

3 years agoMerge #7577
bors[bot] [Fri, 5 Feb 2021 20:45:52 +0000 (20:45 +0000)]
Merge #7577

7577: cargo update r=kjeremy a=kjeremy

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoMerge #7576
bors[bot] [Fri, 5 Feb 2021 20:35:51 +0000 (20:35 +0000)]
Merge #7576

7576: Fix resolveCodeAction trying to edit files before creating them r=Veykril a=Veykril

Fixes #7208
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agocargo update
kjeremy [Fri, 5 Feb 2021 20:35:45 +0000 (15:35 -0500)]
cargo update

3 years agoFix resolveCodeAction trying to edit files before creating them
Lukas Wirth [Fri, 5 Feb 2021 20:26:14 +0000 (21:26 +0100)]
Fix resolveCodeAction trying to edit files before creating them

3 years agoMerge #7575
bors[bot] [Fri, 5 Feb 2021 18:26:51 +0000 (18:26 +0000)]
Merge #7575

7575: Fix resolution of `self` module within blocks r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoTest `super` resolution too
Jonas Schievink [Fri, 5 Feb 2021 18:25:50 +0000 (19:25 +0100)]
Test `super` resolution too

3 years agoFix resolution of `self` module within blocks
Jonas Schievink [Fri, 5 Feb 2021 18:24:03 +0000 (19:24 +0100)]
Fix resolution of `self` module within blocks

3 years agoMerge #7572
bors[bot] [Fri, 5 Feb 2021 17:18:02 +0000 (17:18 +0000)]
Merge #7572

7572: Add `find_or_create_impl_block` to assist utils r=matklad a=yoshuawuyts

This is another continuation of https://github.com/rust-analyzer/rust-analyzer/pull/7562, introducing a small util to either find an `impl` block, or create a new one if none exists. I copied this code from the `generate_new` assist into https://github.com/rust-analyzer/rust-analyzer/pull/7562, and this unifies both into a helper.

It doesn't feel super polished in its current state, but my hope is that this is enough of a starting point that it can be expanded on later. For example something that would be useful would be a flag which either returns the index of the start of the block, or the end of the block.

Anyway, I hope this is useful. Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoAdd `find_or_create_impl_block` to assist utils
Yoshua Wuyts [Fri, 5 Feb 2021 15:32:34 +0000 (16:32 +0100)]
Add `find_or_create_impl_block` to assist utils

3 years agoMerge #7573
bors[bot] [Fri, 5 Feb 2021 16:14:55 +0000 (16:14 +0000)]
Merge #7573

7573: Do not overwrite lock file r=kjeremy a=kjeremy

Use `npm ci` instead of `npm install`. `npm install` will overwrite
the lock file if you have a newer npm version than the one that
generated the package-lock.json

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoMerge #7574
bors[bot] [Fri, 5 Feb 2021 16:04:50 +0000 (16:04 +0000)]
Merge #7574

7574: Remove various redundant clones r=kjeremy a=yoshuawuyts

I noticed when running clippy through RA that there are a few instances where `clone` is called where it's not actually needed. I figured a small patch to remove these might be welcome here.

Thanks!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoDo not overwrite lock file
kjeremy [Fri, 5 Feb 2021 15:57:36 +0000 (10:57 -0500)]
Do not overwrite lock file

Use `npm ci` instead of `npm install`. `npm install` will overwrite
the lock file if you have a newer npm version than the one that
generated the package-lock.json

3 years agoRemove redundant clones
Yoshua Wuyts [Fri, 5 Feb 2021 15:57:26 +0000 (16:57 +0100)]
Remove redundant clones

3 years agoMerge #7505
bors[bot] [Fri, 5 Feb 2021 15:31:25 +0000 (15:31 +0000)]
Merge #7505

7505: Widen Highlights root range to covering element r=Veykril a=Veykril

There have been a few issues about/containing spurious syntax highlighting panics, which all seem to come from the `rust_analyzer::handlers::handle_semantic_tokens_range` request, which I believe this to be the cause of as the text range we want to highlight here is currently potentially smaller than that of the covering element, so we might highlight something that is inside the covering element, but outside of the text range we wish to highlight causing the assert to fail.
Unfortunately this isn't really easy to test since I have yet to find a reproducible cause(#7504 doesn't work for me cause I can't seem to checkout the given commit).

See #7504, #7298, #7299 and #7416, all of those contain an assertion failure in syntax highlighting, but only in the range request.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoMerge #7570 #7571
bors[bot] [Fri, 5 Feb 2021 15:17:41 +0000 (15:17 +0000)]
Merge #7570 #7571

7570: Add doc gen to the `generate_enum_match_method` assist r=yoshuawuyts a=yoshuawuyts

Implements a small extension to https://github.com/rust-analyzer/rust-analyzer/pull/7562, generating default comments. I wasn't sure if this would fit the goals of Rust-Analyzer, so I chose to split it into a separate PR. This is especially useful when writing code in a codebase which uses `#![warn(missing_docs)]` lint, as many production-grade libraries do.

The comments we're generating here are similar to the ones found on [`Option::is_some`](https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some) and [`Result::is_err`](https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err). I briefly considered only generating these for `pub` types, but they seem small and unobtrusive enough that they're probably useful in the general case. Thanks!

## Example

__input__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```

__output__
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    /// Returns `true` if the variant is [`Minor`].
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

This opens up the path to adding an assist for generating these comments on existing `is_` methods. This would make it both easy to document new code, and update existing code with documentation.

7571: Cleanup decl_check r=Veykril a=Veykril

bors r+

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoCleanup decl_check
Lukas Wirth [Fri, 5 Feb 2021 15:09:45 +0000 (16:09 +0100)]
Cleanup decl_check

3 years agoAdd doc gen to the `generate_enum_match_method` assist
Yoshua Wuyts [Fri, 5 Feb 2021 14:35:24 +0000 (15:35 +0100)]
Add doc gen to the `generate_enum_match_method` assist

3 years agoMerge #7569
bors[bot] [Fri, 5 Feb 2021 14:45:59 +0000 (14:45 +0000)]
Merge #7569

7569: Add howtos r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoAdd howtos
Aleksey Kladov [Fri, 5 Feb 2021 14:44:04 +0000 (17:44 +0300)]
Add howtos

3 years agoMerge #7562
bors[bot] [Fri, 5 Feb 2021 14:28:25 +0000 (14:28 +0000)]
Merge #7562

7562: add `generate_enum_match` assist r=matklad a=yoshuawuyts

This adds a `generate_enum_match` assist, which generates `is_` variants for enums (e.g. `Option::{is_none,is_some}` in std). This is my first attempt at contributing to Rust-Analyzer, so I'm not sure if I've gotten everything right. Thanks!

## Example

**Input**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor, // cursor here
    Major,
}
```
**Output**
```rust
pub(crate) enum Variant {
    Undefined,
    Minor,
    Major,
}

impl Variant {
    pub(crate) fn is_minor(&self) -> bool {
        matches!(self, Self::Minor)
    }
}
```

## Future Directions

I made this as a stepping stone for some of the more involved refactors (e.g. #5944). I'm not sure yet how to create, use, and test `window.showQuickPick`-based asssists in RA. But once that's possible, it'd probably be nice to be able to generate match methods in bulk through the quickpick UI rather than one-by-one:

```
[x] Select enum members to generate methods for. (3 selected) [ OK ]
---------------------------------------------------------------------------
[x] Undefined
[x] Minor
[x] Major
```

Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
3 years agoMerge #7568
bors[bot] [Fri, 5 Feb 2021 14:16:12 +0000 (14:16 +0000)]
Merge #7568

7568: Fix merging of `segment_index` in path resolution r=jonas-schievink a=jonas-schievink

This caused associated item lookup to fail when modifying `resolver.rs` to handle block expressions with inner items.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoFix merging of `segment_index` in path resolution
Jonas Schievink [Fri, 5 Feb 2021 14:14:33 +0000 (15:14 +0100)]
Fix merging of `segment_index` in path resolution

3 years agoMerge #7567
bors[bot] [Fri, 5 Feb 2021 14:03:52 +0000 (14:03 +0000)]
Merge #7567

7567: Remove unnecessary allocs in case_conv r=Veykril a=Veykril

and some replace unwraps

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoRemove unnecessary allocs in case_conv
Lukas Wirth [Fri, 5 Feb 2021 14:02:39 +0000 (15:02 +0100)]
Remove unnecessary allocs in case_conv

3 years agoMove `find_struct_impl` to assist utils
Yoshua Wuyts [Fri, 5 Feb 2021 13:36:07 +0000 (14:36 +0100)]
Move `find_struct_impl` to assist utils

3 years agoadd `generate-enum-match` assist
Yoshua Wuyts [Fri, 5 Feb 2021 00:57:39 +0000 (01:57 +0100)]
add `generate-enum-match` assist

3 years agoMerge #7535
bors[bot] [Fri, 5 Feb 2021 02:55:56 +0000 (02:55 +0000)]
Merge #7535

7535: Extract function assist r=cpud36 a=cpud36

This PR adds `extract function/method` assist. closes #5409.

# Supported features
Assist should support extracting from expressions(`1`, `2 + 2`, `loop { }`) and from a series of statements, e.g.:
```rust
foo();
$0bar();
baz();$0
quix();
```
Assist also supports extracting parameters, like:
```rust
fn foo() -> i32 {
  let n = 1;
  $0n + 1$0
}

// -
fn foo() -> i32 {
  let n = 1;
  fun_name(n)
}

fn fun_name(n: i32) -> i32 {
  n + 1
}
```

Extracting methods also generally works.

Assist allows referencing outer variables, both mutably and immutably, and handles handles access to variables local to extracted function:
```rust
fn foo() {
  let mut n = 1;
  let mut m = 2;
  let mut moved_v = Vec::new();
  let mut ref_mut_v = Vec::new();
  $0
  n += 1;
  let k = 1;
  moved_v.push(n);
  let r = &mut m;
  ref_mut_v.push(*r);
  let h = 3;
  $0
  n = ref_mut_v.len() + k;
  n -= h + m;
}

// -
fn foo() {
  let mut n = 1;
  let mut m = 2;
  let mut moved_v = Vec::new();
  let mut ref_mut_v = Vec::new();

  let (k, h) =  fun_name(&mut n, moved_v, &mut m, &mut ref_mut_v);

  n = ref_mut_v.len() + k;
  n -= h + m;
}

fn fun_name(n: &mut i32, mut moved_v: Vec<i32>, m: &mut i32, ref_mut_v: &mut Vec<i32>) -> (i32, i32) {
  *n += 1;
  let k = 1;
  moved_v.push(*n);
  let r = m;
  ref_mut_v.push(*r);
  let h = 3;
  (k, h)
}
```

So we handle both input and output paramters

# Showcase

![extract_cursor_in_range_3](https://user-images.githubusercontent.com/4218373/106980190-c9870800-6770-11eb-83d9-3d36b2550ff6.gif)
![fill_match_arms_discard_wildcard](https://user-images.githubusercontent.com/4218373/106980197-cbe96200-6770-11eb-96b0-14c27894fac0.gif)
![ide_db_helpers_handle_kind](https://user-images.githubusercontent.com/4218373/106980201-cdb32580-6770-11eb-9e6e-6ac8155d65ac.gif)
![ide_db_imports_location_local_query](https://user-images.githubusercontent.com/4218373/106980205-cf7ce900-6770-11eb-8516-653c8fcca807.gif)

# Working with non-`Copy` types

Consider the following example:
```rust
fn foo() {
  let v = Vec::new();
  $0
  let n = v.len();
  $0
  let is_empty = v.is_empty();
}
```
`v` must be a parameter to extracted function.
The question is, what type should it have.
It could be `v: Vec<i32>`, or `v: &Vec<i32>`.
The former is incorrect for `Vec<i32>`, but the later is silly for `i32`.

To resolve this we need to know if the type implements `Copy` trait.

I didn't find any api available from assists to query this.
`hir_ty::method_resolution::implements` seems relevant, but is isn't publicly re-exported from `hir`.

# Star(`*`) token and pointer dereference

If I understand correctly, in order to create expression like `*p`, one should use `ast::make::expr_prefix(T![*], ...)`, which
in turn calls `token(T![*])`.

`token` does not have star in `tokens::SOURCE_FILE`, so this panics.
I had to add `*` to `SOURCE_FILE` to make it work.

Correct me if this is not intended way to do this.

# Lowering access `value -> mut ref -> shared ref`

Consider the following example:
```rust
fn foo() {
  let v = Vec::new();
  $0 let n = v.len(); $0
}
```
`v` is not used after extracted function body, so both `v: &Vec<i32>` and `v: Vec<i32>` would work.
Currently the later would be chosen.

We can however check the body of extracted function and conclude that `v: &Vec<i32>` is sufficient.
Using `v: &Vec<i32>`(that is a minimal required access level) might be a better default.
I am unsure.

# Cleanup
The assist seems to be reasonably handling most of common cases.
If there are no concerns with code it produces(i.e. with test cases), I will start cleaning up

[edit]
added showcase

Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
3 years agoallow extracted body to be indented(dedent it)
Vladyslav Katasonov [Fri, 5 Feb 2021 02:00:53 +0000 (05:00 +0300)]
allow extracted body to be indented(dedent it)

3 years agoallow transitive `&mut` access for fields in extract_function
Vladyslav Katasonov [Fri, 5 Feb 2021 01:35:41 +0000 (04:35 +0300)]
allow transitive `&mut` access for fields in extract_function

3 years agoadd tests for extracting if/match/while/for exprs
Vladyslav Katasonov [Thu, 4 Feb 2021 23:30:34 +0000 (02:30 +0300)]
add tests for extracting if/match/while/for exprs

3 years agodocument extract_function assist implementation
Vladyslav Katasonov [Thu, 4 Feb 2021 23:14:32 +0000 (02:14 +0300)]
document extract_function assist implementation

3 years agouse `&T` for non copy params of extracted function
Vladyslav Katasonov [Thu, 4 Feb 2021 22:18:45 +0000 (01:18 +0300)]
use `&T` for non copy params of extracted function

Use shared ref if param is not `T: Copy` and is used after body

3 years agoMerge #7561
bors[bot] [Thu, 4 Feb 2021 21:42:57 +0000 (21:42 +0000)]
Merge #7561

7561: Avoid using ModPath's fields directly r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoAvoid using ModPath's fields directly
Jonas Schievink [Thu, 4 Feb 2021 21:42:21 +0000 (22:42 +0100)]
Avoid using ModPath's fields directly

3 years ago split extract_function into pieces and order them
Vladyslav Katasonov [Thu, 4 Feb 2021 21:35:28 +0000 (00:35 +0300)]
 split extract_function into pieces and order them

3 years agoMerge #7559
bors[bot] [Thu, 4 Feb 2021 19:59:21 +0000 (19:59 +0000)]
Merge #7559

7559: Make `ModPath`'s representation private r=jonas-schievink a=jonas-schievink

This lets us switch out the `Vec` for something more efficient

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoMake `ModPath`'s representation private
Jonas Schievink [Thu, 4 Feb 2021 19:49:24 +0000 (20:49 +0100)]
Make `ModPath`'s representation private

3 years agoMerge #7558
bors[bot] [Thu, 4 Feb 2021 19:46:01 +0000 (19:46 +0000)]
Merge #7558

7558: Update thread_local r=kjeremy a=kjeremy

Pulls in https://github.com/Amanieu/thread_local-rs/pull/30 which fixes
a leak when dropping ThreadLocal.

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoUpdate thread_local
kjeremy [Thu, 4 Feb 2021 19:42:45 +0000 (14:42 -0500)]
Update thread_local

Pulls in https://github.com/Amanieu/thread_local-rs/pull/30 which fixes
a leak when dropping ThreadLocal.

3 years agoMerge #7557
bors[bot] [Thu, 4 Feb 2021 18:33:57 +0000 (18:33 +0000)]
Merge #7557

7557: Intern `TypeRef`s in the containing `ItemTree` r=jonas-schievink a=jonas-schievink

This reduces the memory used by `ItemTreeQuery` by ~20%. As it turns out, `TypeRef` is very heavy, and is used a lot in `ItemTree`:

* Many types are frequently repeated throughout the same file. This is what this PR addresses by storing identical `TypeRef`s only once per `ItemTree`.
* The vast majority of `TypeRef` consist of a plain path with only a single element. "Type anchors" like in `<Ty>::func` are used incredibly rarely, and even multi-segment paths are much rarer than single-segment paths.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoIntern `TypeRef`s in the containing `ItemTree`
Jonas Schievink [Thu, 4 Feb 2021 18:19:51 +0000 (19:19 +0100)]
Intern `TypeRef`s in the containing `ItemTree`

3 years agoMerge #7555
bors[bot] [Thu, 4 Feb 2021 14:05:25 +0000 (14:05 +0000)]
Merge #7555

7555: Expander: store a LocalModuleId, not ModuleId r=jonas-schievink a=jonas-schievink

It already stores the DefMap containing the module, so having
a full ModuleId is unnecessary and makes it easier to mix things up

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoExpander: store a LocalModuleId, not ModuleId
Jonas Schievink [Thu, 4 Feb 2021 14:04:21 +0000 (15:04 +0100)]
Expander: store a LocalModuleId, not ModuleId

It already stores the DefMap containing the module, so having
a full ModuleId is unnecessary and makes it easier to mix things up

3 years agoMerge #7554
bors[bot] [Thu, 4 Feb 2021 12:45:40 +0000 (12:45 +0000)]
Merge #7554

7554: Don't keep the parent DefMap alive via Arc r=jonas-schievink a=jonas-schievink

This seems like it could easily leak a lot of memory since we don't
currently run GC

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoDon't keep the parent DefMap alive via Arc
Jonas Schievink [Thu, 4 Feb 2021 12:44:54 +0000 (13:44 +0100)]
Don't keep the parent DefMap alive via Arc

This seems like it could easily leak a lot of memory since we don't
currently run GC

3 years agoIncrease Highlights highlight range to covering element
Lukas Wirth [Thu, 4 Feb 2021 10:37:14 +0000 (11:37 +0100)]
Increase Highlights highlight range to covering element

3 years agoMerge #7553
bors[bot] [Thu, 4 Feb 2021 10:28:13 +0000 (10:28 +0000)]
Merge #7553

7553: More architecture.md r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoMore architecture.md
Aleksey Kladov [Thu, 4 Feb 2021 10:27:34 +0000 (13:27 +0300)]
More architecture.md

3 years agoremove ignored test for downgrading mut to shared
Vladyslav Katasonov [Wed, 3 Feb 2021 21:52:53 +0000 (00:52 +0300)]
remove ignored test for downgrading mut to shared

3 years agoallow calling `&mut` methods on outer vars when extracing function
Vladyslav Katasonov [Wed, 3 Feb 2021 21:44:36 +0000 (00:44 +0300)]
allow calling `&mut` methods on outer vars when extracing function

3 years agoallow `&mut param` when extracting function
Vladyslav Katasonov [Wed, 3 Feb 2021 21:27:31 +0000 (00:27 +0300)]
allow `&mut param` when extracting function

Recognise &mut as variable modification.
This allows extracting functions with
`&mut var` with `var` being in outer scope

3 years agoallow modifications of vars from outer scope inside extracted function
Vladyslav Katasonov [Wed, 3 Feb 2021 20:45:03 +0000 (23:45 +0300)]
allow modifications of vars from outer scope inside extracted function

It currently allows only directly setting variable.
No `&mut` references or methods.

3 years agoallow local variables to be used after extracted body
Vladyslav Katasonov [Wed, 3 Feb 2021 17:31:12 +0000 (20:31 +0300)]
allow local variables to be used after extracted body

when variable is defined inside extracted body
export this variable to original scope via return value(s)

3 years agoMerge #7547
bors[bot] [Wed, 3 Feb 2021 18:06:55 +0000 (18:06 +0000)]
Merge #7547

7547: Split out ItemScope::dump from DefMap::dump r=jonas-schievink a=jonas-schievink

This is helpful for more targeted debugging

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoSplit out ItemScope::dump from DefMap::dump
Jonas Schievink [Wed, 3 Feb 2021 18:05:11 +0000 (19:05 +0100)]
Split out ItemScope::dump from DefMap::dump

3 years agoMerge #7546
bors[bot] [Wed, 3 Feb 2021 17:25:06 +0000 (17:25 +0000)]
Merge #7546

7546: Add newline between block and crate maps r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoAdd newline between block and crate maps
Jonas Schievink [Wed, 3 Feb 2021 17:23:59 +0000 (18:23 +0100)]
Add newline between block and crate maps

3 years agoMerge #7545
bors[bot] [Wed, 3 Feb 2021 17:15:21 +0000 (17:15 +0000)]
Merge #7545

7545: Add a FIXME to ItemTree r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoAdd a FIXME to ItemTree
Jonas Schievink [Wed, 3 Feb 2021 17:14:39 +0000 (18:14 +0100)]
Add a FIXME to ItemTree

3 years agoMerge #7544
bors[bot] [Wed, 3 Feb 2021 16:54:29 +0000 (16:54 +0000)]
Merge #7544

7544: Update `DefMap` and `block_def_map` docs r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoUpdate `DefMap` and `block_def_map` docs
Jonas Schievink [Wed, 3 Feb 2021 16:48:41 +0000 (17:48 +0100)]
Update `DefMap` and `block_def_map` docs

3 years agoMerge #7543
bors[bot] [Wed, 3 Feb 2021 16:20:25 +0000 (16:20 +0000)]
Merge #7543

7543: Grammar fixes r=Kushagra-0801 a=Kushagra-0801

I think line 235 is still wrong, but I am not sure.

Is the `crated/tt` in line 252 supposed to be `crates/tt`?

Co-authored-by: Kushagra Gupta <39802979+Kushagra-0801@users.noreply.github.com>
3 years agotypo fixes
Kushagra Gupta [Wed, 3 Feb 2021 16:00:42 +0000 (21:30 +0530)]
typo fixes

3 years agoGrammar fixes
Kushagra Gupta [Wed, 3 Feb 2021 15:35:21 +0000 (21:05 +0530)]
Grammar fixes

I think line 235 is still wrong, but I am not sure.

Is the `crated/tt` in line 252 supposed to be `crates/tt`?

3 years agochange TODO to FIXME
Vladyslav Katasonov [Wed, 3 Feb 2021 14:47:21 +0000 (17:47 +0300)]
change TODO to FIXME

3 years agodisable test for downgrading mutability on extract
Vladyslav Katasonov [Wed, 3 Feb 2021 14:46:57 +0000 (17:46 +0300)]
disable test for downgrading mutability on extract

3 years agoconvert IdentPat to Pat via Into
Vladyslav Katasonov [Wed, 3 Feb 2021 14:45:36 +0000 (17:45 +0300)]
convert IdentPat to Pat via Into

before child getter was used

3 years agoMerge #7541
bors[bot] [Wed, 3 Feb 2021 14:41:13 +0000 (14:41 +0000)]
Merge #7541

7541: Use block_def_map in body lowering (third time's the charm) r=jonas-schievink a=jonas-schievink

After https://github.com/rust-analyzer/rust-analyzer/pull/7380 and https://github.com/rust-analyzer/rust-analyzer/pull/7506 both had to be reverted, this should have finally resolved all remaining bugs.

Most importantly, the optimization to skip `block_def_map` computation when the block contains no inner items was fixed (which fortunately was simpler than expected).

I've ran `analysis-stats` on libstd locally, which works fine, and also ran this PR locally for a short while without issues.

Note that this *still* has no (or almost no) user-facing impact, because the rest of r-a still relies on some local item support hacks.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
3 years agoTest for name resolution with DefMap shortcut
Jonas Schievink [Tue, 2 Feb 2021 14:55:33 +0000 (15:55 +0100)]
Test for name resolution with DefMap shortcut

3 years agoShortcut `block_def_map` if there's no inner items
Jonas Schievink [Mon, 1 Feb 2021 12:32:43 +0000 (13:32 +0100)]
Shortcut `block_def_map` if there's no inner items

This previously didn't work, but apparently only because of the wonky
test setup

3 years agoMerge #7539
bors[bot] [Wed, 3 Feb 2021 14:02:30 +0000 (14:02 +0000)]
Merge #7539

7539: Add cargo file tidy test r=edwin0cheng a=edwin0cheng

bors r+

cc @pksunkara

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
3 years agoAdd cargo file tidy test
Edwin Cheng [Wed, 3 Feb 2021 14:01:09 +0000 (22:01 +0800)]
Add cargo file tidy test

3 years agoUse body lowering for block_def_map tests
Jonas Schievink [Mon, 1 Feb 2021 12:20:35 +0000 (13:20 +0100)]
Use body lowering for block_def_map tests

Removes the hacky and buggy custom lowering code

3 years agoUse block_def_map in body lowering
Jonas Schievink [Mon, 1 Feb 2021 12:19:55 +0000 (13:19 +0100)]
Use block_def_map in body lowering

3 years agoMerge #7538
bors[bot] [Wed, 3 Feb 2021 12:59:22 +0000 (12:59 +0000)]
Merge #7538

7538: Make sure normal dependencies always have version r=edwin0cheng a=pksunkara

How do I prevent this happening in the future by doing something in the CI? IIRC this is the second time.

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
3 years agoMake sure normal dependencies always have version
Pavan Kumar Sunkara [Wed, 3 Feb 2021 12:51:07 +0000 (12:51 +0000)]
Make sure normal dependencies always have version

3 years agoMerge #7537
bors[bot] [Wed, 3 Feb 2021 12:48:13 +0000 (12:48 +0000)]
Merge #7537

7537: Fix spelling mistakes in docs/dev r=Veykril a=Veykril

Also adds a line for `crates/cfg` and `crates/stdx` to the architecture.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
3 years agoFix spelling mistakes in docs/dev
Lukas Wirth [Wed, 3 Feb 2021 12:40:24 +0000 (13:40 +0100)]
Fix spelling mistakes in docs/dev

3 years agoMerge #7536
bors[bot] [Wed, 3 Feb 2021 11:26:49 +0000 (11:26 +0000)]
Merge #7536

7536: Make architecture more informative r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
3 years agoMake architecture more informative
Aleksey Kladov [Tue, 2 Feb 2021 18:59:27 +0000 (21:59 +0300)]
Make architecture more informative

Call out boundaries and invariants

3 years agosupport extracting methods; no mut lowering
Vladyslav Katasonov [Wed, 3 Feb 2021 09:27:53 +0000 (12:27 +0300)]
support extracting methods; no mut lowering

currently mut refernce will *not* be downgraded to shared
if it is sufficient(see relevant test for example)

3 years agoinitial version of extract function assist
Vladyslav Katasonov [Wed, 3 Feb 2021 07:57:11 +0000 (10:57 +0300)]
initial version of extract function assist

there are a few currently limitations:
* no modifications of function body
* does not handle mutability and references
* no method support
* may produce incorrect results

3 years agoMerge #7528
bors[bot] [Tue, 2 Feb 2021 22:18:58 +0000 (22:18 +0000)]
Merge #7528

7528: Update mimalloc r=kjeremy a=kjeremy

Co-authored-by: kjeremy <kjeremy@gmail.com>
3 years agoUpdate mimalloc
kjeremy [Tue, 2 Feb 2021 22:17:49 +0000 (17:17 -0500)]
Update mimalloc

3 years agoMerge #7525
bors[bot] [Tue, 2 Feb 2021 17:02:48 +0000 (17:02 +0000)]
Merge #7525

7525: Fix resolution of `crate` paths from within blocks r=jonas-schievink a=jonas-schievink

They resolve to the crate root, not the DefMap's root module (which
can be a block)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>